mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-17 15:40:16 +00:00
Tests: Use more appropriate assertions in various tests.
This replaces instances of `assertTrue( in_array( ... ) )` with `assertContains()` to use native PHPUnit functionality. Follow-up to [51335], [51337], [51367], [51397], [51403]. Props hellofromTonya, jrf, SergeyBiryukov. Fixes #53123. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51404 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -277,9 +277,9 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
$user_ids = wp_list_pluck( $users, 'id' );
|
||||
|
||||
$this->assertTrue( in_array( self::$editor, $user_ids, true ) );
|
||||
$this->assertTrue( in_array( self::$authors['r_true_p_true'], $user_ids, true ) );
|
||||
$this->assertTrue( in_array( self::$authors['r_true_p_false'], $user_ids, true ) );
|
||||
$this->assertContains( self::$editor, $user_ids );
|
||||
$this->assertContains( self::$authors['r_true_p_true'], $user_ids );
|
||||
$this->assertContains( self::$authors['r_true_p_false'], $user_ids );
|
||||
$this->assertCount( 3, $user_ids );
|
||||
}
|
||||
|
||||
@@ -289,8 +289,8 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$users = $response->get_data();
|
||||
$user_ids = wp_list_pluck( $users, 'id' );
|
||||
|
||||
$this->assertFalse( in_array( self::$authors['r_false_p_true'], $user_ids, true ) );
|
||||
$this->assertFalse( in_array( self::$authors['r_false_p_false'], $user_ids, true ) );
|
||||
$this->assertNotContains( self::$authors['r_false_p_true'], $user_ids );
|
||||
$this->assertNotContains( self::$authors['r_false_p_false'], $user_ids );
|
||||
}
|
||||
|
||||
public function test_get_items_unauthenticated_does_not_include_users_without_published_posts() {
|
||||
@@ -299,8 +299,8 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$users = $response->get_data();
|
||||
$user_ids = wp_list_pluck( $users, 'id' );
|
||||
|
||||
$this->assertFalse( in_array( self::$draft_editor, $user_ids, true ) );
|
||||
$this->assertFalse( in_array( self::$user, $user_ids, true ) );
|
||||
$this->assertNotContains( self::$draft_editor, $user_ids );
|
||||
$this->assertNotContains( self::$user, $user_ids );
|
||||
}
|
||||
|
||||
public function test_get_items_pagination_headers() {
|
||||
@@ -633,15 +633,15 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$ids = wp_list_pluck( $data, 'id' );
|
||||
$this->assertTrue( in_array( $id1, $ids, true ) );
|
||||
$this->assertTrue( in_array( $id2, $ids, true ) );
|
||||
$this->assertContains( $id1, $ids );
|
||||
$this->assertContains( $id2, $ids );
|
||||
|
||||
$request->set_param( 'exclude', array( $id2 ) );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$ids = wp_list_pluck( $data, 'id' );
|
||||
$this->assertTrue( in_array( $id1, $ids, true ) );
|
||||
$this->assertFalse( in_array( $id2, $ids, true ) );
|
||||
$this->assertContains( $id1, $ids );
|
||||
$this->assertNotContains( $id2, $ids );
|
||||
|
||||
// Invalid 'exclude' should error.
|
||||
$request->set_param( 'exclude', 'none-of-those-please' );
|
||||
|
||||
Reference in New Issue
Block a user