From c00b6df5b27663817f5af39b5623547f72e8c721 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 20 Aug 2026 10:51:02 +0400 Subject: [PATCH 1/2] Tests: Restore theme after block template tests --- tests/phpunit/tests/blocks/getBlockTemplates.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/blocks/getBlockTemplates.php b/tests/phpunit/tests/blocks/getBlockTemplates.php index 791f449a163c5..783dfbabfd1eb 100644 --- a/tests/phpunit/tests/blocks/getBlockTemplates.php +++ b/tests/phpunit/tests/blocks/getBlockTemplates.php @@ -9,6 +9,13 @@ class Tests_Blocks_GetBlockTemplates extends WP_UnitTestCase { const TEST_THEME = 'block-theme'; + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + /** * @var WP_Post */ @@ -91,9 +98,18 @@ public static function wpTearDownAfterClass() { public function set_up() { parent::set_up(); + $this->original_stylesheet = get_stylesheet(); switch_theme( self::TEST_THEME ); } + public function tear_down() { + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + + parent::tear_down(); + } + /** * Gets the template IDs from the given array. * From e7c604e8d468e93aa0cb2b3cb2b1ad390254822d Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 20 Aug 2026 10:57:27 +0400 Subject: [PATCH 2/2] Tests: Restore themes after block tests --- tests/phpunit/tests/blocks/editor.php | 13 +++++++++++++ tests/phpunit/tests/blocks/getBlockAssetUrl.php | 12 ++++++++++++ tests/phpunit/tests/blocks/getHookedBlocks.php | 16 ++++++++++++++++ tests/phpunit/tests/blocks/register.php | 12 ++++++++++++ .../tests/blocks/wpBlockPatternsRegistry.php | 13 +++++++++++++ .../tests/theme/wpThemeGetBlockPatterns.php | 13 +++++++++++++ 6 files changed, 79 insertions(+) diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 1de4dbf1719a6..ed740a35bbcbc 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -16,6 +16,7 @@ public function set_up() { global $post; parent::set_up(); + $this->original_stylesheet = get_stylesheet(); remove_action( 'wp_print_styles', 'print_emoji_styles' ); @@ -51,6 +52,11 @@ public function tear_down() { $wp_rest_server = null; global $post_ID; $post_ID = null; + + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + parent::tear_down(); } @@ -64,6 +70,13 @@ public function tear_down() { */ protected $original_wp_styles; + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + public function filter_set_block_categories_post( $block_categories, $post ) { if ( empty( $post ) ) { return $block_categories; diff --git a/tests/phpunit/tests/blocks/getBlockAssetUrl.php b/tests/phpunit/tests/blocks/getBlockAssetUrl.php index ee1c541cf0c2c..fba6757369242 100644 --- a/tests/phpunit/tests/blocks/getBlockAssetUrl.php +++ b/tests/phpunit/tests/blocks/getBlockAssetUrl.php @@ -18,10 +18,18 @@ class Tests_Get_Block_Asset_Url extends WP_UnitTestCase { */ private $orig_theme_dir; + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + public function set_up() { global $wp_theme_directories; parent::set_up(); + $this->original_stylesheet = get_stylesheet(); // Sets up the `wp-content/themes/` directory to ensure consistency when running tests. $this->orig_theme_dir = $wp_theme_directories; @@ -34,6 +42,10 @@ public function set_up() { public function tear_down() { global $wp_theme_directories; + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + $wp_theme_directories = $this->orig_theme_dir; wp_clean_themes_cache(); diff --git a/tests/phpunit/tests/blocks/getHookedBlocks.php b/tests/phpunit/tests/blocks/getHookedBlocks.php index 83a741b4d0771..d0d17886bd4d8 100644 --- a/tests/phpunit/tests/blocks/getHookedBlocks.php +++ b/tests/phpunit/tests/blocks/getHookedBlocks.php @@ -16,6 +16,18 @@ class Tests_Blocks_GetHookedBlocks extends WP_UnitTestCase { const TEST_THEME_NAME = 'block-theme-with-hooked-blocks'; + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + + public function set_up() { + parent::set_up(); + $this->original_stylesheet = get_stylesheet(); + } + /** * Tear down after each test. * @@ -43,6 +55,10 @@ public function tear_down() { } } + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + parent::tear_down(); } diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index d2a836ba85e68..81cebf27c798c 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -20,6 +20,13 @@ class Tests_Blocks_Register extends WP_UnitTestCase { */ protected $original_wp_styles; + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + /** * ID for a test post. * @@ -61,6 +68,7 @@ public function render_stub() {} */ public function set_up() { parent::set_up(); + $this->original_stylesheet = get_stylesheet(); global $wp_scripts, $wp_styles; $this->original_wp_scripts = $wp_scripts; @@ -96,6 +104,10 @@ public function tear_down() { $wp_scripts = $this->original_wp_scripts; $wp_styles = $this->original_wp_styles; + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + parent::tear_down(); } diff --git a/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php b/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php index 738d086f4a30e..8749de5f3662b 100644 --- a/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php +++ b/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php @@ -27,6 +27,13 @@ class Tests_Blocks_wpBlockPatternsRegistry extends WP_UnitTestCase { */ private $original_registered_patterns = null; + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + /** * Set up each test method. * @@ -37,6 +44,7 @@ public function set_up() { $this->registry = new WP_Block_Patterns_Registry(); $this->original_registered_patterns = $this->get_registered_patterns_variable_value(); + $this->original_stylesheet = get_stylesheet(); } /** @@ -54,6 +62,11 @@ public function tear_down() { } $this->set_registered_patterns_variable_value( $this->original_registered_patterns ); + + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + parent::tear_down(); } diff --git a/tests/phpunit/tests/theme/wpThemeGetBlockPatterns.php b/tests/phpunit/tests/theme/wpThemeGetBlockPatterns.php index cd27aa00fd034..cc1827496a92f 100644 --- a/tests/phpunit/tests/theme/wpThemeGetBlockPatterns.php +++ b/tests/phpunit/tests/theme/wpThemeGetBlockPatterns.php @@ -19,14 +19,27 @@ class Tests_Theme_WPThemeGetBlockPatterns extends WP_UnitTestCase { */ private $initial_cache_object; + /** + * Original stylesheet. + * + * @var string + */ + private $original_stylesheet; + public function set_up() { parent::set_up(); $this->initial_cache_object = wp_using_ext_object_cache(); + $this->original_stylesheet = get_stylesheet(); } public function tear_down() { wp_using_ext_object_cache( $this->initial_cache_object ); + + if ( get_stylesheet() !== $this->original_stylesheet ) { + switch_theme( $this->original_stylesheet ); + } + parent::tear_down(); }