From d77f065f244307fb50a13741304a212a0a432b3a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 10 Jul 2021 11:15:44 +0000 Subject: [PATCH] Tests: Use more appropriate assertions in various tests. This replaces instances of `assertTrue( isset( ... ) )` with `assertArrayHasKey()` to use native PHPUnit functionality. Follow-up to [51335], [51337], [51367]. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51397 602fd350-edb4-49c9-b593-d223f7449a82 --- .../testcase-rest-post-type-controller.php | 26 +++++++++---------- tests/phpunit/tests/actions.php | 2 +- tests/phpunit/tests/admin/includesPlugin.php | 4 +-- tests/phpunit/tests/adminbar.php | 8 +++--- tests/phpunit/tests/blocks/block-list.php | 4 +-- tests/phpunit/tests/dependencies.php | 4 +-- tests/phpunit/tests/dependencies/jquery.php | 2 +- tests/phpunit/tests/feed/rss2.php | 2 +- tests/phpunit/tests/hooks/removeFilter.php | 8 +++--- tests/phpunit/tests/http/base.php | 9 ++++--- tests/phpunit/tests/http/http.php | 2 +- tests/phpunit/tests/image/functions.php | 2 +- .../phpunit/tests/image/intermediateSize.php | 2 +- tests/phpunit/tests/includes/helpers.php | 2 +- tests/phpunit/tests/kses.php | 2 +- tests/phpunit/tests/media.php | 2 +- tests/phpunit/tests/meta/query.php | 4 +-- tests/phpunit/tests/oembed/filterResult.php | 8 +++--- tests/phpunit/tests/option/networkOption.php | 4 +-- tests/phpunit/tests/option/siteTransient.php | 2 +- tests/phpunit/tests/post.php | 2 +- tests/phpunit/tests/post/objects.php | 2 +- tests/phpunit/tests/post/types.php | 10 +++---- tests/phpunit/tests/rest-api.php | 6 ++--- .../rest-api/rest-attachments-controller.php | 8 +++--- .../rest-api/rest-categories-controller.php | 6 ++--- .../tests/rest-api/rest-controller.php | 2 +- .../rest-api/rest-post-types-controller.php | 10 +++---- .../tests/rest-api/rest-posts-controller.php | 8 +++--- tests/phpunit/tests/rest-api/rest-server.php | 4 +-- .../tests/rest-api/rest-tags-controller.php | 8 +++--- .../rest-api/rest-taxonomies-controller.php | 8 +++--- .../tests/rest-api/rest-themes-controller.php | 24 ++++++++--------- tests/phpunit/tests/rewrite/permastructs.php | 2 +- .../phpunit/tests/sitemaps/sitemaps-posts.php | 2 +- tests/phpunit/tests/taxonomy.php | 4 +-- tests/phpunit/tests/term/getTerm.php | 4 +-- tests/phpunit/tests/term/wpGetObjectTerms.php | 2 +- tests/phpunit/tests/theme.php | 2 +- tests/phpunit/tests/user.php | 8 +++--- tests/phpunit/tests/user/capabilities.php | 6 ++--- tests/phpunit/tests/user/multisite.php | 18 ++++++------- tests/phpunit/tests/widgets.php | 2 +- 43 files changed, 126 insertions(+), 121 deletions(-) diff --git a/tests/phpunit/includes/testcase-rest-post-type-controller.php b/tests/phpunit/includes/testcase-rest-post-type-controller.php index 32e84e340a..1ebb28f3a5 100644 --- a/tests/phpunit/includes/testcase-rest-post-type-controller.php +++ b/tests/phpunit/includes/testcase-rest-post-type-controller.php @@ -46,14 +46,14 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C $this->assertEmpty( $data['parent'] ); } } else { - $this->assertFalse( isset( $data['parent'] ) ); + $this->assertArrayNotHasKey( 'parent', $data ); } // Page attributes. if ( $post_type_obj->hierarchical && post_type_supports( $post->post_type, 'page-attributes' ) ) { $this->assertSame( $post->menu_order, $data['menu_order'] ); } else { - $this->assertFalse( isset( $data['menu_order'] ) ); + $this->assertArrayNotHasKey( 'menu_order', $data ); } // Comments. @@ -61,8 +61,8 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C $this->assertSame( $post->comment_status, $data['comment_status'] ); $this->assertSame( $post->ping_status, $data['ping_status'] ); } else { - $this->assertFalse( isset( $data['comment_status'] ) ); - $this->assertFalse( isset( $data['ping_status'] ) ); + $this->assertArrayNotHasKey( 'comment_status', $data ); + $this->assertArrayNotHasKey( 'ping_status', $data ); } if ( 'post' === $post->post_type ) { @@ -80,7 +80,7 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C if ( post_type_supports( $post->post_type, 'thumbnail' ) ) { $this->assertSame( (int) get_post_thumbnail_id( $post->ID ), $data['featured_media'] ); } else { - $this->assertFalse( isset( $data['featured_media'] ) ); + $this->assertArrayNotHasKey( 'featured_media', $data ); } // Check post format. @@ -92,7 +92,7 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C $this->assertSame( get_post_format( $post->ID ), $data['format'] ); } } else { - $this->assertFalse( isset( $data['format'] ) ); + $this->assertArrayNotHasKey( 'format', $data ); } // Check filtered values. @@ -103,10 +103,10 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C if ( 'edit' === $context ) { $this->assertSame( $post->post_title, $data['title']['raw'] ); } else { - $this->assertFalse( isset( $data['title']['raw'] ) ); + $this->assertArrayNotHasKey( 'raw', $data['title'] ); } } else { - $this->assertFalse( isset( $data['title'] ) ); + $this->assertArrayNotHasKey( 'title', $data ); } if ( post_type_supports( $post->post_type, 'editor' ) ) { @@ -118,10 +118,10 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C if ( 'edit' === $context ) { $this->assertSame( $post->post_content, $data['content']['raw'] ); } else { - $this->assertFalse( isset( $data['content']['raw'] ) ); + $this->assertArrayNotHasKey( 'raw', $data['content'] ); } } else { - $this->assertFalse( isset( $data['content'] ) ); + $this->assertArrayNotHasKey( 'content', $data ); } if ( post_type_supports( $post->post_type, 'excerpt' ) ) { @@ -134,10 +134,10 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C if ( 'edit' === $context ) { $this->assertSame( $post->post_excerpt, $data['excerpt']['raw'] ); } else { - $this->assertFalse( isset( $data['excerpt']['raw'] ) ); + $this->assertArrayNotHasKey( 'raw', $data['excerpt'] ); } } else { - $this->assertFalse( isset( $data['excerpt'] ) ); + $this->assertArrayNotHasKey( 'excerpt', $data ); } $this->assertSame( $post->post_status, $data['status'] ); @@ -149,7 +149,7 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C $taxonomies = wp_list_filter( get_object_taxonomies( $post->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { - $this->assertTrue( isset( $data[ $taxonomy->rest_base ] ) ); + $this->assertArrayHasKey( $taxonomy->rest_base, $data ); $terms = wp_get_object_terms( $post->ID, $taxonomy->name, array( 'fields' => 'ids' ) ); sort( $terms ); sort( $data[ $taxonomy->rest_base ] ); diff --git a/tests/phpunit/tests/actions.php b/tests/phpunit/tests/actions.php index ee92d104e8..2f2848100f 100644 --- a/tests/phpunit/tests/actions.php +++ b/tests/phpunit/tests/actions.php @@ -423,7 +423,7 @@ class Tests_Actions extends WP_UnitTestCase { add_action( $tag, '__return_null', 11, 1 ); - $this->assertTrue( isset( $wp_filter[ $tag ][11] ) ); + $this->assertArrayHasKey( 11, $wp_filter[ $tag ] ); $this->assertArrayHasKey( '__return_null', $wp_filter[ $tag ][11] ); unset( $wp_filter[ $tag ][11] ); diff --git a/tests/phpunit/tests/admin/includesPlugin.php b/tests/phpunit/tests/admin/includesPlugin.php index 1a989d008b..1d6bbbaf48 100644 --- a/tests/phpunit/tests/admin/includesPlugin.php +++ b/tests/phpunit/tests/admin/includesPlugin.php @@ -30,7 +30,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase { $this->assertIsArray( $data ); foreach ( $default_headers as $name => $value ) { - $this->assertTrue( isset( $data[ $name ] ) ); + $this->assertArrayHasKey( $name, $data ); $this->assertSame( $value, $data[ $name ] ); } } @@ -552,7 +552,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase { unlink( $plugin[1] ); $result = validate_active_plugins(); - $this->assertTrue( isset( $result[ $plugin[0] ] ) ); + $this->assertArrayHasKey( $plugin[0], $result ); } /** diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index 68f8daddbd..08c9d5cfd7 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -702,7 +702,7 @@ class Tests_AdminBar extends WP_UnitTestCase { $nodes = $wp_admin_bar->get_nodes(); foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { - $this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %s must not display for a regular user.', $id ) ); + $this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %s must not display for a regular user.', $id ) ); } } @@ -719,7 +719,7 @@ class Tests_AdminBar extends WP_UnitTestCase { $nodes = $wp_admin_bar->get_nodes(); foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { - $this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %s must display for a super admin.', $id ) ); + $this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %s must display for a super admin.', $id ) ); } } @@ -745,9 +745,9 @@ class Tests_AdminBar extends WP_UnitTestCase { $nodes = $wp_admin_bar->get_nodes(); foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { if ( in_array( $cap, $network_user_caps, true ) ) { - $this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) ); + $this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) ); } else { - $this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) ); + $this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) ); } } } diff --git a/tests/phpunit/tests/blocks/block-list.php b/tests/phpunit/tests/blocks/block-list.php index ffefbfadac..fa2b715d1b 100644 --- a/tests/phpunit/tests/blocks/block-list.php +++ b/tests/phpunit/tests/blocks/block-list.php @@ -51,7 +51,7 @@ class WP_Block_List_Test extends WP_UnitTestCase { $blocks = new WP_Block_List( $parsed_blocks, $context, $this->registry ); // Test "offsetExists". - $this->assertTrue( isset( $blocks[0] ) ); + $this->assertArrayHasKey( 0, $blocks ); // Test "offsetGet". $this->assertSame( 'core/example', $blocks[0]->name ); @@ -63,7 +63,7 @@ class WP_Block_List_Test extends WP_UnitTestCase { // Test "offsetUnset". unset( $blocks[0] ); - $this->assertFalse( isset( $blocks[0] ) ); + $this->assertArrayNotHasKey( 0, $blocks ); } /** diff --git a/tests/phpunit/tests/dependencies.php b/tests/phpunit/tests/dependencies.php index 5ec6f2b276..e36d2ed5d4 100644 --- a/tests/phpunit/tests/dependencies.php +++ b/tests/phpunit/tests/dependencies.php @@ -100,12 +100,12 @@ class Tests_Dependencies extends WP_UnitTestCase { $dep->dequeue( 'one' ); $this->assertFalse( $dep->query( 'one', 'queue' ) ); $this->assertTrue( $dep->query( 'two', 'queue' ) ); - $this->assertFalse( isset( $dep->args['one'] ) ); + $this->assertArrayNotHasKey( 'one', $dep->args ); $dep->dequeue( 'two' ); $this->assertFalse( $dep->query( 'one', 'queue' ) ); $this->assertFalse( $dep->query( 'two', 'queue' ) ); - $this->assertFalse( isset( $dep->args['two'] ) ); + $this->assertArrayNotHasKey( 'two', $dep->args ); } /** diff --git a/tests/phpunit/tests/dependencies/jquery.php b/tests/phpunit/tests/dependencies/jquery.php index 082d0e6bd0..f812d9b8de 100644 --- a/tests/phpunit/tests/dependencies/jquery.php +++ b/tests/phpunit/tests/dependencies/jquery.php @@ -34,7 +34,7 @@ class Tests_Dependencies_jQuery extends WP_UnitTestCase { foreach ( $object->deps as $dep ) { $o = $scripts->query( $dep, 'registered' ); $this->assertInstanceOf( '_WP_Dependency', $object ); - $this->assertTrue( isset( $jquery_scripts[ $dep ] ) ); + $this->assertArrayHasKey( $dep, $jquery_scripts ); $this->assertSame( $jquery_scripts[ $dep ], $o->src ); } } diff --git a/tests/phpunit/tests/feed/rss2.php b/tests/phpunit/tests/feed/rss2.php index 1abd298397..25c0efcc45 100644 --- a/tests/phpunit/tests/feed/rss2.php +++ b/tests/phpunit/tests/feed/rss2.php @@ -131,7 +131,7 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase { $channel = xml_find( $xml, 'rss', 'channel' ); // The channel should be free of attributes. - $this->assertTrue( empty( $channel[0]['attributes'] ) ); + $this->assertArrayNotHasKey( 'attributes', $channel[0] ); // Verify the channel is present and contains a title child element. $title = xml_find( $xml, 'rss', 'channel', 'title' ); diff --git a/tests/phpunit/tests/hooks/removeFilter.php b/tests/phpunit/tests/hooks/removeFilter.php index d1c4eb7106..793cd02b3c 100644 --- a/tests/phpunit/tests/hooks/removeFilter.php +++ b/tests/phpunit/tests/hooks/removeFilter.php @@ -18,7 +18,7 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase { $hook->add_filter( $tag, $callback, $priority, $accepted_args ); $hook->remove_filter( $tag, $callback, $priority ); - $this->assertFalse( isset( $hook->callbacks[ $priority ] ) ); + $this->assertArrayNotHasKey( $priority, $hook->callbacks ); } public function test_remove_filter_with_object() { @@ -32,7 +32,7 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase { $hook->add_filter( $tag, $callback, $priority, $accepted_args ); $hook->remove_filter( $tag, $callback, $priority ); - $this->assertFalse( isset( $hook->callbacks[ $priority ] ) ); + $this->assertArrayNotHasKey( $priority, $hook->callbacks ); } public function test_remove_filter_with_static_method() { @@ -45,7 +45,7 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase { $hook->add_filter( $tag, $callback, $priority, $accepted_args ); $hook->remove_filter( $tag, $callback, $priority ); - $this->assertFalse( isset( $hook->callbacks[ $priority ] ) ); + $this->assertArrayNotHasKey( $priority, $hook->callbacks ); } public function test_remove_filters_with_another_at_same_priority() { @@ -76,7 +76,7 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase { $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args ); $hook->remove_filter( $tag, $callback_one, $priority ); - $this->assertFalse( isset( $hook->callbacks[ $priority ] ) ); + $this->assertArrayNotHasKey( $priority, $hook->callbacks ); $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] ); } } diff --git a/tests/phpunit/tests/http/base.php b/tests/phpunit/tests/http/base.php index 2dd254a7fa..8dd002f830 100644 --- a/tests/phpunit/tests/http/base.php +++ b/tests/phpunit/tests/http/base.php @@ -255,11 +255,14 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $headers[ $parts[0] ] = $parts[1]; } - $this->assertTrue( isset( $headers['test1'] ) && 'test' === $headers['test1'] ); - $this->assertTrue( isset( $headers['test2'] ) && '0' === $headers['test2'] ); + $this->assertArrayHasKey( 'test1', $headers ); + $this->assertSame( 'test', $headers['test1'] ); + $this->assertArrayHasKey( 'test2', $headers ); + $this->assertSame( '0', $headers['test2'] ); // cURL/HTTP Extension Note: Will never pass, cURL does not pass headers with an empty value. // Should it be that empty headers with empty values are NOT sent? - // $this->assertTrue( isset( $headers['test3'] ) && '' === $headers['test3'] ); + // $this->assertArrayHasKey( 'test3', $headers ); + // $this->assertSame( '', $headers['test3'] ); } /** diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index f8ae30e6c2..1ece726d04 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -313,7 +313,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { foreach ( array_keys( $cookies ) as $cookie ) { if ( 'foo' === $cookie ) { - $this->assertFalse( isset( $cookie_jar[ $cookie ] ) ); + $this->assertArrayNotHasKey( $cookie, $cookie_jar ); } else { $this->assertInstanceOf( 'Requests_Cookie', $cookie_jar[ $cookie ] ); } diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 6b1e371f1e..3f79070b09 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -647,7 +647,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { ); $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); - $this->assertTrue( isset( $metadata['sizes']['test-size'] ), 'The `test-size` was not added to the metadata.' ); + $this->assertArrayHasKey( 'test-size', $metadata['sizes'], 'The `test-size` was not added to the metadata.' ); $this->assertSame( $metadata['sizes']['test-size'], $expected ); remove_image_size( 'test-size' ); diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php index b44334c70a..9b0e651c82 100644 --- a/tests/phpunit/tests/image/intermediateSize.php +++ b/tests/phpunit/tests/image/intermediateSize.php @@ -59,7 +59,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $this->assertSame( 75, $image['height'] ); $this->assertSame( 'image/jpeg', $image['mime-type'] ); - $this->assertFalse( isset( $image['path'] ) ); + $this->assertArrayNotHasKey( 'path', $image ); } /** diff --git a/tests/phpunit/tests/includes/helpers.php b/tests/phpunit/tests/includes/helpers.php index c33cc2f83a..a2baf75089 100644 --- a/tests/phpunit/tests/includes/helpers.php +++ b/tests/phpunit/tests/includes/helpers.php @@ -227,7 +227,7 @@ class Tests_TestHelpers extends WP_UnitTestCase { $stati = get_post_stati(); - $this->assertFalse( isset( $stati['foo'] ) ); + $this->assertArrayNotHasKey( 'foo', $stati ); } /** diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index 1d5dfdff60..961ed71b16 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -507,7 +507,7 @@ EOF; $this->assertTrue( $tags['a']['rel'] ); $tags = wp_kses_allowed_html(); - $this->assertFalse( isset( $tags['a']['rel'] ) ); + $this->assertArrayNotHasKey( 'rel', $tags['a'] ); $this->assertSame( array(), wp_kses_allowed_html( 'strip' ) ); diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 6ff6ac3822..816ba75b51 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -446,7 +446,7 @@ https://w.org', $prepped = wp_prepare_attachment_for_js( get_post( $id ) ); - $this->assertTrue( isset( $prepped['sizes'] ) ); + $this->assertArrayHasKey( 'sizes', $prepped ); } /** diff --git a/tests/phpunit/tests/meta/query.php b/tests/phpunit/tests/meta/query.php index bca15e5ec8..5b3815d47d 100644 --- a/tests/phpunit/tests/meta/query.php +++ b/tests/phpunit/tests/meta/query.php @@ -146,7 +146,7 @@ class Tests_Meta_Query extends WP_UnitTestCase { $query = new WP_Meta_Query(); $query->parse_query_vars( $qv ); - $this->assertTrue( ! isset( $query->queries[0]['value'] ) ); + $this->assertArrayNotHasKey( 'value', $query->queries[0] ); } /** @@ -163,7 +163,7 @@ class Tests_Meta_Query extends WP_UnitTestCase { $query = new WP_Meta_Query(); $query->parse_query_vars( $qv ); - $this->assertTrue( ! isset( $query->queries[0]['value'] ) ); + $this->assertArrayNotHasKey( 'value', $query->queries[0] ); } /** diff --git a/tests/phpunit/tests/oembed/filterResult.php b/tests/phpunit/tests/oembed/filterResult.php index 8107dc5e3f..0bea036996 100644 --- a/tests/phpunit/tests/oembed/filterResult.php +++ b/tests/phpunit/tests/oembed/filterResult.php @@ -19,8 +19,8 @@ class Tests_Filter_oEmbed_Result extends WP_UnitTestCase { $matches = array(); preg_match( '|src=".*#\?secret=([\w\d]+)" data-secret="([\w\d]+)"|', $actual, $matches ); - $this->assertTrue( isset( $matches[1] ) ); - $this->assertTrue( isset( $matches[2] ) ); + $this->assertArrayHasKey( 1, $matches ); + $this->assertArrayHasKey( 2, $matches ); $this->assertSame( $matches[1], $matches[2] ); } @@ -63,8 +63,8 @@ EOD; $matches = array(); preg_match( '|src="https://wordpress.org#\?secret=([\w\d]+)" data-secret="([\w\d]+)"|', $actual, $matches ); - $this->assertTrue( isset( $matches[1] ) ); - $this->assertTrue( isset( $matches[2] ) ); + $this->assertArrayHasKey( 1, $matches ); + $this->assertArrayHasKey( 2, $matches ); $this->assertSame( $matches[1], $matches[2] ); } diff --git a/tests/phpunit/tests/option/networkOption.php b/tests/phpunit/tests/option/networkOption.php index a6cd1b6690..bf2e27504c 100644 --- a/tests/phpunit/tests/option/networkOption.php +++ b/tests/phpunit/tests/option/networkOption.php @@ -61,7 +61,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase { $options = wp_load_alloptions(); - $this->assertFalse( isset( $options[ $key ] ) ); + $this->assertArrayNotHasKey( $key, $options ); } /** @@ -75,7 +75,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase { $options = wp_load_alloptions(); - $this->assertFalse( isset( $options[ $key ] ) ); + $this->assertArrayNotHasKey( $key, $options ); } /** diff --git a/tests/phpunit/tests/option/siteTransient.php b/tests/phpunit/tests/option/siteTransient.php index 7050b2cd90..f4c9a86c0a 100644 --- a/tests/phpunit/tests/option/siteTransient.php +++ b/tests/phpunit/tests/option/siteTransient.php @@ -56,6 +56,6 @@ class Tests_Option_SiteTransient extends WP_UnitTestCase { $options = wp_load_alloptions(); - $this->assertFalse( isset( $options[ '_site_transient_' . $key ] ) ); + $this->assertArrayNotHasKey( '_site_transient_' . $key, $options ); } } diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 65dd4ae783..ebea603414 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -891,7 +891,7 @@ class Tests_Post extends WP_UnitTestCase { register_post_status( 'test' ); $counts = wp_count_posts(); - $this->assertTrue( isset( $counts->test ) ); + $this->assertObjectHasAttribute( 'test', $counts ); $this->assertSame( 0, $counts->test ); } diff --git a/tests/phpunit/tests/post/objects.php b/tests/phpunit/tests/post/objects.php index 4602b014c7..71cfc754d8 100644 --- a/tests/phpunit/tests/post/objects.php +++ b/tests/phpunit/tests/post/objects.php @@ -35,7 +35,7 @@ class Tests_Post_Objects extends WP_UnitTestCase { $post = get_post( $id, ARRAY_N ); $this->assertIsArray( $post ); - $this->assertFalse( isset( $post['post_type'] ) ); + $this->assertArrayNotHasKey( 'post_type', $post ); $this->assertTrue( in_array( 'post', $post, true ) ); $post = get_post( $id ); diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php index 00615623e3..ca2cbb8761 100644 --- a/tests/phpunit/tests/post/types.php +++ b/tests/phpunit/tests/post/types.php @@ -394,9 +394,9 @@ class Tests_Post_Types extends WP_UnitTestCase { $this->assertTrue( unregister_post_type( 'foo' ) ); - $this->assertFalse( isset( $post_type_meta_caps['read_bar'] ) ); - $this->assertFalse( isset( $post_type_meta_caps['delete_bar'] ) ); - $this->assertFalse( isset( $post_type_meta_caps['edit_bar'] ) ); + $this->assertArrayNotHasKey( 'read_bar', $post_type_meta_caps ); + $this->assertArrayNotHasKey( 'delete_bar', $post_type_meta_caps ); + $this->assertArrayNotHasKey( 'edit_bar', $post_type_meta_caps ); } /** @@ -422,7 +422,7 @@ class Tests_Post_Types extends WP_UnitTestCase { $_wp_post_type_features['foo'] ); $this->assertTrue( unregister_post_type( 'foo' ) ); - $this->assertFalse( isset( $_wp_post_type_features['foo'] ) ); + $this->assertArrayNotHasKey( 'foo', $_wp_post_type_features ); } /** @@ -504,7 +504,7 @@ class Tests_Post_Types extends WP_UnitTestCase { $this->assertTrue( unregister_post_type( 'foo' ) ); - $this->assertFalse( isset( $wp_post_types['foo'] ) ); + $this->assertArrayNotHasKey( 'foo', $wp_post_types ); $this->assertNull( get_post_type_object( 'foo' ) ); } diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index f6e057ba8d..e271d369a0 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -237,7 +237,7 @@ class Tests_REST_API extends WP_UnitTestCase { true ); $endpoints = $GLOBALS['wp_rest_server']->get_routes(); - $this->assertFalse( isset( $endpoints['/test-empty-namespace'] ) ); + $this->assertArrayNotHasKey( '/test-empty-namespace', $endpoints ); } /** @@ -257,7 +257,7 @@ class Tests_REST_API extends WP_UnitTestCase { true ); $endpoints = $GLOBALS['wp_rest_server']->get_routes(); - $this->assertFalse( isset( $endpoints['/test-empty-route'] ) ); + $this->assertArrayNotHasKey( '/test-empty-route', $endpoints ); } /** @@ -951,7 +951,7 @@ class Tests_REST_API extends WP_UnitTestCase { ); $this->assertSame( array_keys( $preload_data ), array( '/wp/v2/types', 'OPTIONS' ) ); - $this->assertTrue( isset( $preload_data['OPTIONS']['/wp/v2/media'] ) ); + $this->assertArrayHasKey( '/wp/v2/media', $preload_data['OPTIONS'] ); $GLOBALS['wp_rest_server'] = $rest_server; } diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index f8773358e6..2673d738ce 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -691,7 +691,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control remove_image_size( 'rest-api-test' ); $this->assertIsArray( $data['media_details']['sizes'], 'Could not retrieve the sizes data.' ); - $this->assertFalse( isset( $data['media_details']['sizes']['rest-api-test']['source_url'] ) ); + $this->assertArrayNotHasKey( 'source_url', $data['media_details']['sizes']['rest-api-test'] ); } public function test_get_item_private_post_not_authenticated() { @@ -1686,10 +1686,10 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertSame( $attachment->post_excerpt, $data['caption']['raw'] ); $this->assertSame( $attachment->post_content, $data['description']['raw'] ); } else { - $this->assertFalse( isset( $data['caption']['raw'] ) ); - $this->assertFalse( isset( $data['description']['raw'] ) ); + $this->assertArrayNotHasKey( 'raw', $data['caption'] ); + $this->assertArrayNotHasKey( 'raw', $data['description'] ); } - $this->assertTrue( isset( $data['media_details'] ) ); + $this->assertArrayHasKey( 'media_details', $data ); if ( $attachment->post_parent ) { $this->assertSame( $attachment->post_parent, $data['post'] ); diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index fb6d291d57..51878f548c 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -747,7 +747,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas $this->assertArrayHasKey( 'meta', $data ); $meta = (array) $data['meta']; - $this->assertFalse( isset( $meta['test_tag_meta'] ) ); + $this->assertArrayNotHasKey( 'test_tag_meta', $meta ); } public function test_get_term_invalid_taxonomy() { @@ -942,7 +942,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas $this->assertSame( 'new-slug', $data['slug'] ); $this->assertSame( 'just meta', $data['meta']['test_single'] ); $this->assertSame( 'category-specific meta', $data['meta']['test_cat_single'] ); - $this->assertFalse( isset( $data['meta']['test_tag_meta'] ) ); + $this->assertArrayNotHasKey( 'test_tag_meta', $data['meta'] ); } public function test_update_item_invalid_taxonomy() { @@ -1209,7 +1209,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas if ( $taxonomy->hierarchical ) { $this->assertSame( $term->parent, $data['parent'] ); } else { - $this->assertFalse( isset( $term->parent ) ); + $this->assertObjectNotHasProperty( 'parent', $term ); } $relations = array( diff --git a/tests/phpunit/tests/rest-api/rest-controller.php b/tests/phpunit/tests/rest-api/rest-controller.php index 717bc1b214..8a4d41bc29 100644 --- a/tests/phpunit/tests/rest-api/rest-controller.php +++ b/tests/phpunit/tests/rest-api/rest-controller.php @@ -249,7 +249,7 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase { $args = rest_get_endpoint_args_for_schema( $controller->get_item_schema() ); $this->assertSame( 'A pretty string.', $args['somestring']['description'] ); - $this->assertFalse( isset( $args['someinteger']['description'] ) ); + $this->assertArrayNotHasKey( 'description', $args['someinteger'] ); } public function test_get_endpoint_args_for_item_schema_arg_options() { diff --git a/tests/phpunit/tests/rest-api/rest-post-types-controller.php b/tests/phpunit/tests/rest-api/rest-post-types-controller.php index 2a30c5e520..0e06bf9d15 100644 --- a/tests/phpunit/tests/rest-api/rest-post-types-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-types-controller.php @@ -43,7 +43,7 @@ class WP_Test_REST_Post_Types_Controller extends WP_Test_REST_Controller_Testcas $this->check_post_type_obj( 'view', $post_types['post'], $data['post'], $data['post']['_links'] ); $this->assertSame( $post_types['page']->name, $data['page']['slug'] ); $this->check_post_type_obj( 'view', $post_types['page'], $data['page'], $data['page']['_links'] ); - $this->assertFalse( isset( $data['revision'] ) ); + $this->assertArrayNotHasKey( 'revision', $data ); } public function test_get_items_invalid_permission_for_context() { @@ -218,10 +218,10 @@ class WP_Test_REST_Post_Types_Controller extends WP_Test_REST_Controller_Testcas $this->assertSame( $viewable, $data['viewable'] ); $this->assertSame( get_all_post_type_supports( $post_type_obj->name ), $data['supports'] ); } else { - $this->assertFalse( isset( $data['capabilities'] ) ); - $this->assertFalse( isset( $data['viewable'] ) ); - $this->assertFalse( isset( $data['labels'] ) ); - $this->assertFalse( isset( $data['supports'] ) ); + $this->assertArrayNotHasKey( 'capabilities', $data ); + $this->assertArrayNotHasKey( 'viewable', $data ); + $this->assertArrayNotHasKey( 'labels', $data ); + $this->assertArrayNotHasKey( 'supports', $data ); } } diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index d1a8c48732..7639e76724 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -1777,7 +1777,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertSame( rest_url( '/wp/v2/posts/' . self::$post_id . '/revisions' ), $links['version-history'][0]['href'] ); $this->assertSame( 0, $links['version-history'][0]['attributes']['count'] ); - $this->assertFalse( isset( $links['predecessor-version'] ) ); + $this->assertArrayNotHasKey( 'predecessor-version', $links ); $attachments_url = rest_url( '/wp/v2/media' ); $attachments_url = add_query_arg( 'parent', self::$post_id, $attachments_url ); @@ -1833,7 +1833,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); $response = rest_get_server()->dispatch( $request ); $links = $response->get_links(); - $this->assertFalse( isset( $links['author'] ) ); + $this->assertArrayNotHasKey( 'author', $links ); wp_update_post( array( 'ID' => self::$post_id, @@ -2030,7 +2030,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); - $this->assertFalse( isset( $data['content']['block_version'] ) ); + $this->assertArrayNotHasKey( 'block_version', $data['content'] ); } /** @@ -4157,7 +4157,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te ); create_initial_rest_routes(); $routes = rest_get_server()->get_routes(); - $this->assertFalse( isset( $routes['/wp/v2/invalid-controller'] ) ); + $this->assertArrayNotHasKey( '/wp/v2/invalid-controller', $routes ); _unregister_post_type( 'invalid-controller' ); } diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 999ae6349c..435675e287 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -1118,12 +1118,12 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { continue; } - $this->assertTrue( isset( $headers[ $header ] ), sprintf( 'Header %s is not present in the response.', $header ) ); + $this->assertArrayHasKey( $header, $headers, sprintf( 'Header %s is not present in the response.', $header ) ); $this->assertSame( $value, $headers[ $header ] ); } // Last-Modified should be unset as per #WP23021. - $this->assertFalse( isset( $headers['Last-Modified'] ), 'Last-Modified should not be sent.' ); + $this->assertArrayNotHasKey( 'Last-Modified', $headers, 'Last-Modified should not be sent.' ); } public function test_no_nocache_headers_on_unauthenticated_requests() { diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index 23f41acb7f..1e4998b85e 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -700,7 +700,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $this->assertArrayHasKey( 'meta', $data ); $meta = (array) $data['meta']; - $this->assertFalse( isset( $meta['test_cat_meta'] ) ); + $this->assertArrayNotHasKey( 'test_cat_meta', $meta ); } public function test_get_term_invalid_term() { @@ -874,7 +874,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $this->assertSame( 'new-slug', $data['slug'] ); $this->assertSame( 'just meta', $data['meta']['test_single'] ); $this->assertSame( 'tag-specific meta', $data['meta']['test_tag_single'] ); - $this->assertFalse( isset( $data['meta']['test_cat_meta'] ) ); + $this->assertArrayNotHasKey( 'test_cat_meta', $data['meta'] ); } public function test_update_item_no_change() { @@ -1242,7 +1242,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $data = $response->get_data(); $properties = $data['schema']['properties']; $this->assertArrayHasKey( 'id', $properties ); - $this->assertFalse( isset( $properties['parent'] ) ); + $this->assertArrayNotHasKey( 'parent', $properties ); } public function test_get_additional_field_registration() { @@ -1427,7 +1427,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { if ( $taxonomy->hierarchical ) { $this->assertSame( $term->parent, $data['parent'] ); } else { - $this->assertFalse( isset( $data['parent'] ) ); + $this->assertArrayNotHasKey( 'parent', $data ); } $expected_links = array( 'self', diff --git a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php index acca692482..357e1c7e17 100644 --- a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php +++ b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php @@ -266,10 +266,10 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas $this->assertSame( $tax_obj->show_in_quick_edit, $data['visibility']['show_in_quick_edit'] ); $this->assertSame( $tax_obj->show_ui, $data['visibility']['show_ui'] ); } else { - $this->assertFalse( isset( $data['capabilities'] ) ); - $this->assertFalse( isset( $data['labels'] ) ); - $this->assertFalse( isset( $data['show_cloud'] ) ); - $this->assertFalse( isset( $data['visibility'] ) ); + $this->assertArrayNotHasKey( 'capabilities', $data ); + $this->assertArrayNotHasKey( 'labels', $data ); + $this->assertArrayNotHasKey( 'show_cloud', $data ); + $this->assertArrayNotHasKey( 'visibility', $data ); } } diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 13c941c67b..b8b864a6a7 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -1029,8 +1029,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { remove_theme_support( 'post-formats' ); $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); - $this->assertTrue( isset( $result[0]['theme_supports']['formats'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); + $this->assertArrayHasKey( 'formats', $result[0]['theme_supports'] ); $this->assertSame( array( 'standard' ), $result[0]['theme_supports']['formats'] ); } @@ -1043,8 +1043,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { add_theme_support( 'post-formats', array( 'aside', 'video' ) ); $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); - $this->assertTrue( isset( $result[0]['theme_supports']['formats'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); + $this->assertArrayHasKey( 'formats', $result[0]['theme_supports'] ); $this->assertSame( array( 'standard', 'aside', 'video' ), $result[0]['theme_supports']['formats'] ); } @@ -1058,8 +1058,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); - $this->assertTrue( isset( $result[0]['theme_supports']['responsive-embeds'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); + $this->assertArrayHasKey( 'responsive-embeds', $result[0]['theme_supports'] ); $this->assertFalse( $result[0]['theme_supports']['responsive-embeds'] ); } @@ -1073,7 +1073,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { add_theme_support( 'responsive-embeds' ); $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); $this->assertTrue( $result[0]['theme_supports']['responsive-embeds'] ); } @@ -1087,8 +1087,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); - $this->assertTrue( isset( $result[0]['theme_supports']['post-thumbnails'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); + $this->assertArrayHasKey( 'post-thumbnails', $result[0]['theme_supports'] ); $this->assertFalse( $result[0]['theme_supports']['post-thumbnails'] ); } @@ -1102,7 +1102,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { add_theme_support( 'post-thumbnails' ); $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); $this->assertTrue( $result[0]['theme_supports']['post-thumbnails'] ); } @@ -1116,7 +1116,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { add_theme_support( 'post-thumbnails', array( 'post' ) ); $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); $this->assertSame( array( 'post' ), $result[0]['theme_supports']['post-thumbnails'] ); } @@ -1142,7 +1142,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { $response = self::perform_active_theme_request(); $result = $response->get_data(); - $this->assertTrue( isset( $result[0]['theme_supports'] ) ); + $this->assertArrayHasKey( 'theme_supports', $result[0] ); $this->assertSame( array( 'a', 'b', 'c' ), $result[0]['theme_supports']['test-feature'] ); } diff --git a/tests/phpunit/tests/rewrite/permastructs.php b/tests/phpunit/tests/rewrite/permastructs.php index 1605b2c00d..f2fde194af 100644 --- a/tests/phpunit/tests/rewrite/permastructs.php +++ b/tests/phpunit/tests/rewrite/permastructs.php @@ -38,6 +38,6 @@ class Tests_Rewrite_Permastructs extends WP_UnitTestCase { $this->assertSame( '/bar/%foo%', $wp_rewrite->extra_permastructs['foo']['struct'] ); remove_permastruct( 'foo' ); - $this->assertFalse( isset( $wp_rewrite->extra_permastructs['foo'] ) ); + $this->assertArrayNotHasKey( 'foo', $wp_rewrite->extra_permastructs ); } } diff --git a/tests/phpunit/tests/sitemaps/sitemaps-posts.php b/tests/phpunit/tests/sitemaps/sitemaps-posts.php index a5be317ce4..169729a28b 100644 --- a/tests/phpunit/tests/sitemaps/sitemaps-posts.php +++ b/tests/phpunit/tests/sitemaps/sitemaps-posts.php @@ -58,7 +58,7 @@ class Test_WP_Sitemaps_Posts extends WP_UnitTestCase { $url_list = $posts_provider->get_url_list( 1, 'page' ); $sitemap_entry = array_shift( $url_list ); - $this->assertTrue( isset( $sitemap_entry['lastmod'] ) ); + $this->assertArrayHasKey( 'lastmod', $sitemap_entry ); } /** diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 6ae814a7e7..8e256f8928 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -842,7 +842,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { $this->assertIsArray( $wp_rewrite->extra_permastructs['foo'] ); $this->assertTrue( unregister_taxonomy( 'foo' ) ); - $this->assertFalse( isset( $wp_rewrite->extra_permastructs['foo'] ) ); + $this->assertArrayNotHasKey( 'foo', $wp_rewrite->extra_permastructs ); } /** @@ -878,7 +878,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { $this->assertTrue( unregister_taxonomy( 'foo' ) ); - $this->assertFalse( isset( $wp_taxonomies['foo'] ) ); + $this->assertArrayNotHasKey( 'foo', $wp_taxonomies ); $this->assertFalse( get_taxonomy( 'foo' ) ); } diff --git a/tests/phpunit/tests/term/getTerm.php b/tests/phpunit/tests/term/getTerm.php index d2aef46e9a..2b32500345 100644 --- a/tests/phpunit/tests/term/getTerm.php +++ b/tests/phpunit/tests/term/getTerm.php @@ -104,14 +104,14 @@ class Tests_Term_GetTerm extends WP_UnitTestCase { $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); $term = get_term( $t, 'wptests_tax', ARRAY_A ); $this->assertIsArray( $term ); - $this->assertTrue( isset( $term['term_id'] ) ); + $this->assertArrayHasKey( 'term_id', $term ); } public function test_output_array_n() { $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); $term = get_term( $t, 'wptests_tax', ARRAY_N ); $this->assertIsArray( $term ); - $this->assertFalse( isset( $term['term_id'] ) ); + $this->assertArrayNotHasKey( 'term_id', $term ); foreach ( $term as $k => $v ) { $this->assertIsInt( $k ); } diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php index 03e2301ecf..bc85e6e3ba 100644 --- a/tests/phpunit/tests/term/wpGetObjectTerms.php +++ b/tests/phpunit/tests/term/wpGetObjectTerms.php @@ -838,7 +838,7 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { } $term = get_term( $t ); - $this->assertFalse( isset( $term->object_id ) ); + $this->assertObjectNotHasAttribute( 'object_id', $term ); } /** diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index a04b817306..9e54eebf8c 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -131,7 +131,7 @@ class Tests_Theme extends WP_UnitTestCase { 'Theme Root URI' => 'Theme Root URI', ); foreach ( $default_headers as $name => $value ) { - $this->assertTrue( isset( $theme[ $name ] ) ); + $this->assertArrayHasKey( $name, $theme ); } // Make the tests work both for WordPress 2.8.5 and WordPress 2.9-rare. diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 9ff5a4749a..e913c454c5 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -166,7 +166,8 @@ class Tests_User extends WP_UnitTestCase { // For reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere. // So we'll just check to make sure our values are included somewhere. foreach ( $vals as $k => $v ) { - $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v ); + $this->assertArrayHasKey( $k, $out ); + $this->assertSame( $v, $out[ $k ][0] ); } // Delete one key and check again. $keys = array_keys( $vals ); @@ -176,9 +177,10 @@ class Tests_User extends WP_UnitTestCase { // Make sure that key is excluded from the results. foreach ( $vals as $k => $v ) { if ( $k === $key_to_delete ) { - $this->assertFalse( isset( $out[ $k ] ) ); + $this->assertArrayNotHasKey( $k, $out ); } else { - $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v ); + $this->assertArrayHasKey( $k, $out ); + $this->assertSame( $v, $out[ $k ][0] ); } } } diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index 9079ed413a..f52b3f7dbe 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -1608,11 +1608,11 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $author = self::$users['author']; $author->add_cap( 'foo', false ); - $this->assertTrue( isset( $author->caps['foo'] ) ); + $this->assertArrayHasKey( 'foo', $author->caps ); $this->assertFalse( user_can( $author->ID, 'foo' ) ); $author->remove_cap( 'foo' ); - $this->assertFalse( isset( $author->caps['foo'] ) ); + $this->assertArrayNotHasKey( 'foo', $author->caps ); $this->assertFalse( user_can( $author->ID, 'foo' ) ); } @@ -2237,7 +2237,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $wp_roles = wp_roles(); $wp_roles->for_site( $site_id ); - $this->assertTrue( isset( $wp_roles->role_objects[ $role_name ] ) ); + $this->assertArrayHasKey( $role_name, $wp_roles->role_objects ); } /** diff --git a/tests/phpunit/tests/user/multisite.php b/tests/phpunit/tests/user/multisite.php index 89daba1b29..7a20cb16a9 100644 --- a/tests/phpunit/tests/user/multisite.php +++ b/tests/phpunit/tests/user/multisite.php @@ -72,15 +72,15 @@ if ( is_multisite() ) : // Each site retrieved should match the expected structure. foreach ( $blogs_of_user as $blog_id => $blog ) { $this->assertSame( $blog_id, $blog->userblog_id ); - $this->assertTrue( isset( $blog->userblog_id ) ); - $this->assertTrue( isset( $blog->blogname ) ); - $this->assertTrue( isset( $blog->domain ) ); - $this->assertTrue( isset( $blog->path ) ); - $this->assertTrue( isset( $blog->site_id ) ); - $this->assertTrue( isset( $blog->siteurl ) ); - $this->assertTrue( isset( $blog->archived ) ); - $this->assertTrue( isset( $blog->spam ) ); - $this->assertTrue( isset( $blog->deleted ) ); + $this->assertObjectHasAttribute( 'userblog_id', $blog ); + $this->assertObjectHasAttribute( 'blogname', $blog ); + $this->assertObjectHasAttribute( 'domain', $blog ); + $this->assertObjectHasAttribute( 'path', $blog ); + $this->assertObjectHasAttribute( 'site_id', $blog ); + $this->assertObjectHasAttribute( 'siteurl', $blog ); + $this->assertObjectHasAttribute( 'archived', $blog ); + $this->assertObjectHasAttribute( 'spam', $blog ); + $this->assertObjectHasAttribute( 'deleted', $blog ); } // Mark each remaining site as spam, archived, and deleted. diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index c3ddfca599..327f43b87c 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -134,7 +134,7 @@ class Tests_Widgets extends WP_UnitTestCase { register_sidebars( 1, array( 'id' => 'wp-unit-test' ) ); - $this->assertTrue( isset( $wp_registered_sidebars['wp-unit-test'] ) ); + $this->assertArrayHasKey( 'wp-unit-test', $wp_registered_sidebars ); }