Commit f15415cd97d for woocommerce

commit f15415cd97d38df21261ffcb5108a4ff8c8e8953
Author: Pavel Dohnal <pavel.dohnal@automattic.com>
Date:   Tue Nov 10 11:13:19 2026 +0100

    Make email editor integration tests pass in any order (#70810)

    * Restore core block types after the core renderer tests

    Renderer_Test replaced paragraph, button and other block types with
    stripped copies and never put the originals back, so tests that ran
    after it rendered those blocks differently.

    * Switch back the theme after the theme controller tests

    Two tests switched to Twenty Twenty-Four and left it, with its styles
    in WordPress's static theme cache, so later tests got its colours.

    * Drop the extra theme cache clear in the theme test teardowns

    switch_theme() already clears WordPress's theme style cache through
    the core switch_theme hook.

diff --git a/packages/php/email-editor/changelog/email-editor-test-order-isolation b/packages/php/email-editor/changelog/email-editor-test-order-isolation
new file mode 100644
index 00000000000..ea6001e3f95
--- /dev/null
+++ b/packages/php/email-editor/changelog/email-editor-test-order-isolation
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Make email editor integration tests pass in any order; no production change.
+
diff --git a/packages/php/email-editor/tests/integration/Engine/Site_Style_Sync_Controller_Test.php b/packages/php/email-editor/tests/integration/Engine/Site_Style_Sync_Controller_Test.php
index 1ee2c6fc1e3..fe7edc72bc5 100644
--- a/packages/php/email-editor/tests/integration/Engine/Site_Style_Sync_Controller_Test.php
+++ b/packages/php/email-editor/tests/integration/Engine/Site_Style_Sync_Controller_Test.php
@@ -17,6 +17,12 @@ use WP_Theme_JSON;
  * Class Site_Style_Sync_Controller_Test
  */
 class Site_Style_Sync_Controller_Test extends \Email_Editor_Integration_Test_Case {
+	/**
+	 * Theme that was active before the test.
+	 *
+	 * @var string
+	 */
+	private string $previous_theme = '';

 	/**
 	 * Site Style Sync Controller instance.
@@ -32,11 +38,21 @@ class Site_Style_Sync_Controller_Test extends \Email_Editor_Integration_Test_Cas
 		parent::setUp();

 		// Switch theme for easier testing theme colors.
+		$this->previous_theme = get_stylesheet();
 		switch_theme( 'twentytwentyfour' );

 		$this->controller = new Site_Style_Sync_Controller();
 	}

+	/**
+	 * Switch back to the theme from before the test. Switching also clears WordPress's
+	 * cached theme styles, which the database rollback does not reset.
+	 */
+	public function tearDown(): void {
+		switch_theme( $this->previous_theme );
+		parent::tearDown();
+	}
+
 	/**
 	 * Test controller initialization.
 	 */
diff --git a/packages/php/email-editor/tests/integration/Engine/Theme_Controller_Test.php b/packages/php/email-editor/tests/integration/Engine/Theme_Controller_Test.php
index cfeb5c7e01a..ede1cfe10ec 100644
--- a/packages/php/email-editor/tests/integration/Engine/Theme_Controller_Test.php
+++ b/packages/php/email-editor/tests/integration/Engine/Theme_Controller_Test.php
@@ -15,6 +15,13 @@ use Automattic\WooCommerce\EmailEditor\Engine\User_Theme;
  * Integration test for Theme_Controller class
  */
 class Theme_Controller_Test extends \Email_Editor_Integration_Test_Case {
+	/**
+	 * Theme that was active before the test.
+	 *
+	 * @var string
+	 */
+	private string $previous_theme = '';
+
 	/**
 	 * Theme controller instance
 	 *
@@ -29,6 +36,7 @@ class Theme_Controller_Test extends \Email_Editor_Integration_Test_Case {
 		parent::setUp();

 		// Switch theme for easier testing theme colors.
+		$this->previous_theme = get_stylesheet();
 		switch_theme( 'twentytwentyfour' );

 		// Crete a custom user theme post.
@@ -57,6 +65,15 @@ class Theme_Controller_Test extends \Email_Editor_Integration_Test_Case {
 		$this->theme_controller = $this->di_container->get( Theme_Controller::class );
 	}

+	/**
+	 * Switch back to the theme from before the test. Switching also clears WordPress's
+	 * cached theme styles, which the database rollback does not reset.
+	 */
+	public function tearDown(): void {
+		switch_theme( $this->previous_theme );
+		parent::tearDown();
+	}
+
 	/**
 	 * Test it get the theme json
 	 *
diff --git a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php
index 2b2e5870d90..03bd27ed664 100644
--- a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php
+++ b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php
@@ -35,6 +35,13 @@ class Renderer_Test extends \Email_Editor_Integration_Test_Case {
 	 */
 	private $renderer;

+	/**
+	 * Block types replaced in setUp.
+	 *
+	 * @var array<\WP_Block_Type|false>
+	 */
+	private array $original_block_types = array();
+
 	/**
 	 * Set up before each test
 	 */
@@ -50,18 +57,33 @@ class Renderer_Test extends \Email_Editor_Integration_Test_Case {
 		foreach ( self::USED_CORE_BLOCKS as $block ) {
 			$block_type = \WP_Block_Type_Registry::get_instance()->get_registered( $block );
 			$this->assertInstanceOf( \WP_Block_Type::class, $block_type );
-			$settings = array(
+			$settings                     = array(
 				'title'    => $block_type->title,
 				'name'     => $block_type->name,
 				'category' => $block_type->category,
 				'supports' => $block_type->supports ?? array(),
 			);
-			\WP_Block_Type_Registry::get_instance()->unregister( $block );
-			$settings = $initializer->update_block_settings( $settings );
+			$this->original_block_types[] = \WP_Block_Type_Registry::get_instance()->unregister( $block );
+			$settings                     = $initializer->update_block_settings( $settings );
 			register_block_type( $block, $settings );
 		}
 	}

+	/**
+	 * Put back the block types replaced in setUp, so later tests see the real ones.
+	 */
+	public function tearDown(): void {
+		$registry = \WP_Block_Type_Registry::get_instance();
+		foreach ( $this->original_block_types as $block_type ) {
+			if ( $block_type instanceof \WP_Block_Type ) {
+				$registry->unregister( $block_type->name );
+				$registry->register( $block_type );
+			}
+		}
+		$this->original_block_types = array();
+		parent::tearDown();
+	}
+
 	/**
 	 * Test it inlines button default styles
 	 */