diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index b06fffe2c1..66dc212530 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -456,6 +456,18 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { } } + /** + * Asserts that a condition is not false. + * + * @param bool $condition + * @param string $message + * + * @throws PHPUnit_Framework_AssertionFailedError + */ + public static function assertNotFalse( $condition, $message = '' ) { + self::assertThat( $condition, self::logicalNot( self::isFalse() ), $message ); + } + /** * Modify WordPress's query internals as if a given URL has been requested. * diff --git a/tests/phpunit/tests/customize/custom-css-setting.php b/tests/phpunit/tests/customize/custom-css-setting.php index e52eec1b1f..3dea39ed2f 100644 --- a/tests/phpunit/tests/customize/custom-css-setting.php +++ b/tests/phpunit/tests/customize/custom-css-setting.php @@ -150,7 +150,7 @@ class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase { $this->wp_customize->set_post_value( $this->setting->id, $updated_css ); $saved = $this->setting->save(); - $this->assertTrue( false !== $saved ); + $this->assertNotFalse( $saved ); $this->assertEquals( $updated_css, $this->setting->value() ); $this->assertEquals( $updated_css, wp_get_custom_css( $this->setting->stylesheet ) ); $this->assertEquals( $updated_css, get_post( $post_id )->post_content ); diff --git a/tests/phpunit/tests/customize/setting.php b/tests/phpunit/tests/customize/setting.php index 03fd0c28b1..86a0743941 100644 --- a/tests/phpunit/tests/customize/setting.php +++ b/tests/phpunit/tests/customize/setting.php @@ -456,7 +456,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase { // Satisfy all requirements for save to happen. wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); - $this->assertTrue( false !== $setting->save() ); + $this->assertNotFalse( $setting->save() ); $this->assertTrue( 1 === did_action( 'customize_update_custom' ) ); $this->assertTrue( 1 === did_action( 'customize_save_foo' ) ); } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index d8c28c2191..5d1e52be85 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1175,7 +1175,7 @@ EOF; // Test to confirm all sources in the array include the same edit hash. foreach ( $sizes as $size ) { - $this->assertTrue( false !== strpos( $size, $hash ) ); + $this->assertNotFalse( strpos( $size, $hash ) ); } } diff --git a/tests/phpunit/tests/oembed/template.php b/tests/phpunit/tests/oembed/template.php index fd9fddd2b7..48245d1125 100644 --- a/tests/phpunit/tests/oembed/template.php +++ b/tests/phpunit/tests/oembed/template.php @@ -25,8 +25,8 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); - $this->assertTrue( false === strpos( $actual, 'That embed can’t be found.' ) ); - $this->assertTrue( false !== strpos( $actual, 'Hello World' ) ); + $this->assertFalse( strpos( $actual, 'That embed can’t be found.' ) ); + $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); } function test_oembed_output_post_with_thumbnail() { @@ -52,8 +52,8 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); $this->assertFalse( strpos( $actual, 'That embed can’t be found.' ) ); - $this->assertTrue( false !== strpos( $actual, 'Hello World' ) ); - $this->assertTrue( false !== strpos( $actual, 'canola.jpg' ) ); + $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); + $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) ); } function test_oembed_output_404() { @@ -68,7 +68,7 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); - $this->assertTrue( false !== strpos( $actual, 'That embed can’t be found.' ) ); + $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); } function test_oembed_output_attachment() { @@ -92,8 +92,8 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); $this->assertFalse( strpos( $actual, 'That embed can’t be found.' ) ); - $this->assertTrue( false !== strpos( $actual, 'Hello World' ) ); - $this->assertTrue( false !== strpos( $actual, 'canola.jpg' ) ); + $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); + $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) ); } function test_oembed_output_draft_post() { @@ -114,7 +114,7 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); - $this->assertTrue( false !== strpos( $actual, 'That embed can’t be found.' ) ); + $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); } function test_oembed_output_scheduled_post() { @@ -136,7 +136,7 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); - $this->assertTrue( false !== strpos( $actual, 'That embed can’t be found.' ) ); + $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); } function test_oembed_output_private_post() { @@ -157,7 +157,7 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); - $this->assertTrue( false !== strpos( $actual, 'That embed can’t be found.' ) ); + $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); } function test_oembed_output_private_post_with_permissions() { @@ -182,8 +182,8 @@ class Tests_Embed_Template extends WP_UnitTestCase { $doc = new DOMDocument(); $this->assertTrue( $doc->loadHTML( $actual ) ); - $this->assertTrue( false === strpos( $actual, 'That embed can’t be found.' ) ); - $this->assertTrue( false !== strpos( $actual, 'Hello World' ) ); + $this->assertFalse( strpos( $actual, 'That embed can’t be found.' ) ); + $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); } function test_wp_embed_excerpt_more_no_embed() { diff --git a/tests/phpunit/tests/oembed/wpOembed.php b/tests/phpunit/tests/oembed/wpOembed.php index b7e6887214..ade91df95e 100644 --- a/tests/phpunit/tests/oembed/wpOembed.php +++ b/tests/phpunit/tests/oembed/wpOembed.php @@ -36,7 +36,7 @@ class Tests_WP_oEmbed extends WP_UnitTestCase { $actual = $this->oembed->get_html( $permalink ); remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) ); - $this->assertTrue( false !== $this->pre_oembed_result_filtered ); + $this->assertNotFalse( $this->pre_oembed_result_filtered ); $this->assertEquals( $this->pre_oembed_result_filtered, $actual ); } @@ -51,7 +51,7 @@ class Tests_WP_oEmbed extends WP_UnitTestCase { $actual = $this->oembed->get_html( $permalink ); remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) ); - $this->assertTrue( false !== $this->pre_oembed_result_filtered ); + $this->assertNotFalse( $this->pre_oembed_result_filtered ); $this->assertEquals( $this->pre_oembed_result_filtered, $actual ); } @@ -66,7 +66,7 @@ class Tests_WP_oEmbed extends WP_UnitTestCase { $actual = $this->oembed->get_html( 'https://example.com/' ); remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) ); - $this->assertTrue( false !== $this->pre_oembed_result_filtered ); + $this->assertNotFalse( $this->pre_oembed_result_filtered ); $this->assertFalse( $actual ); } } diff --git a/tests/phpunit/tests/post/thumbnails.php b/tests/phpunit/tests/post/thumbnails.php index a597ccd165..1346aebf20 100644 --- a/tests/phpunit/tests/post/thumbnails.php +++ b/tests/phpunit/tests/post/thumbnails.php @@ -194,7 +194,7 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { function test_get_the_post_thumbnail_url_with_invalid_post() { set_post_thumbnail( self::$post, self::$attachment_id ); - $this->assertTrue( false !== get_the_post_thumbnail_url( self::$post->ID ) ); + $this->assertNotFalse( get_the_post_thumbnail_url( self::$post->ID ) ); $deleted = wp_delete_post( self::$post->ID, true ); $this->assertNotEmpty( $deleted ); diff --git a/tests/phpunit/tests/post/wpPostType.php b/tests/phpunit/tests/post/wpPostType.php index e9d1d71d21..a9d046e551 100644 --- a/tests/phpunit/tests/post/wpPostType.php +++ b/tests/phpunit/tests/post/wpPostType.php @@ -101,7 +101,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { $post_type_object->remove_rewrite_rules(); $rewrite_tags_after = $wp_rewrite->rewritecode; - $this->assertTrue( false !== array_search( "%$post_type%", $rewrite_tags ) ); + $this->assertNotFalse( array_search( "%$post_type%", $rewrite_tags ) ); $this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after ) ); } diff --git a/tests/phpunit/tests/term/wpTaxonomy.php b/tests/phpunit/tests/term/wpTaxonomy.php index 377808cede..0c1c954dd6 100644 --- a/tests/phpunit/tests/term/wpTaxonomy.php +++ b/tests/phpunit/tests/term/wpTaxonomy.php @@ -66,7 +66,7 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase { $taxonomy_object->remove_rewrite_rules(); $rewrite_tags_after = $wp_rewrite->rewritecode; - $this->assertTrue( false !== array_search( "%$taxonomy%", $rewrite_tags ) ); + $this->assertNotFalse( array_search( "%$taxonomy%", $rewrite_tags ) ); $this->assertFalse( array_search( "%$taxonomy%", $rewrite_tags_after ) ); } diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index a9136d1dfd..2e76f7c80e 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -302,7 +302,7 @@ class Tests_Theme extends WP_UnitTestCase { $theme = wp_get_theme(); $this->assertEquals( $style, (string) $theme ); - $this->assertNotSame( false, $theme->errors() ); + $this->assertNotFalse( $theme->errors() ); $this->assertFalse( $theme->exists() ); // these return the bogus name - perhaps not ideal behaviour? diff --git a/tests/phpunit/tests/theme/support.php b/tests/phpunit/tests/theme/support.php index 648f031797..9b7eb24ea3 100644 --- a/tests/phpunit/tests/theme/support.php +++ b/tests/phpunit/tests/theme/support.php @@ -90,7 +90,7 @@ class Tests_Theme_Support extends WP_UnitTestCase { remove_theme_support( 'html5' ); $this->assertFalse( current_theme_supports( 'html5' ) ); $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) ); - $this->assertNotSame( false, add_theme_support( 'html5' ) ); + $this->assertNotFalse( add_theme_support( 'html5' ) ); $this->assertTrue( current_theme_supports( 'html5' ) ); $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) ); $this->assertTrue( current_theme_supports( 'html5', 'comment-list' ) ); @@ -108,7 +108,7 @@ class Tests_Theme_Support extends WP_UnitTestCase { $this->assertFalse( current_theme_supports( 'html5' ) ); $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) ); $this->assertFalse( add_theme_support( 'html5', 'comment-form' ) ); - $this->assertNotSame( false, add_theme_support( 'html5', array( 'comment-form' ) ) ); + $this->assertNotFalse( add_theme_support( 'html5', array( 'comment-form' ) ) ); $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) ); // This will return true, which might help a plugin author decide what markup to serve, @@ -117,7 +117,7 @@ class Tests_Theme_Support extends WP_UnitTestCase { // It appends, rather than replaces. $this->assertFalse( current_theme_supports( 'html5', 'comment-list' ) ); - $this->assertNotSame( false, add_theme_support( 'html5', array( 'comment-list' ) ) ); + $this->assertNotFalse( add_theme_support( 'html5', array( 'comment-list' ) ) ); $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) ); $this->assertTrue( current_theme_supports( 'html5', 'comment-list' ) ); $this->assertFalse( current_theme_supports( 'html5', 'search-form' ) );