From 971e12a0c0ebf335b8b08f8f588916601ffee7a2 Mon Sep 17 00:00:00 2001 From: Michael D Adams Date: Sun, 16 Aug 2026 13:46:37 -0700 Subject: [PATCH 1/5] Tests: Fix test set up/tear down in `@group fontface` `self::$theme_root` should be reverted in `WP_Font_Face_UnitTestCase` `self::$requires_switch_theme_fixtures` needs to be set before calling `parent::set_up_before_class()`. --- tests/phpunit/tests/fonts/font-face/base.php | 1 + .../fonts/font-face/wpPrintFontFacesFromStyleVariations.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/fonts/font-face/base.php b/tests/phpunit/tests/fonts/font-face/base.php index 3b016557728a6..43c21ac3a89b3 100644 --- a/tests/phpunit/tests/fonts/font-face/base.php +++ b/tests/phpunit/tests/fonts/font-face/base.php @@ -69,6 +69,7 @@ public static function set_up_before_class() { public static function tear_down_after_class() { // Reset static flags. self::$requires_switch_theme_fixtures = false; + self::$theme_root = null; parent::tear_down_after_class(); } diff --git a/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php b/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php index 664404d552b45..2c35569b4d196 100644 --- a/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php +++ b/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php @@ -16,8 +16,9 @@ class Tests_Fonts_WpPrintFontFacesFromStyleVariations extends WP_Font_Face_UnitT const FONTS_THEME = 'fonts-block-theme'; public static function set_up_before_class() { - parent::set_up_before_class(); self::$requires_switch_theme_fixtures = true; + + parent::set_up_before_class(); } /** From bb3b81bf15ae32d2db2fce8c3e55373f3a12ff52 Mon Sep 17 00:00:00 2001 From: Michael D Adams Date: Sun, 16 Aug 2026 15:20:31 -0700 Subject: [PATCH 2/5] Tests: Remove `@runInSeparateProcess` from tests in `Tests_Sitemaps_Sitemaps` `@runInSeparateProcess` reruns `tests/phpunit/includes/bootstrap.php`, which deletes all posts, which changes the conditions of the test. In particular, `test_disable_sitemap_should_return_404()` is supposed to test what happens if sitemaps are disabled, not what happens when there are no posts in the sitemap. --- tests/phpunit/tests/sitemaps/sitemaps.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/sitemaps/sitemaps.php b/tests/phpunit/tests/sitemaps/sitemaps.php index 85f9965245842..24243787d5068 100644 --- a/tests/phpunit/tests/sitemaps/sitemaps.php +++ b/tests/phpunit/tests/sitemaps/sitemaps.php @@ -464,15 +464,17 @@ public function test_sitemaps_enabled() { /** * @ticket 50643 - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function test_disable_sitemap_should_return_404() { add_filter( 'wp_sitemaps_enabled', '__return_false' ); + // Instantiate the server before navigating: registering the sitemap + // rewrite tags is what adds `sitemap` to `$wp->public_query_vars`. + $sitemaps = wp_sitemaps_get_server(); + $this->go_to( home_url( '/?sitemap=index' ) ); - wp_sitemaps_get_server()->render_sitemaps(); + $sitemaps->render_sitemaps(); remove_filter( 'wp_sitemaps_enabled', '__return_false' ); @@ -481,8 +483,6 @@ public function test_disable_sitemap_should_return_404() { /** * @ticket 50643 - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function test_empty_url_list_should_return_404() { wp_register_sitemap_provider( 'foo', new WP_Sitemaps_Empty_Test_Provider( 'foo' ) ); From a336e41f5d9b7f22787e6e11c721bc71b02cb8f0 Mon Sep 17 00:00:00 2001 From: Michael D Adams Date: Sun, 16 Aug 2026 15:36:08 -0700 Subject: [PATCH 3/5] Tests: Allow `*::test_render_control_template_scripts()` to run by itself. These tests call `->render_control_template_scripts()`, which depends on a normally lazy-loaded file: `wp-includes/media-template.php`. Previous tests in these classes load that file as a side-effect of calling `$widget->enqueue_admin_scripts()`. When testing these tests individually, that file is never loaded. Load it explicitly. --- tests/phpunit/tests/widgets/wpWidgetMediaAudio.php | 3 +++ tests/phpunit/tests/widgets/wpWidgetMediaVideo.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/phpunit/tests/widgets/wpWidgetMediaAudio.php b/tests/phpunit/tests/widgets/wpWidgetMediaAudio.php index 20aee5f30baf4..cb555fb5285a5 100644 --- a/tests/phpunit/tests/widgets/wpWidgetMediaAudio.php +++ b/tests/phpunit/tests/widgets/wpWidgetMediaAudio.php @@ -316,6 +316,9 @@ public function test_enqueue_admin_scripts() { * @covers WP_Widget_Media_Audio::render_control_template_scripts */ public function test_render_control_template_scripts() { + // Provides wp_underscore_audio_template(), normally loaded by wp_enqueue_media(). + require_once ABSPATH . WPINC . '/media-template.php'; + $widget = new WP_Widget_Media_Audio(); ob_start(); diff --git a/tests/phpunit/tests/widgets/wpWidgetMediaVideo.php b/tests/phpunit/tests/widgets/wpWidgetMediaVideo.php index aeedae2a3174f..98c86ec4865fd 100644 --- a/tests/phpunit/tests/widgets/wpWidgetMediaVideo.php +++ b/tests/phpunit/tests/widgets/wpWidgetMediaVideo.php @@ -344,6 +344,9 @@ public function test_enqueue_admin_scripts() { * @covers WP_Widget_Media_Video::render_control_template_scripts */ public function test_render_control_template_scripts() { + // Provides wp_underscore_video_template(), normally loaded by wp_enqueue_media(). + require_once ABSPATH . WPINC . '/media-template.php'; + $widget = new WP_Widget_Media_Video(); ob_start(); From c09bdc5faf6c34b4e615f455bd4cdb2e4590c649 Mon Sep 17 00:00:00 2001 From: Michael D Adams Date: Sun, 16 Aug 2026 15:50:26 -0700 Subject: [PATCH 4/5] Tests: Unregister block types in REST_Block_Type_Controller_Test Test methods that register new block types should unregister them as well. Otherwise, the state leaks into later tests. --- .../tests/rest-api/rest-block-type-controller.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-block-type-controller.php b/tests/phpunit/tests/rest-api/rest-block-type-controller.php index 3cf8c5244d77c..c75e164f11cce 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -62,8 +62,6 @@ public static function wpTearDownAfterClass() { self::delete_user( self::$admin_id ); self::delete_user( self::$subscriber_id ); unregister_block_type( 'fake/test' ); - unregister_block_type( 'fake/invalid' ); - unregister_block_type( 'fake/false' ); } /** @@ -138,6 +136,7 @@ public function test_get_item_with_styles() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_name ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_name ); $data = $response->get_data(); $this->assertSameSets( array( $block_styles ), $data['styles'] ); } @@ -166,6 +165,7 @@ public function test_get_item_with_styles_merge() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_name ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_name ); $data = $response->get_data(); $expected = array( array( @@ -232,6 +232,7 @@ public function test_get_item_invalid() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_type ); $data = $response->get_data(); $this->assertSame( $block_type, $data['name'] ); $this->assertSame( '1', $data['title'] ); @@ -311,6 +312,7 @@ public function test_get_item_defaults() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_type ); $data = $response->get_data(); $this->assertSame( $block_type, $data['name'] ); $this->assertSame( '', $data['title'] ); @@ -368,6 +370,7 @@ public function test_get_item_deprecated() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_type ); $data = $response->get_data(); $this->assertSameSets( array( 'hello_world' ), @@ -438,6 +441,7 @@ public function test_get_item_deprecated_with_arrays() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_type ); $data = $response->get_data(); $this->assertSameSets( $settings['editor_script'], @@ -525,6 +529,7 @@ public function test_get_variation() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_type ); $data = $response->get_data(); $this->assertSame( $block_type, $data['name'] ); $this->assertArrayHasKey( 'variations', $data ); @@ -868,6 +873,7 @@ public function test_variation_callback() { wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); + unregister_block_type( $block_type ); $data = $response->get_data(); $this->assertSameSets( $this->mock_variation_callback(), $data['variations'] ); } From c41f6d654ac9c9ccd3769d758f277a443d709ecc Mon Sep 17 00:00:00 2001 From: Michael D Adams Date: Sun, 16 Aug 2026 16:30:18 -0700 Subject: [PATCH 5/5] phpcbf --- .../tests/rest-api/rest-block-type-controller.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-block-type-controller.php b/tests/phpunit/tests/rest-api/rest-block-type-controller.php index c75e164f11cce..21eb081bcf11e 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -137,7 +137,7 @@ public function test_get_item_with_styles() { $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_name ); $response = rest_get_server()->dispatch( $request ); unregister_block_type( $block_name ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSameSets( array( $block_styles ), $data['styles'] ); } @@ -233,7 +233,7 @@ public function test_get_item_invalid() { $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); unregister_block_type( $block_type ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSame( $block_type, $data['name'] ); $this->assertSame( '1', $data['title'] ); $this->assertNull( $data['category'] ); @@ -313,7 +313,7 @@ public function test_get_item_defaults() { $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); unregister_block_type( $block_type ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSame( $block_type, $data['name'] ); $this->assertSame( '', $data['title'] ); $this->assertNull( $data['category'] ); @@ -371,7 +371,7 @@ public function test_get_item_deprecated() { $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); unregister_block_type( $block_type ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSameSets( array( 'hello_world' ), $data['editor_script_handles'], @@ -442,7 +442,7 @@ public function test_get_item_deprecated_with_arrays() { $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); unregister_block_type( $block_type ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSameSets( $settings['editor_script'], $data['editor_script_handles'], @@ -530,7 +530,7 @@ public function test_get_variation() { $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); unregister_block_type( $block_type ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSame( $block_type, $data['name'] ); $this->assertArrayHasKey( 'variations', $data ); $this->assertCount( 1, $data['variations'] ); @@ -874,7 +874,7 @@ public function test_variation_callback() { $request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type ); $response = rest_get_server()->dispatch( $request ); unregister_block_type( $block_type ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSameSets( $this->mock_variation_callback(), $data['variations'] ); }