From c96a42e08ac8708f4cb814f2beed991919a54dc4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 12 Jul 2021 10:35:44 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/ajax/DeleteComment.php | 2 +- tests/phpunit/tests/ajax/DimComment.php | 2 +- tests/phpunit/tests/ajax/Response.php | 2 +- tests/phpunit/tests/feed/atom.php | 2 +- tests/phpunit/tests/formatting/EscUrl.php | 4 ++-- tests/phpunit/tests/oembed/headers.php | 2 +- tests/phpunit/tests/pluggable.php | 2 +- tests/phpunit/tests/post/meta.php | 2 +- tests/phpunit/tests/post/objects.php | 2 +- tests/phpunit/tests/post/wpPostType.php | 2 +- tests/phpunit/tests/rest-api.php | 2 +- .../rest-api/rest-attachments-controller.php | 12 +++++----- .../rest-api/rest-categories-controller.php | 8 +++---- .../rest-api/rest-comments-controller.php | 24 +++++++++---------- .../tests/rest-api/rest-posts-controller.php | 24 +++++++++---------- tests/phpunit/tests/rest-api/rest-request.php | 4 ++-- .../tests/rest-api/rest-tags-controller.php | 8 +++---- .../tests/rest-api/rest-users-controller.php | 22 ++++++++--------- tests/phpunit/tests/term/wpInsertTerm.php | 2 +- tests/phpunit/tests/term/wpTaxonomy.php | 2 +- tests/phpunit/tests/term/wpUpdateTerm.php | 2 +- tests/phpunit/tests/theme/themeDir.php | 2 +- tests/phpunit/tests/user.php | 10 ++++---- tests/phpunit/tests/wp.php | 6 ++--- tests/phpunit/tests/xmlrpc/wp/editPost.php | 6 ++--- 25 files changed, 78 insertions(+), 78 deletions(-) diff --git a/tests/phpunit/tests/ajax/DeleteComment.php b/tests/phpunit/tests/ajax/DeleteComment.php index aa628221ac..82409d3b66 100644 --- a/tests/phpunit/tests/ajax/DeleteComment.php +++ b/tests/phpunit/tests/ajax/DeleteComment.php @@ -108,7 +108,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase { // Check for either possible total. $message = sprintf( 'returned value: %1$d $total: %2$d $recalc_total: %3$d', (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], $total, $recalc_total ); - $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ), $message ); + $this->assertContains( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), $message ); } /** diff --git a/tests/phpunit/tests/ajax/DimComment.php b/tests/phpunit/tests/ajax/DimComment.php index dcf5ba07ab..9ff1bf405e 100644 --- a/tests/phpunit/tests/ajax/DimComment.php +++ b/tests/phpunit/tests/ajax/DimComment.php @@ -103,7 +103,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase { $total = $_POST['_total'] - 1; // Check for either possible total. - $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ) ); + $this->assertContains( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ) ); } /** diff --git a/tests/phpunit/tests/ajax/Response.php b/tests/phpunit/tests/ajax/Response.php index 3efbac3aef..0bb3cf3fa6 100644 --- a/tests/phpunit/tests/ajax/Response.php +++ b/tests/phpunit/tests/ajax/Response.php @@ -83,7 +83,7 @@ class Tests_Ajax_Response extends WP_UnitTestCase { $headers = xdebug_get_headers(); ob_end_clean(); - $this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers, true ) ); + $this->assertContains( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers ); } /** diff --git a/tests/phpunit/tests/feed/atom.php b/tests/phpunit/tests/feed/atom.php index 88140ded96..6bdf033073 100644 --- a/tests/phpunit/tests/feed/atom.php +++ b/tests/phpunit/tests/feed/atom.php @@ -186,7 +186,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { } $categories = xml_find( $entries[ $key ]['child'], 'category' ); foreach ( $categories as $category ) { - $this->assertTrue( in_array( $category['attributes']['term'], $terms, true ) ); + $this->assertContains( $category['attributes']['term'], $terms ); } unset( $terms ); diff --git a/tests/phpunit/tests/formatting/EscUrl.php b/tests/phpunit/tests/formatting/EscUrl.php index 13ecc4af66..ccc9083134 100644 --- a/tests/phpunit/tests/formatting/EscUrl.php +++ b/tests/phpunit/tests/formatting/EscUrl.php @@ -127,10 +127,10 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase { ); } - $this->assertTrue( ! in_array( 'data', wp_allowed_protocols(), true ) ); + $this->assertNotContains( 'data', wp_allowed_protocols() ); $this->assertSame( '', esc_url( 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D' ) ); - $this->assertTrue( ! in_array( 'foo', wp_allowed_protocols(), true ) ); + $this->assertNotContains( 'foo', wp_allowed_protocols() ); $this->assertSame( 'foo://example.com', esc_url( diff --git a/tests/phpunit/tests/oembed/headers.php b/tests/phpunit/tests/oembed/headers.php index 6f2854a04e..6f0f5f46dc 100644 --- a/tests/phpunit/tests/oembed/headers.php +++ b/tests/phpunit/tests/oembed/headers.php @@ -31,6 +31,6 @@ class Tests_oEmbed_HTTP_Headers extends WP_UnitTestCase { $headers = xdebug_get_headers(); - $this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers, true ) ); + $this->assertContains( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers ); } } diff --git a/tests/phpunit/tests/pluggable.php b/tests/phpunit/tests/pluggable.php index 460c7b588a..0138ab371e 100644 --- a/tests/phpunit/tests/pluggable.php +++ b/tests/phpunit/tests/pluggable.php @@ -62,7 +62,7 @@ class Tests_Pluggable extends WP_UnitTestCase { foreach ( $expected as $function => $sig ) { $msg = 'Function: ' . $function . '()'; $this->assertTrue( function_exists( $function ), $msg ); - $this->assertTrue( in_array( $function, $defined, true ), $msg ); + $this->assertContains( $function, $defined, $msg ); } } diff --git a/tests/phpunit/tests/post/meta.php b/tests/phpunit/tests/post/meta.php index d8ff74bc62..1b35df99fd 100644 --- a/tests/phpunit/tests/post/meta.php +++ b/tests/phpunit/tests/post/meta.php @@ -95,7 +95,7 @@ class Tests_Post_Meta extends WP_UnitTestCase { 'another value', ); sort( $expected ); - $this->assertTrue( in_array( get_post_meta( self::$post_id, 'nonunique', true ), $expected, true ) ); + $this->assertContains( get_post_meta( self::$post_id, 'nonunique', true ), $expected ); $actual = get_post_meta( self::$post_id, 'nonunique', false ); sort( $actual ); $this->assertSame( $expected, $actual ); diff --git a/tests/phpunit/tests/post/objects.php b/tests/phpunit/tests/post/objects.php index 71cfc754d8..3d077d0f7a 100644 --- a/tests/phpunit/tests/post/objects.php +++ b/tests/phpunit/tests/post/objects.php @@ -36,7 +36,7 @@ class Tests_Post_Objects extends WP_UnitTestCase { $post = get_post( $id, ARRAY_N ); $this->assertIsArray( $post ); $this->assertArrayNotHasKey( 'post_type', $post ); - $this->assertTrue( in_array( 'post', $post, true ) ); + $this->assertContains( 'post', $post ); $post = get_post( $id ); $post = get_post( $post, ARRAY_A ); diff --git a/tests/phpunit/tests/post/wpPostType.php b/tests/phpunit/tests/post/wpPostType.php index 1acb6b83ba..c08af7a142 100644 --- a/tests/phpunit/tests/post/wpPostType.php +++ b/tests/phpunit/tests/post/wpPostType.php @@ -119,7 +119,7 @@ class Tests_Post_WP_Post_Type extends WP_UnitTestCase { ); $post_type_object->add_rewrite_rules(); - $this->assertFalse( in_array( 'foobar', $wp->public_query_vars, true ) ); + $this->assertNotContains( 'foobar', $wp->public_query_vars ); } public function test_adds_query_var_if_public() { diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index e271d369a0..fc01087a66 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -265,7 +265,7 @@ class Tests_REST_API extends WP_UnitTestCase { */ function test_rest_route_query_var() { rest_api_init(); - $this->assertTrue( in_array( 'rest_route', $GLOBALS['wp']->public_query_vars, true ) ); + $this->assertContains( 'rest_route', $GLOBALS['wp']->public_query_vars ); } public function test_route_method() { diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 2673d738ce..fab7c48a71 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -302,9 +302,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $data = $response->get_data(); $this->assertCount( 2, $data ); $ids = wp_list_pluck( $data, 'id' ); - $this->assertTrue( in_array( $id1, $ids, true ) ); - $this->assertFalse( in_array( $id2, $ids, true ) ); - $this->assertTrue( in_array( $id3, $ids, true ) ); + $this->assertContains( $id1, $ids ); + $this->assertNotContains( $id2, $ids ); + $this->assertContains( $id3, $ids ); $this->check_get_posts_response( $response ); } @@ -343,9 +343,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $data = $response->get_data(); $this->assertCount( 3, $data ); $ids = wp_list_pluck( $data, 'id' ); - $this->assertTrue( in_array( $id1, $ids, true ) ); - $this->assertTrue( in_array( $id2, $ids, true ) ); - $this->assertTrue( in_array( $id3, $ids, true ) ); + $this->assertContains( $id1, $ids ); + $this->assertContains( $id2, $ids ); + $this->assertContains( $id3, $ids ); } public function test_get_items_media_type() { diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index 51878f548c..f8d49198b3 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -311,15 +311,15 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas $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 ); } public function test_get_items_orderby_args() { diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index bd3283a373..6bc3e24694 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -247,7 +247,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertTrue( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) ); } /** @@ -270,7 +270,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertFalse( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertNotContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) ); } /** @@ -310,7 +310,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertFalse( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertNotContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) ); } public function test_get_password_items_with_edit_post_permission() { @@ -329,7 +329,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertTrue( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) ); } public function test_get_items_without_private_post_permission() { @@ -348,7 +348,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertFalse( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertNotContains( $private_comment, wp_list_pluck( $collection_data, 'id' ) ); } public function test_get_items_with_private_post_permission() { @@ -367,7 +367,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertTrue( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertContains( $private_comment, wp_list_pluck( $collection_data, 'id' ) ); } public function test_get_items_with_invalid_post() { @@ -386,7 +386,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertFalse( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertNotContains( $comment_id, wp_list_pluck( $collection_data, 'id' ) ); wp_delete_comment( $comment_id ); } @@ -407,7 +407,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertSame( 200, $response->get_status() ); $collection_data = $response->get_data(); - $this->assertTrue( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ), true ) ); + $this->assertContains( $comment_id, wp_list_pluck( $collection_data, 'id' ) ); wp_delete_comment( $comment_id ); } @@ -525,15 +525,15 @@ class WP_Test_REST_Comments_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', array( 'invalid' ) ); diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 7639e76724..a2d8ae7fdf 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -475,22 +475,22 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $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 ); $request->set_param( 'exclude', (string) $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 ); $request->set_param( 'exclude', 'invalid' ); $response = rest_get_server()->dispatch( $request ); @@ -1482,9 +1482,9 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $posts = $response->get_data(); $ids = wp_list_pluck( $posts, 'id' ); - $this->assertTrue( in_array( $id1, $ids, true ) ); - $this->assertFalse( in_array( $id2, $ids, true ) ); - $this->assertFalse( in_array( $id3, $ids, true ) ); + $this->assertContains( $id1, $ids ); + $this->assertNotContains( $id2, $ids ); + $this->assertNotContains( $id3, $ids); $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3,$id2) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" ); } @@ -1508,9 +1508,9 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $posts = $response->get_data(); $ids = wp_list_pluck( $posts, 'id' ); - $this->assertTrue( in_array( $id1, $ids, true ) ); - $this->assertTrue( in_array( $id2, $ids, true ) ); - $this->assertFalse( in_array( $id3, $ids, true ) ); + $this->assertContains( $id1, $ids ); + $this->assertContains( $id2, $ids ); + $this->assertNotContains( $id3, $ids ); $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" ); } diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php index cf6678d4f7..f5b3a91258 100644 --- a/tests/phpunit/tests/rest-api/rest-request.php +++ b/tests/phpunit/tests/rest-api/rest-request.php @@ -616,8 +616,8 @@ class Tests_REST_Request extends WP_UnitTestCase { $data = $valid->get_error_data( 'rest_missing_callback_param' ); - $this->assertTrue( in_array( 'someinteger', $data['params'], true ) ); - $this->assertTrue( in_array( 'someotherinteger', $data['params'], true ) ); + $this->assertContains( 'someinteger', $data['params'] ); + $this->assertContains( 'someotherinteger', $data['params'] ); } public function test_has_valid_params_validate_callback() { diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index 1e4998b85e..28065e28d4 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -245,15 +245,15 @@ class WP_Test_REST_Tags_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', array( 'invalid' ) ); diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index bded32517a..a3cbb49221 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -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' ); diff --git a/tests/phpunit/tests/term/wpInsertTerm.php b/tests/phpunit/tests/term/wpInsertTerm.php index bad84c9ae4..1627238773 100644 --- a/tests/phpunit/tests/term/wpInsertTerm.php +++ b/tests/phpunit/tests/term/wpInsertTerm.php @@ -822,7 +822,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { $cached_children = get_option( 'wptests_tax_children' ); $this->assertNotEmpty( $cached_children[ $t ] ); - $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t ], true ) ); + $this->assertContains( $found['term_id'], $cached_children[ $t ] ); } /** diff --git a/tests/phpunit/tests/term/wpTaxonomy.php b/tests/phpunit/tests/term/wpTaxonomy.php index 3f646fd5ba..a8689284c2 100644 --- a/tests/phpunit/tests/term/wpTaxonomy.php +++ b/tests/phpunit/tests/term/wpTaxonomy.php @@ -22,7 +22,7 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase { $taxonomy_object = new WP_Taxonomy( $taxonomy, 'post' ); $taxonomy_object->add_rewrite_rules(); - $this->assertFalse( in_array( 'foobar', $wp->public_query_vars, true ) ); + $this->assertNotContains( 'foobar', $wp->public_query_vars ); } public function test_adds_query_var_if_public() { diff --git a/tests/phpunit/tests/term/wpUpdateTerm.php b/tests/phpunit/tests/term/wpUpdateTerm.php index 3cd74aa5ac..68ed7a703b 100644 --- a/tests/phpunit/tests/term/wpUpdateTerm.php +++ b/tests/phpunit/tests/term/wpUpdateTerm.php @@ -685,7 +685,7 @@ class Tests_Term_WpUpdateTerm extends WP_UnitTestCase { $cached_children = get_option( 'wptests_tax_children' ); $this->assertNotEmpty( $cached_children[ $t2 ] ); - $this->assertTrue( in_array( $found['term_id'], $cached_children[ $t2 ], true ) ); + $this->assertContains( $found['term_id'], $cached_children[ $t2 ] ); } /** diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index 663503fc1f..5455c66c9e 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -208,7 +208,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { $this->assertNotEmpty( $theme ); $templates = $theme['Template Files']; - $this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates, true ) ); + $this->assertContains( $this->theme_root . '/page-templates/template-top-level.php', $templates ); } /** diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index e913c454c5..f5ba3982e2 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -1113,7 +1113,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); + $this->assertContains( (string) self::$contrib_id, $users ); } public function test_search_users_url() { @@ -1124,7 +1124,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); + $this->assertContains( (string) self::$contrib_id, $users ); } public function test_search_users_email() { @@ -1135,7 +1135,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); + $this->assertContains( (string) self::$contrib_id, $users ); } public function test_search_users_nicename() { @@ -1146,7 +1146,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); + $this->assertContains( (string) self::$contrib_id, $users ); } public function test_search_users_display_name() { @@ -1157,7 +1157,7 @@ class Tests_User extends WP_UnitTestCase { ) ); - $this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) ); + $this->assertContains( (string) self::$contrib_id, $users ); } /** diff --git a/tests/phpunit/tests/wp.php b/tests/phpunit/tests/wp.php index 3e80b303c8..428263298f 100644 --- a/tests/phpunit/tests/wp.php +++ b/tests/phpunit/tests/wp.php @@ -22,15 +22,15 @@ class Tests_WP extends WP_UnitTestCase { $this->wp->add_query_var( 'test' ); $this->assertCount( $public_qv_count + 2, $this->wp->public_query_vars ); - $this->assertTrue( in_array( 'test', $this->wp->public_query_vars, true ) ); - $this->assertTrue( in_array( 'test2', $this->wp->public_query_vars, true ) ); + $this->assertContains( 'test', $this->wp->public_query_vars ); + $this->assertContains( 'test2', $this->wp->public_query_vars ); } public function test_remove_query_var() { $public_qv_count = count( $this->wp->public_query_vars ); $this->wp->add_query_var( 'test' ); - $this->assertTrue( in_array( 'test', $this->wp->public_query_vars, true ) ); + $this->assertContains( 'test', $this->wp->public_query_vars ); $this->wp->remove_query_var( 'test' ); $this->assertCount( $public_qv_count, $this->wp->public_query_vars ); diff --git a/tests/phpunit/tests/xmlrpc/wp/editPost.php b/tests/phpunit/tests/xmlrpc/wp/editPost.php index 389345a9b8..8d732b1e64 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/editPost.php @@ -445,7 +445,7 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { $this->assertCount( 1, get_post_meta( $post_id, 'enclosure' ) ); // For good measure, check that the expected value is in the array. - $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); + $this->assertContains( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ); // Attempt to add a brand new enclosure via XML-RPC. $this->myxmlrpcserver->add_enclosure_if_new( $post_id, $new_enclosure ); @@ -455,10 +455,10 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { // Check that the new enclosure is in the enclosure meta. $new_enclosure_string = "{$new_enclosure['url']}\n{$new_enclosure['length']}\n{$new_enclosure['type']}\n"; - $this->assertTrue( in_array( $new_enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); + $this->assertContains( $new_enclosure_string, get_post_meta( $post_id, 'enclosure' ) ); // Check that the old enclosure is in the enclosure meta. - $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); + $this->assertContains( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ); } /**