diff --git a/tests/phpunit/data/themedir1/block-theme/theme.json b/tests/phpunit/data/themedir1/block-theme/theme.json index 2c29884bf4dcb..4dca1dfb0ac2d 100644 --- a/tests/phpunit/data/themedir1/block-theme/theme.json +++ b/tests/phpunit/data/themedir1/block-theme/theme.json @@ -96,6 +96,11 @@ } } } + }, + "my/unregistered-third-party-block": { + "color": { + "background": "hotpink" + } } }, "elements": { diff --git a/tests/phpunit/tests/template.php b/tests/phpunit/tests/template.php index a79702554dc64..00d64ae4d982e 100644 --- a/tests/phpunit/tests/template.php +++ b/tests/phpunit/tests/template.php @@ -151,6 +151,11 @@ public function tear_down() { $registry->unregister( 'third-party/test' ); } + if ( isset( $GLOBALS['_wp_tests_development_mode'] ) ) { + remove_all_filters( 'theme_file_path' ); + wp_theme_has_theme_json(); + } + unset( $GLOBALS['_wp_tests_development_mode'] ); parent::tear_down(); } diff --git a/tests/phpunit/tests/theme/support.php b/tests/phpunit/tests/theme/support.php index aed9d94d3c1fd..d7262273e8536 100644 --- a/tests/phpunit/tests/theme/support.php +++ b/tests/phpunit/tests/theme/support.php @@ -41,6 +41,7 @@ public function test_post_thumbnails() { $this->assertFalse( current_theme_supports( 'post-thumbnails' ) ); add_theme_support( 'post-thumbnails' ); $this->assertTrue( current_theme_supports( 'post-thumbnails' ) ); + remove_theme_support( 'post-thumbnails' ); } public function test_post_thumbnails_flat_array_of_post_types() { @@ -57,6 +58,8 @@ public function test_post_thumbnails_flat_array_of_post_types() { * @ticket 22080 */ public function test_post_thumbnails_mixed_args() { + remove_theme_support( 'post-thumbnails' ); + add_theme_support( 'post-thumbnails', array( 'post', 'page' ) ); add_theme_support( 'post-thumbnails', array( 'page' ) ); $this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) ); @@ -162,6 +165,8 @@ public function supports_foobar( $yesno, $args, $feature ) { * @ticket 11611 */ public function test_plugin_hook() { + remove_theme_support( 'foobar' ); + $this->assertFalse( current_theme_supports( 'foobar' ) ); add_theme_support( 'foobar' ); $this->assertTrue( current_theme_supports( 'foobar' ) ); @@ -185,6 +190,7 @@ public function test_plugin_hook_with_no_args() { add_filter( 'current_theme_supports-foobar', '__return_false' ); $this->assertFalse( current_theme_supports( 'foobar' ) ); + remove_theme_support( 'foobar' ); } /** diff --git a/tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php b/tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php index b3a836dee704f..a7f8301971dd4 100644 --- a/tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php +++ b/tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php @@ -18,6 +18,13 @@ class Tests_Theme_WpAddGlobalStylesForBlocks extends WP_Theme_UnitTestCase { */ private $test_blocks = array(); + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + /** * Administrator ID. * @@ -37,6 +44,7 @@ public static function set_up_before_class() { public function set_up() { parent::set_up(); + $this->original_stylesheet = get_stylesheet(); remove_action( 'wp_print_styles', 'print_emoji_styles' ); } @@ -49,6 +57,10 @@ public function tear_down() { $this->test_blocks = array(); } + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + parent::tear_down(); } @@ -63,7 +75,7 @@ public function test_third_party_blocks_inline_styles_not_register_to_global_sty wp_add_global_styles_for_blocks(); $this->assertNotContains( - ':root :where(.wp-block-my-third-party-block){background-color: hotpink;}', + ':root :where(.wp-block-my-unregistered-third-party-block){background-color: hotpink;}', $this->get_global_styles() ); }