Skip to content

Commit 1af3145

Browse files
test fixes
1 parent 4852ea7 commit 1af3145

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,27 +202,25 @@ public function test_core_get_user_output_is_normalized_to_schema_types(): void
202202

203203
wp_set_current_user( $user_id );
204204

205-
$ability = wp_get_ability( 'core/get-user' );
206-
207-
$capability_filter = static function ( $allcaps, $caps, $args, $user ) use ( $user_id ) {
208-
if ( $user_id === (int) $user->ID ) {
209-
$allcaps['custom_capability_flag'] = '1';
210-
}
211-
212-
return $allcaps;
213-
};
214-
add_filter( 'user_has_cap', $capability_filter, 10, 4 );
205+
$ability = wp_get_ability( 'core/get-user' );
206+
$capability_key = $GLOBALS['wpdb']->get_blog_prefix() . 'capabilities';
207+
update_user_meta(
208+
$user_id,
209+
$capability_key,
210+
array(
211+
'subscriber' => true,
212+
'custom_capability_flag' => '1',
213+
'custom_capability_disabled' => '0',
214+
)
215+
);
216+
clean_user_cache( $user_id );
215217

216-
try {
217-
$result = $ability->execute(
218-
array(
219-
'id' => $user_id,
220-
'include_capabilities' => 1,
221-
)
222-
);
223-
} finally {
224-
remove_filter( 'user_has_cap', $capability_filter, 10 );
225-
}
218+
$result = $ability->execute(
219+
array(
220+
'id' => $user_id,
221+
'include_capabilities' => 1,
222+
)
223+
);
226224

227225
$this->assertIsArray( $result );
228226
$this->assertIsInt( $result['id'] );
@@ -252,8 +250,11 @@ public function test_core_get_user_output_is_normalized_to_schema_types(): void
252250

253251
$this->assertIsObject( $result['capabilities'] );
254252
$this->assertObjectHasProperty( 'custom_capability_flag', $result['capabilities'] );
253+
$this->assertObjectHasProperty( 'custom_capability_disabled', $result['capabilities'] );
255254
$this->assertIsBool( $result['capabilities']->custom_capability_flag );
255+
$this->assertIsBool( $result['capabilities']->custom_capability_disabled );
256256
$this->assertTrue( $result['capabilities']->custom_capability_flag );
257+
$this->assertFalse( $result['capabilities']->custom_capability_disabled );
257258
}
258259

259260
/**

0 commit comments

Comments
 (0)