Commit 54bb71c4ab8 for woocommerce

commit 54bb71c4ab8649e15380b2e58c1c868a3a94e906
Author: Ján Mikláš <neosinner@gmail.com>
Date:   Thu Nov 19 12:19:25 2026 +0100

    Share checkout switching for extension browser tests (#71126)

    * Add shared checkout switching for extension tests

    * Add checkout helper changelog entry

    * Keep checkout page IDs before fixtures are seeded

diff --git a/packages/js/extension-tooling/README.md b/packages/js/extension-tooling/README.md
index f359d7909f3..25048ff48ee 100644
--- a/packages/js/extension-tooling/README.md
+++ b/packages/js/extension-tooling/README.md
@@ -138,6 +138,12 @@ pnpm run wp-env:e2e run cli bash wp-content/woo-extension-tooling/provision-e2e-

 The site needs Storefront, WooCommerce, and the extension's `WC_Docker_Provision_Manager` test mu-plugin. The script configures the block pages, creates the shortcode pages, and calls the mu-plugin's `wp wc docker-e2e provision` importer once. A failed WP-CLI step stops provisioning. Pass `--metric-units` if the suite expects kilograms and centimeters, as Product Bundles does.

+### Switch checkout modes in test fixtures
+
+In a test mu-plugin, load `checkout-mode.php` from the tooling bin mount and use the `Automattic\WooCommerce\ExtensionTooling\Checkout_Mode` trait. The fixture defines `THEME_LEGACY` and `THEME_BLOCKS`, registers its filters and decides when a request may switch modes. Add the tooling bin mapping to every test site that loads the fixture.
+
+The package test suite requires a PHP CLI on `PATH` to exercise the checkout fixture.
+
 ## Lint and analysis presets

 If your Stylelint config already disables `selector-class-pattern` for legacy SCSS, extend the shared overlay after the WordPress preset. Keep any file-specific rules in your own config.
diff --git a/packages/js/extension-tooling/bin/checkout-mode.php b/packages/js/extension-tooling/bin/checkout-mode.php
new file mode 100644
index 00000000000..989e708b365
--- /dev/null
+++ b/packages/js/extension-tooling/bin/checkout-mode.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Checkout mode and page selection for extension browser tests.
+ *
+ * @package WooCommerce\ExtensionTooling
+ */
+
+namespace Automattic\WooCommerce\ExtensionTooling;
+
+/**
+ * Shared methods for test fixtures that define THEME_LEGACY and THEME_BLOCKS.
+ */
+trait Checkout_Mode {
+
+	/**
+	 * Select the checkout mode and activate its theme when needed.
+	 *
+	 * @param string $mode Checkout mode.
+	 */
+	public static function switch_test_mode( $mode ) {
+		$mode  = ( 'blocks' === $mode ) ? 'blocks' : 'legacy';
+		$theme = ( 'blocks' === $mode ) ? self::THEME_BLOCKS : self::THEME_LEGACY;
+
+		update_option( 'e2e_tests_mode', $mode );
+
+		if ( get_stylesheet() !== $theme ) {
+			switch_theme( $theme );
+		}
+	}
+
+	/**
+	 * Select the cart page for the active checkout mode.
+	 *
+	 * @param int|string $cart_page_id Current cart page ID.
+	 * @return int|string Cart page ID.
+	 */
+	public static function filter_cart_page_id( $cart_page_id ) {
+		if ( 'legacy' === get_option( 'e2e_tests_mode', 'legacy' ) ) {
+			$legacy_page_id = (int) get_option( 'tests_legacy_woocommerce_cart_page_id', 0 );
+			if ( $legacy_page_id > 0 ) {
+				return $legacy_page_id;
+			}
+		}
+
+		return $cart_page_id;
+	}
+
+	/**
+	 * Select the checkout page for the active checkout mode.
+	 *
+	 * @param int|string $checkout_page_id Current checkout page ID.
+	 * @return int|string Checkout page ID.
+	 */
+	public static function filter_checkout_page_id( $checkout_page_id ) {
+		if ( 'legacy' === get_option( 'e2e_tests_mode', 'legacy' ) ) {
+			$legacy_page_id = (int) get_option( 'tests_legacy_woocommerce_checkout_page_id', 0 );
+			if ( $legacy_page_id > 0 ) {
+				return $legacy_page_id;
+			}
+		}
+
+		return $checkout_page_id;
+	}
+}
diff --git a/packages/js/extension-tooling/changelog/shared-extension-checkout-mode b/packages/js/extension-tooling/changelog/shared-extension-checkout-mode
new file mode 100644
index 00000000000..62bf8e6f65e
--- /dev/null
+++ b/packages/js/extension-tooling/changelog/shared-extension-checkout-mode
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Share checkout mode, theme, and page selection in extension browser tests.
diff --git a/packages/js/extension-tooling/package.json b/packages/js/extension-tooling/package.json
index 37a16e99ccb..a600ba19791 100644
--- a/packages/js/extension-tooling/package.json
+++ b/packages/js/extension-tooling/package.json
@@ -62,7 +62,8 @@
 					"changes": [
 						"package.json",
 						"bin/*",
-						"{src,test}/**/*.js"
+						"{src,test}/**/*.js",
+						"test/fixtures/**/*.php"
 					],
 					"events": [
 						"pull_request",
diff --git a/packages/js/extension-tooling/test/checkout-mode.test.js b/packages/js/extension-tooling/test/checkout-mode.test.js
new file mode 100644
index 00000000000..5032da67a21
--- /dev/null
+++ b/packages/js/extension-tooling/test/checkout-mode.test.js
@@ -0,0 +1,24 @@
+/**
+ * External dependencies
+ */
+const assert = require( 'node:assert/strict' );
+const { execFileSync } = require( 'node:child_process' );
+const path = require( 'node:path' );
+const test = require( 'node:test' );
+
+test( 'switches checkout pages and themes in either order without reactivating the active theme', () => {
+	const result = execFileSync(
+		'php',
+		[ path.join( __dirname, 'fixtures/class-checkout-mode-fixture.php' ) ],
+		{ encoding: 'utf8' }
+	);
+
+	assert.deepEqual( JSON.parse( result ), [
+		[ '32', '33' ],
+		[ 12, 13 ],
+		[ 'blocks', 'twentytwentyfive', [ '32', '33' ] ],
+		[ 'legacy', 'storefront', [ 12, 13 ] ],
+		[ 'legacy', 'storefront' ],
+		[ 'twentytwentyfive', 'storefront' ],
+	] );
+} );
diff --git a/packages/js/extension-tooling/test/fixtures/class-checkout-mode-fixture.php b/packages/js/extension-tooling/test/fixtures/class-checkout-mode-fixture.php
new file mode 100644
index 00000000000..74a7048b72a
--- /dev/null
+++ b/packages/js/extension-tooling/test/fixtures/class-checkout-mode-fixture.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Exercise checkout switching with the options and theme APIs stubbed.
+ *
+ * @package WooCommerce\ExtensionTooling
+ */
+
+use Automattic\WooCommerce\ExtensionTooling\Checkout_Mode;
+
+require dirname( __DIR__, 2 ) . '/bin/checkout-mode.php';
+
+/** Test-only checkout fixture. */
+class Checkout_Mode_Fixture {
+	use Checkout_Mode;
+
+	const THEME_LEGACY = 'storefront';
+	const THEME_BLOCKS = 'twentytwentyfive';
+}
+
+$options = array();
+$theme   = 'storefront';
+$changes = array();
+
+/** Stub get_option. */
+function get_option( $name, $default_value = false ) {
+	global $options;
+	return $options[ $name ] ?? $default_value;
+}
+
+/** Stub update_option. */
+function update_option( $name, $value ) {
+	global $options;
+	$options[ $name ] = $value;
+}
+
+/** Stub get_stylesheet. */
+function get_stylesheet() {
+	global $theme;
+	return $theme;
+}
+
+/** Stub switch_theme. */
+function switch_theme( $stylesheet ) {
+	global $theme, $changes;
+	$theme     = $stylesheet;
+	$changes[] = $stylesheet;
+}
+
+$pages = static function () {
+	return array(
+		Checkout_Mode_Fixture::filter_cart_page_id( '32' ),
+		Checkout_Mode_Fixture::filter_checkout_page_id( '33' ),
+	);
+};
+
+$unseeded = $pages();
+$options  = array(
+	'tests_legacy_woocommerce_cart_page_id'     => '12',
+	'tests_legacy_woocommerce_checkout_page_id' => '13',
+);
+$initial  = $pages();
+Checkout_Mode_Fixture::switch_test_mode( 'blocks' );
+$blocks = array( get_option( 'e2e_tests_mode' ), $theme, $pages() );
+Checkout_Mode_Fixture::switch_test_mode( 'blocks' );
+Checkout_Mode_Fixture::switch_test_mode( 'legacy' );
+$legacy = array( get_option( 'e2e_tests_mode' ), $theme, $pages() );
+Checkout_Mode_Fixture::switch_test_mode( 'unknown' );
+$fallback = array( get_option( 'e2e_tests_mode' ), $theme );
+
+echo json_encode( array( $unseeded, $initial, $blocks, $legacy, $fallback, $changes ) );