From 51d9149aab29083844a86d21691e52a39a61b101 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:19:47 +0000 Subject: [PATCH 01/14] Initial plan From a6902f06db04359c25c4b584fc37e2150d5895ee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:26:10 +0000 Subject: [PATCH 02/14] Connection: Fix date format compatibility for WordPress trunk/PHP 8.4+ Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../packages/connection/src/class-tokens.php | 7 ++- .../connection/tests/php/TokensTest.php | 51 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/projects/packages/connection/src/class-tokens.php b/projects/packages/connection/src/class-tokens.php index 73efd519f858..65f84fc690f3 100644 --- a/projects/packages/connection/src/class-tokens.php +++ b/projects/packages/connection/src/class-tokens.php @@ -660,7 +660,12 @@ public function is_locked() { $locked_site_url = base64_decode( $the_lock[1] ); $expires = $the_lock[0]; - $expiration_date = DateTime::createFromFormat( static::DATE_FORMAT_ATOM, $expires ); + // Try parsing with microseconds first (WordPress trunk/PHP 8.4+), then without (stable versions). + $expiration_date = DateTime::createFromFormat( 'Y-m-d\TH:i:s.uP', $expires ); + if ( false === $expiration_date ) { + $expiration_date = DateTime::createFromFormat( static::DATE_FORMAT_ATOM, $expires ); + } + if ( false === $expiration_date || ! $locked_site_url ) { // Something's wrong with the lock. $this->remove_lock(); diff --git a/projects/packages/connection/tests/php/TokensTest.php b/projects/packages/connection/tests/php/TokensTest.php index 918a75c5d156..2a7d5ef90243 100644 --- a/projects/packages/connection/tests/php/TokensTest.php +++ b/projects/packages/connection/tests/php/TokensTest.php @@ -268,7 +268,15 @@ public function test_set_lock() { static::assertSame( 'https://test1.example.org', base64_decode( $lock_site_url ) ); - $date = $lock_expiration ? DateTime::createFromFormat( Tokens::DATE_FORMAT_ATOM, $lock_expiration )->format( 'Y-m-d' ) : false; + // Parse the expiration date, handling both formats (with and without microseconds). + $date = false; + if ( $lock_expiration ) { + $parsed_date = DateTime::createFromFormat( 'Y-m-d\TH:i:s.uP', $lock_expiration ); + if ( false === $parsed_date ) { + $parsed_date = DateTime::createFromFormat( Tokens::DATE_FORMAT_ATOM, $lock_expiration ); + } + $date = $parsed_date ? $parsed_date->format( 'Y-m-d' ) : false; + } static::assertSame( gmdate( 'Y-m-d', strtotime( 'tomorrow' ) ), $date ); remove_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); @@ -307,6 +315,47 @@ public function test_unlock() { remove_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); } + /** + * Test that is_locked() handles both date formats (with and without microseconds). + * This ensures compatibility with both WordPress trunk/PHP 8.4+ and stable versions. + */ + public function test_is_locked_handles_both_date_formats() { + $tokens = new Tokens(); + + $this->site_url = 'https://test.example.org'; + add_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); + + // Test with date format without microseconds (old format). + $future_date = ( new DateTime() )->add( new DateInterval( 'PT1H' ) ); + $lock_value = $future_date->format( 'Y-m-d\TH:i:sP' ) . '|||' . base64_encode( 'https://test.example.org' ); + Jetpack_Options::update_option( 'token_lock', $lock_value ); + + // Should not be locked (same site URL). + static::assertFalse( $tokens->is_locked() ); + + // Change site URL, should now be locked. + $this->site_url = 'https://other.example.org'; + static::assertTrue( $tokens->is_locked() ); + + $tokens->remove_lock(); + + // Test with date format with microseconds (new format in WordPress trunk/PHP 8.4+). + $future_date_with_microseconds = ( new DateTime() )->add( new DateInterval( 'PT1H' ) ); + $lock_value_with_microseconds = $future_date_with_microseconds->format( 'Y-m-d\TH:i:s.uP' ) . '|||' . base64_encode( 'https://test.example.org' ); + Jetpack_Options::update_option( 'token_lock', $lock_value_with_microseconds ); + + // Should not be locked (same site URL). + $this->site_url = 'https://test.example.org'; + static::assertFalse( $tokens->is_locked() ); + + // Change site URL, should now be locked. + $this->site_url = 'https://other.example.org'; + static::assertTrue( $tokens->is_locked() ); + + $tokens->remove_lock(); + remove_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); + } + /** * Filter to get the current site URL. * From 72971b6ec3301a9c3e0b028d2a3057e4d77bb1c3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:27:41 +0000 Subject: [PATCH 03/14] Connection: Add changelog for date format compatibility fix Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../connection/changelog/fix-date-format-compatibility | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/packages/connection/changelog/fix-date-format-compatibility diff --git a/projects/packages/connection/changelog/fix-date-format-compatibility b/projects/packages/connection/changelog/fix-date-format-compatibility new file mode 100644 index 000000000000..398267515ab6 --- /dev/null +++ b/projects/packages/connection/changelog/fix-date-format-compatibility @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix date format parsing to handle both formats with and without microseconds for WordPress trunk/PHP 8.4+ compatibility. From 3d9cbaa3deb425efd0cd2a8812f929d5bd7f47fd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:28:10 +0000 Subject: [PATCH 04/14] Connection: Remove trailing whitespace Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- projects/packages/connection/src/class-tokens.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/packages/connection/src/class-tokens.php b/projects/packages/connection/src/class-tokens.php index 65f84fc690f3..5850761d7396 100644 --- a/projects/packages/connection/src/class-tokens.php +++ b/projects/packages/connection/src/class-tokens.php @@ -665,7 +665,7 @@ public function is_locked() { if ( false === $expiration_date ) { $expiration_date = DateTime::createFromFormat( static::DATE_FORMAT_ATOM, $expires ); } - + if ( false === $expiration_date || ! $locked_site_url ) { // Something's wrong with the lock. $this->remove_lock(); From a202d3a622ef538635563e6d050e5a0187334d23 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:34:03 +0000 Subject: [PATCH 05/14] Jetpack MU WPCOM: Fix verbum comments test for WP trunk block output WordPress trunk removed layout classes from block output (Gutenberg PR #71207). Updated test expectations to match the new output format that no longer includes "is-layout-flow" classes on quote blocks. Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../changelog/fix-date-format-compatibility | 4 -- .../packages/connection/src/class-tokens.php | 7 +-- .../connection/tests/php/TokensTest.php | 51 +------------------ .../changelog/fix-verbum-block-test-wp-trunk | 4 ++ .../Verbum_Block_Utils_Test.php | 4 +- 5 files changed, 9 insertions(+), 61 deletions(-) delete mode 100644 projects/packages/connection/changelog/fix-date-format-compatibility create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk diff --git a/projects/packages/connection/changelog/fix-date-format-compatibility b/projects/packages/connection/changelog/fix-date-format-compatibility deleted file mode 100644 index 398267515ab6..000000000000 --- a/projects/packages/connection/changelog/fix-date-format-compatibility +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: fixed - -Fix date format parsing to handle both formats with and without microseconds for WordPress trunk/PHP 8.4+ compatibility. diff --git a/projects/packages/connection/src/class-tokens.php b/projects/packages/connection/src/class-tokens.php index 5850761d7396..73efd519f858 100644 --- a/projects/packages/connection/src/class-tokens.php +++ b/projects/packages/connection/src/class-tokens.php @@ -660,12 +660,7 @@ public function is_locked() { $locked_site_url = base64_decode( $the_lock[1] ); $expires = $the_lock[0]; - // Try parsing with microseconds first (WordPress trunk/PHP 8.4+), then without (stable versions). - $expiration_date = DateTime::createFromFormat( 'Y-m-d\TH:i:s.uP', $expires ); - if ( false === $expiration_date ) { - $expiration_date = DateTime::createFromFormat( static::DATE_FORMAT_ATOM, $expires ); - } - + $expiration_date = DateTime::createFromFormat( static::DATE_FORMAT_ATOM, $expires ); if ( false === $expiration_date || ! $locked_site_url ) { // Something's wrong with the lock. $this->remove_lock(); diff --git a/projects/packages/connection/tests/php/TokensTest.php b/projects/packages/connection/tests/php/TokensTest.php index 2a7d5ef90243..918a75c5d156 100644 --- a/projects/packages/connection/tests/php/TokensTest.php +++ b/projects/packages/connection/tests/php/TokensTest.php @@ -268,15 +268,7 @@ public function test_set_lock() { static::assertSame( 'https://test1.example.org', base64_decode( $lock_site_url ) ); - // Parse the expiration date, handling both formats (with and without microseconds). - $date = false; - if ( $lock_expiration ) { - $parsed_date = DateTime::createFromFormat( 'Y-m-d\TH:i:s.uP', $lock_expiration ); - if ( false === $parsed_date ) { - $parsed_date = DateTime::createFromFormat( Tokens::DATE_FORMAT_ATOM, $lock_expiration ); - } - $date = $parsed_date ? $parsed_date->format( 'Y-m-d' ) : false; - } + $date = $lock_expiration ? DateTime::createFromFormat( Tokens::DATE_FORMAT_ATOM, $lock_expiration )->format( 'Y-m-d' ) : false; static::assertSame( gmdate( 'Y-m-d', strtotime( 'tomorrow' ) ), $date ); remove_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); @@ -315,47 +307,6 @@ public function test_unlock() { remove_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); } - /** - * Test that is_locked() handles both date formats (with and without microseconds). - * This ensures compatibility with both WordPress trunk/PHP 8.4+ and stable versions. - */ - public function test_is_locked_handles_both_date_formats() { - $tokens = new Tokens(); - - $this->site_url = 'https://test.example.org'; - add_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); - - // Test with date format without microseconds (old format). - $future_date = ( new DateTime() )->add( new DateInterval( 'PT1H' ) ); - $lock_value = $future_date->format( 'Y-m-d\TH:i:sP' ) . '|||' . base64_encode( 'https://test.example.org' ); - Jetpack_Options::update_option( 'token_lock', $lock_value ); - - // Should not be locked (same site URL). - static::assertFalse( $tokens->is_locked() ); - - // Change site URL, should now be locked. - $this->site_url = 'https://other.example.org'; - static::assertTrue( $tokens->is_locked() ); - - $tokens->remove_lock(); - - // Test with date format with microseconds (new format in WordPress trunk/PHP 8.4+). - $future_date_with_microseconds = ( new DateTime() )->add( new DateInterval( 'PT1H' ) ); - $lock_value_with_microseconds = $future_date_with_microseconds->format( 'Y-m-d\TH:i:s.uP' ) . '|||' . base64_encode( 'https://test.example.org' ); - Jetpack_Options::update_option( 'token_lock', $lock_value_with_microseconds ); - - // Should not be locked (same site URL). - $this->site_url = 'https://test.example.org'; - static::assertFalse( $tokens->is_locked() ); - - // Change site URL, should now be locked. - $this->site_url = 'https://other.example.org'; - static::assertTrue( $tokens->is_locked() ); - - $tokens->remove_lock(); - remove_filter( 'jetpack_sync_site_url', array( $this, 'filter_site_url' ), 10 ); - } - /** * Filter to get the current site URL. * diff --git a/projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk b/projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk new file mode 100644 index 000000000000..e5fd19336af8 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix verbum comments test expectations for WordPress trunk block output changes (Gutenberg PR #71207). diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php index 7e052d482cd1..90857511f590 100644 --- a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php +++ b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php @@ -43,7 +43,9 @@ public function test_comment_text_block_sanitization_sanity_check() { $comment_content = '
test
'; $filtered_content = preg_replace( '/\R+/', '', Verbum_Block_Utils::render_verbum_blocks( $comment_content ) ); - $expected_content = 'something
someone
test
'; + // WordPress trunk removed layout classes from block output (Gutenberg PR #71207). + // The test now expects output without those classes to match both trunk and stable versions. + $expected_content = 'something
someone
test
'; $this->assertSame( $expected_content, $filtered_content ); } From b0f485cbba1a3719eaf1654704fb0ce092e033c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:34:45 +0000 Subject: [PATCH 06/14] Jetpack MU WPCOM: Clarify test comment Updated comment to be more accurate - this test is for trunk compatibility specifically. Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../php/features/verbum-comments/Verbum_Block_Utils_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php index 90857511f590..a7b8ab1dfbc9 100644 --- a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php +++ b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php @@ -44,7 +44,7 @@ public function test_comment_text_block_sanitization_sanity_check() { $filtered_content = preg_replace( '/\R+/', '', Verbum_Block_Utils::render_verbum_blocks( $comment_content ) ); // WordPress trunk removed layout classes from block output (Gutenberg PR #71207). - // The test now expects output without those classes to match both trunk and stable versions. + // Updated test expectations to match the new trunk output format. $expected_content = 'something
someone
test
'; $this->assertSame( $expected_content, $filtered_content ); } From b15c48dfa44cd3cae38bc73a44df2feb3e5f60b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:46:29 +0000 Subject: [PATCH 07/14] Add WordPress version detection for block output compatibility Created helper traits to handle WordPress 6.9 vs 7.0+ block output differences: - Added Jetpack_WP_Version_Test_Helpers trait for Jetpack plugin tests - Added Jetpack_Mu_Wpcom_WP_Version_Test_Helpers trait for MU WPCOM tests - Updated Block_Fixture_TestCase to normalize block HTML for version compatibility - Updated Verbum_Block_Utils_Test to use version-specific expectations WordPress 7.0+ (Gutenberg PR #71207) removed layout classes like 'is-layout-flow' from block output. Tests now conditionally expect the correct format based on WordPress version, allowing them to pass on both WP 6.9 and 7.0+ (trunk). Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../changelog/fix-verbum-block-test-wp-trunk | 2 +- .../Verbum_Block_Utils_Test.php | 12 ++- .../php/trait-wp-version-test-helpers.php | 48 +++++++++++ .../changelog/fix-block-tests-wp-version | 3 + .../blocks/class-block-fixture-testcase.php | 16 +++- .../php/trait-wp-version-test-helpers.php | 86 +++++++++++++++++++ 6 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php create mode 100644 projects/plugins/jetpack/changelog/fix-block-tests-wp-version create mode 100644 projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php diff --git a/projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk b/projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk index e5fd19336af8..85c75b12bda6 100644 --- a/projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk +++ b/projects/packages/jetpack-mu-wpcom/changelog/fix-verbum-block-test-wp-trunk @@ -1,4 +1,4 @@ Significance: patch Type: fixed -Fix verbum comments test expectations for WordPress trunk block output changes (Gutenberg PR #71207). +Add WordPress version detection to handle both WP 6.9 and 7.0+ block output in tests (Gutenberg PR #71207). diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php index a7b8ab1dfbc9..dd6e60f2cec4 100644 --- a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php +++ b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/Verbum_Block_Utils_Test.php @@ -9,6 +9,7 @@ use Brain\Monkey\Functions; use PHPUnit\Framework\Attributes\CoversClass; require_once Jetpack_Mu_Wpcom::PKG_DIR . 'src/features/verbum-comments/assets/class-verbum-block-utils.php'; +require_once __DIR__ . '/../../trait-wp-version-test-helpers.php'; /** * Test class for Verbum_Block_Utils. @@ -17,6 +18,7 @@ */ #[CoversClass( Verbum_Block_Utils::class )] class Verbum_Block_Utils_Test extends \WorDBless\BaseTestCase { + use Jetpack_Mu_Wpcom_WP_Version_Test_Helpers; /** * Ensure string comments are not modified when 'render_verbum_blocks' is applied */ @@ -43,9 +45,13 @@ public function test_comment_text_block_sanitization_sanity_check() { $comment_content = 'something
someone
test
'; $filtered_content = preg_replace( '/\R+/', '', Verbum_Block_Utils::render_verbum_blocks( $comment_content ) ); - // WordPress trunk removed layout classes from block output (Gutenberg PR #71207). - // Updated test expectations to match the new trunk output format. - $expected_content = 'something
someone
test
'; + // WordPress trunk (7.0+) removed layout classes from block output (Gutenberg PR #71207). + // We need to handle both old (with classes) and new (without classes) formats. + $expected_content_wp7 = 'something
someone
test
'; + $expected_content_wp6 = 'something
someone
test
'; + + $expected_content = $this->get_version_specific_expected_html( $expected_content_wp7, $expected_content_wp6 ); + $this->assertSame( $expected_content, $filtered_content ); } diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php new file mode 100644 index 000000000000..6afa8aa593aa --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php @@ -0,0 +1,48 @@ +=' ); + } + + /** + * Get version-appropriate expected HTML for block output. + * + * @param string $html_without_layout_classes HTML without layout classes (WP 7.0+ format). + * @param string $html_with_layout_classes HTML with layout classes (WP 6.9 and earlier format). + * @return string The appropriate HTML for the current WordPress version. + */ + protected function get_version_specific_expected_html( $html_without_layout_classes, $html_with_layout_classes ) { + if ( $this->is_wp_7_or_higher() ) { + return $html_without_layout_classes; + } + + return $html_with_layout_classes; + } +} diff --git a/projects/plugins/jetpack/changelog/fix-block-tests-wp-version b/projects/plugins/jetpack/changelog/fix-block-tests-wp-version new file mode 100644 index 000000000000..fa50a115b696 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-block-tests-wp-version @@ -0,0 +1,3 @@ +Significance: patch +Type: other +Comment: Add WordPress version detection to handle both WP 6.9 and 7.0+ block output in tests. diff --git a/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php b/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php index f172e6101cd0..f01944dd465b 100644 --- a/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php +++ b/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php @@ -5,12 +5,18 @@ * @package automattic/jetpack */ +/** + * Include helper trait for WordPress version-specific test expectations. + */ +require_once __DIR__ . '/trait-wp-version-test-helpers.php'; + /** * Jetpack Block Fixture Test Case with method for testing against the block's * serialized HTML test fixtures, generated by the block's `save` method in JavaScript. */ abstract class Jetpack_Block_Fixture_TestCase extends WP_UnitTestCase { use \Automattic\Jetpack\PHPUnit\WP_UnitTestCase_Fix; + use Jetpack_WP_Version_Test_Helpers; /** * This test iterates over the block's serialized fixtures, and tests that the generated @@ -39,11 +45,14 @@ public function generate_server_side_rendering_based_on_serialized_fixtures( $parsed_blocks = parse_blocks( $block_markup ); $rendered_output = trim( render_block( $parsed_blocks[0] ) ); + // Normalize output for version-agnostic comparison + $normalized_output = $this->normalize_block_html_for_version( $rendered_output ); + $target_markup_filename = str_replace( '.serialized.html', $target_extension, $file ); // Create a server rendered fixture if one does not exist. if ( ! file_exists( $target_markup_filename ) ) { - file_put_contents( $target_markup_filename, $rendered_output ); + file_put_contents( $target_markup_filename, $normalized_output ); $fail_messages[] = sprintf( "No server rendered fixture could be found for the %s block's %s fixture\n" . @@ -56,11 +65,12 @@ public function generate_server_side_rendering_based_on_serialized_fixtures( $server_rendered_fixture = file_get_contents( $target_markup_filename ); $this->assertEquals( - $rendered_output, + $normalized_output, trim( $server_rendered_fixture ), sprintf( 'The results of render_block for %s called with serialized markup from %s do not match ' . - "the server-rendered fixture: %s\n", + "the server-rendered fixture: %s\n" . + "Note: Layout classes (is-layout-flow) are normalized for WordPress version compatibility.\n", $block_name, basename( $file ), basename( $target_markup_filename ) diff --git a/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php b/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php new file mode 100644 index 000000000000..9552a394ac42 --- /dev/null +++ b/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php @@ -0,0 +1,86 @@ +=' ); + } + + /** + * Remove layout classes from block HTML output. + * + * Strips classes like 'is-layout-flow' and 'wp-block-*-is-layout-flow' + * that were removed in WordPress 7.0+ (Gutenberg PR #71207). + * + * @param string $html The HTML content to process. + * @return string The HTML with layout classes removed. + */ + protected function remove_layout_classes( $html ) { + // Remove is-layout-* classes + $html = preg_replace( '/\s+is-layout-[a-z-]+/', '', $html ); + + // Remove wp-block-*-is-layout-* classes + $html = preg_replace( '/\s+wp-block-[a-z-]+-is-layout-[a-z-]+/', '', $html ); + + return $html; + } + + /** + * Normalize block HTML output for version-agnostic comparison. + * + * If testing against WP 7.0+, returns HTML as-is. + * If testing against WP 6.9 or earlier, removes layout classes to match WP 7.0+ output. + * + * @param string $html The HTML content to normalize. + * @return string The normalized HTML. + */ + protected function normalize_block_html_for_version( $html ) { + if ( $this->is_wp_7_or_higher() ) { + // WP 7.0+ doesn't have layout classes, so HTML is already in the expected format + return $html; + } + + // WP 6.9 and earlier have layout classes, so remove them to match WP 7.0+ expectations + return $this->remove_layout_classes( $html ); + } + + /** + * Get version-appropriate expected HTML for block output. + * + * @param string $html_without_layout_classes HTML without layout classes (WP 7.0+ format). + * @param string $html_with_layout_classes HTML with layout classes (WP 6.9 and earlier format). + * @return string The appropriate HTML for the current WordPress version. + */ + protected function get_version_specific_expected_html( $html_without_layout_classes, $html_with_layout_classes ) { + if ( $this->is_wp_7_or_higher() ) { + return $html_without_layout_classes; + } + + return $html_with_layout_classes; + } +} From 5bcf6f5a84084ce2913b4f33ad8855b432afe04c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 03:47:17 +0000 Subject: [PATCH 08/14] Fix trait require path in Block_Fixture_TestCase Corrected the path to the trait file - it's two directories up from the extensions/blocks directory. Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../php/extensions/blocks/class-block-fixture-testcase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php b/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php index f01944dd465b..8c04e17ee395 100644 --- a/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php +++ b/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php @@ -8,7 +8,7 @@ /** * Include helper trait for WordPress version-specific test expectations. */ -require_once __DIR__ . '/trait-wp-version-test-helpers.php'; +require_once __DIR__ . '/../../trait-wp-version-test-helpers.php'; /** * Jetpack Block Fixture Test Case with method for testing against the block's From 153d8c21b69e25f986f11f3b50f7d6badf73dd36 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 04:18:11 +0000 Subject: [PATCH 09/14] Improve WordPress version detection robustness - Use get_bloginfo('version') as primary method (more reliable in tests) - Fall back to global $wp_version if get_bloginfo not available - Default to true (WP 7.0+ behavior) if version cannot be determined - This makes tests forward-compatible with trunk and handles edge cases Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../tests/php/trait-wp-version-test-helpers.php | 11 +++++++++-- .../tests/php/trait-wp-version-test-helpers.php | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php index 6afa8aa593aa..815104d4916c 100644 --- a/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php +++ b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php @@ -20,10 +20,17 @@ trait Jetpack_Mu_Wpcom_WP_Version_Test_Helpers { * @return bool True if WordPress 7.0+, false otherwise. */ protected function is_wp_7_or_higher() { - global $wp_version; + // Try to get version from get_bloginfo() first (more reliable in test environments) + if ( function_exists( 'get_bloginfo' ) ) { + $wp_version = get_bloginfo( 'version' ); + } else { + global $wp_version; + } if ( empty( $wp_version ) ) { - return false; + // If we can't determine version, assume we're on a newer version + // This makes tests forward-compatible with trunk + return true; } // Check if version is 7.0 or higher diff --git a/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php b/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php index 9552a394ac42..33f5c3fc6303 100644 --- a/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php +++ b/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php @@ -20,10 +20,17 @@ trait Jetpack_WP_Version_Test_Helpers { * @return bool True if WordPress 7.0+, false otherwise. */ protected function is_wp_7_or_higher() { - global $wp_version; + // Try to get version from get_bloginfo() first (more reliable in test environments) + if ( function_exists( 'get_bloginfo' ) ) { + $wp_version = get_bloginfo( 'version' ); + } else { + global $wp_version; + } if ( empty( $wp_version ) ) { - return false; + // If we can't determine version, assume we're on a newer version + // This makes tests forward-compatible with trunk + return true; } // Check if version is 7.0 or higher From cad4544599f0a71bd4bfed311b8774eda09a2a98 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 04:19:14 +0000 Subject: [PATCH 10/14] Fix default behavior when version cannot be determined Changed default from true to false when WordPress version cannot be determined. This is safer because: - If on WP 7.0+, stripping non-existent classes is harmless - If on WP 6.9, we correctly strip the classes that are present - Ensures tests are compatible regardless of version detection issues Co-authored-by: kraftbj <88897+kraftbj@users.noreply.github.com> --- .../tests/php/trait-wp-version-test-helpers.php | 6 +++--- .../jetpack/tests/php/trait-wp-version-test-helpers.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php index 815104d4916c..749392208fa5 100644 --- a/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php +++ b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php @@ -28,9 +28,9 @@ protected function is_wp_7_or_higher() { } if ( empty( $wp_version ) ) { - // If we can't determine version, assume we're on a newer version - // This makes tests forward-compatible with trunk - return true; + // If we can't determine version, assume we're on an older version + // This is safer for test compatibility - we'll normalize by removing classes + return false; } // Check if version is 7.0 or higher diff --git a/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php b/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php index 33f5c3fc6303..8908c4a8d805 100644 --- a/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php +++ b/projects/plugins/jetpack/tests/php/trait-wp-version-test-helpers.php @@ -28,9 +28,9 @@ protected function is_wp_7_or_higher() { } if ( empty( $wp_version ) ) { - // If we can't determine version, assume we're on a newer version - // This makes tests forward-compatible with trunk - return true; + // If we can't determine version, assume we're on an older version + // This is safer for test compatibility - we'll normalize by removing classes + return false; } // Check if version is 7.0 or higher From 0def849521a179612f73fa13b0a02d87ef99255c Mon Sep 17 00:00:00 2001 From: Brandon Kraftsomething
someone
test
'; $expected_content_wp6 = 'something
someone
test
'; diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php index a7acd504ee4c..2beddaee3c55 100644 --- a/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php +++ b/projects/packages/jetpack-mu-wpcom/tests/php/trait-wp-version-test-helpers.php @@ -7,6 +7,8 @@ * * This trait provides helper methods to handle version-specific expectations in tests. * + * @todo Remove this trait once WP 7.0 is the minimum supported version. + * * @package automattic/jetpack-mu-wpcom */ diff --git a/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php b/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php index 5942e1f73d41..164c879b3f8d 100644 --- a/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php +++ b/projects/plugins/jetpack/tests/php/extensions/blocks/class-block-fixture-testcase.php @@ -90,6 +90,8 @@ public function generate_server_side_rendering_based_on_serialized_fixtures( * - `wp-block-paragraph` class (added in WP trunk, core r61605) * - Leftover empty `class=""` attributes after stripping * + * @todo Remove this method once WP 7.0 is the minimum supported version. + * * @param string $html The HTML content to normalize. * @return string The normalized HTML. */ From e6b8b021a16525d3ee64ba88f1701a43ed4e7392 Mon Sep 17 00:00:00 2001 From: Brandon Kraftsomething
someone