From b22fb796a516f219e48816f24bad22bce39664f4 Mon Sep 17 00:00:00 2001 From: noruzzamans Date: Thu, 26 Nov 2026 11:52:36 +0600 Subject: [PATCH 1/2] Isolate multisite global styles revisions block variation tests --- ...est-global-styles-revisions-controller.php | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php index 469a5203f9a7e..bd0688943116d 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php @@ -66,6 +66,13 @@ class WP_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_REST_Contr */ private $revision_3_id; + /** + * Whether the current test granted super admin to the administrator. + * + * @var bool + */ + private $granted_super_admin = false; + /** * Create fake data before our tests run. * @@ -224,6 +231,31 @@ public function set_up() { $this->revision_3_id = $this->revision_3->ID; } + /** + * Cleans up after tests. + */ + public function tear_down() { + if ( $this->granted_super_admin ) { + revoke_super_admin( self::$admin_id ); + kses_init(); + $this->granted_super_admin = false; + } + + parent::tear_down(); + } + + /** + * Sets the current user to the admin, granting super admin on multisite + * so global styles JSON is not stripped by KSES on save. + */ + private function set_admin_user_with_unfiltered_html() { + if ( is_multisite() ) { + grant_super_admin( self::$admin_id ); + $this->granted_super_admin = true; + } + wp_set_current_user( self::$admin_id ); + } + /** * @ticket 58524 * @ticket 59810 @@ -991,7 +1023,7 @@ public function test_get_global_styles_revisions_pagination() { * @covers WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response */ public function test_get_item_preserves_block_style_variations() { - wp_set_current_user( self::$admin_id ); + $this->set_admin_user_with_unfiltered_html(); switch_theme( 'block-theme-child-with-block-style-variations' ); // Create a global styles post for the theme. @@ -1077,7 +1109,7 @@ public function test_get_item_preserves_block_style_variations() { * @covers WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response */ public function test_multiple_block_variations_are_preserved() { - wp_set_current_user( self::$admin_id ); + $this->set_admin_user_with_unfiltered_html(); switch_theme( 'block-theme-child-with-block-style-variations' ); // Create a global styles post for the theme. @@ -1181,7 +1213,7 @@ public function test_multiple_block_variations_are_preserved() { * @covers WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response */ public function test_theme_variations_are_registered_for_revisions() { - wp_set_current_user( self::$admin_id ); + $this->set_admin_user_with_unfiltered_html(); switch_theme( 'block-theme-child-with-block-style-variations' ); // Verify the theme has a block style variation defined. @@ -1264,7 +1296,7 @@ public function test_theme_variations_are_registered_for_revisions() { * @covers WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response */ public function test_get_items_preserves_block_style_variations() { - wp_set_current_user( self::$admin_id ); + $this->set_admin_user_with_unfiltered_html(); switch_theme( 'block-theme-child-with-block-style-variations' ); // Create a global styles post for the theme. From 6e314dc486d99e51bd02278b9e99f74be022eb6e Mon Sep 17 00:00:00 2001 From: noruzzamans Date: Thu, 26 Nov 2026 18:59:38 +0600 Subject: [PATCH 2/2] Remove redundant super admin teardown per review feedback --- ...est-global-styles-revisions-controller.php | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php index bd0688943116d..ca981f1c77d07 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php @@ -66,13 +66,6 @@ class WP_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_REST_Contr */ private $revision_3_id; - /** - * Whether the current test granted super admin to the administrator. - * - * @var bool - */ - private $granted_super_admin = false; - /** * Create fake data before our tests run. * @@ -231,19 +224,6 @@ public function set_up() { $this->revision_3_id = $this->revision_3->ID; } - /** - * Cleans up after tests. - */ - public function tear_down() { - if ( $this->granted_super_admin ) { - revoke_super_admin( self::$admin_id ); - kses_init(); - $this->granted_super_admin = false; - } - - parent::tear_down(); - } - /** * Sets the current user to the admin, granting super admin on multisite * so global styles JSON is not stripped by KSES on save. @@ -251,7 +231,6 @@ public function tear_down() { private function set_admin_user_with_unfiltered_html() { if ( is_multisite() ) { grant_super_admin( self::$admin_id ); - $this->granted_super_admin = true; } wp_set_current_user( self::$admin_id ); }