Commit 79c514309a5 for woocommerce
commit 79c514309a5d95d0c6681785cc0540777ce527e3
Author: Ján Mikláš <neosinner@gmail.com>
Date: Thu Nov 19 15:32:29 2026 +0100
Share the PHP debug log marker for browser tests (#71141)
* feat: share the PHP log marker
* docs: record the package change
diff --git a/packages/js/extension-tooling/README.md b/packages/js/extension-tooling/README.md
index 25048ff48ee..c505754d3e3 100644
--- a/packages/js/extension-tooling/README.md
+++ b/packages/js/extension-tooling/README.md
@@ -84,6 +84,8 @@ Use the second config to set suite-specific projects, worker limits, storage sta
Use `@woocommerce/extension-tooling/php-warning-filter` with the log text and the path fragments for the tested plugins. The filter returns matching PHP errors, warnings, notices and deprecations. The extension reads the log and checks the result in its warnings project.
+For suites that verify the debug log is connected to WordPress, map `./node_modules/@woocommerce/extension-tooling/bin/e2e-log-marker.php` to `wp-content/mu-plugins/e2e-log-marker.php` in the browser test environment. A request with `?e2e_log_marker=test-id` writes `e2e-log-marker-test-id` to the PHP log. Install the marker only on test sites.
+
## Webpack
Import the helpers from the extension's webpack configuration. Keep the entry paths, output paths and match patterns in that configuration.
diff --git a/packages/js/extension-tooling/bin/e2e-log-marker.php b/packages/js/extension-tooling/bin/e2e-log-marker.php
new file mode 100644
index 00000000000..2423ae3a410
--- /dev/null
+++ b/packages/js/extension-tooling/bin/e2e-log-marker.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Plugin Name: E2E Log Marker
+ * Description: Writes a marker to verify the browser test site's PHP debug log.
+ *
+ * @package WooCommerce\ExtensionTooling
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+add_action(
+ 'init',
+ static function () {
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Test site log probe.
+ if ( ! isset( $_GET['e2e_log_marker'] ) || ! is_string( $_GET['e2e_log_marker'] ) ) {
+ return;
+ }
+
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Test site log probe.
+ $marker = sanitize_key( wp_unslash( $_GET['e2e_log_marker'] ) );
+ // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Test site log probe.
+ error_log( 'e2e-log-marker-' . $marker );
+ }
+);
diff --git a/packages/js/extension-tooling/changelog/add-e2e-log-marker b/packages/js/extension-tooling/changelog/add-e2e-log-marker
new file mode 100644
index 00000000000..a6eeefb74d2
--- /dev/null
+++ b/packages/js/extension-tooling/changelog/add-e2e-log-marker
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Share the PHP debug log marker for browser test sites.
diff --git a/packages/js/extension-tooling/test/e2e-log-marker.test.js b/packages/js/extension-tooling/test/e2e-log-marker.test.js
new file mode 100644
index 00000000000..f0d689530ac
--- /dev/null
+++ b/packages/js/extension-tooling/test/e2e-log-marker.test.js
@@ -0,0 +1,22 @@
+/**
+ * External dependencies
+ */
+const assert = require( 'node:assert/strict' );
+const { spawnSync } = require( 'node:child_process' );
+const path = require( 'node:path' );
+const test = require( 'node:test' );
+
+test( 'writes the sanitized marker only for the test query parameter', () => {
+ const result = spawnSync(
+ 'php',
+ [
+ '-d',
+ 'error_log=',
+ path.join( __dirname, 'fixtures/e2e-log-marker-fixture.php' ),
+ ],
+ { encoding: 'utf8' }
+ );
+
+ assert.equal( result.status, 0, result.error?.message ?? result.stderr );
+ assert.equal( result.stderr.trim(), 'e2e-log-marker-request-42' );
+} );
diff --git a/packages/js/extension-tooling/test/fixtures/e2e-log-marker-fixture.php b/packages/js/extension-tooling/test/fixtures/e2e-log-marker-fixture.php
new file mode 100644
index 00000000000..5da37f19e5d
--- /dev/null
+++ b/packages/js/extension-tooling/test/fixtures/e2e-log-marker-fixture.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Exercise the WordPress log marker without starting a test site.
+ *
+ * @package WooCommerce\ExtensionTooling
+ */
+
+function add_action( $hook, $callback ) {
+ if ( 'init' !== $hook ) {
+ throw new RuntimeException( 'The marker must run on init.' );
+ }
+ $GLOBALS['marker_callback'] = $callback;
+}
+
+function wp_unslash( $value ) {
+ return stripslashes( $value );
+}
+
+function sanitize_key( $value ) {
+ return preg_replace( '/[^a-z0-9_-]/', '', strtolower( $value ) );
+}
+
+define( 'ABSPATH', __DIR__ . '/' );
+require __DIR__ . '/../../bin/e2e-log-marker.php';
+
+foreach ( array(
+ array(),
+ array( 'unrelated' => 'ignore' ),
+ array( 'e2e_log_marker' => array( 'ignore' ) ),
+ array( 'e2e_log_marker' => 'REQUEST-42!' ),
+) as $query ) {
+ $_GET = $query;
+ $GLOBALS['marker_callback']();
+}