From 11e758e9a7fc78130d947c9ba2b1247dcb86387f Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 12:59:05 +0100 Subject: [PATCH 01/21] Fix typo in comment --- tests/phpunit/includes/build-visual-html-tree.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/includes/build-visual-html-tree.php b/tests/phpunit/includes/build-visual-html-tree.php index ac31a0ac071db..e7cf543b56a73 100644 --- a/tests/phpunit/includes/build-visual-html-tree.php +++ b/tests/phpunit/includes/build-visual-html-tree.php @@ -237,7 +237,7 @@ static function ( $a, $b ) { ++$indent_level; } - // If they're no attributes, we're done here. + // If there are no attributes, we're done here. if ( empty( $block_attrs ) ) { break; } From 84c65af3c52a337b0e06e4e7bd9e26176df5050a Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 12:59:18 +0100 Subject: [PATCH 02/21] Do not trim leading text node whitespace --- tests/phpunit/includes/build-visual-html-tree.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/includes/build-visual-html-tree.php b/tests/phpunit/includes/build-visual-html-tree.php index e7cf543b56a73..d2c63990a12b0 100644 --- a/tests/phpunit/includes/build-visual-html-tree.php +++ b/tests/phpunit/includes/build-visual-html-tree.php @@ -202,7 +202,7 @@ static function ( $a, $b ) { case '#cdata-section': case '#text': $text_content = $processor->get_modifiable_text(); - if ( '' === trim( $text_content, " \f\t\r\n" ) ) { + if ( '' === $text_content ) { break; } $was_text = true; From d483c8da17f44d17f34339ddffad13070537614a Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 13:00:36 +0100 Subject: [PATCH 03/21] Update test without leading whitespace, use nowdoc --- tests/phpunit/tests/build-visual-html-tree.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/build-visual-html-tree.php b/tests/phpunit/tests/build-visual-html-tree.php index 42e35c5b74b9f..7c8e7c645010e 100644 --- a/tests/phpunit/tests/build-visual-html-tree.php +++ b/tests/phpunit/tests/build-visual-html-tree.php @@ -9,13 +9,13 @@ */ class Tests_Build_Equivalent_HTML_Semantic_Tree extends WP_UnitTestCase { public function data_build_equivalent_html_semantic_tree() { - $block_markup = << -
- -END; + $block_markup = <<<'HTML' + +
+ +HTML; - $tree_structure = << array( $block_markup, $tree_structure ), From 72e7c40fcf8c14fd521c07a615c36b00f6a5a19b Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 13:08:57 +0100 Subject: [PATCH 04/21] Add test for https://core.trac.wordpress.org/ticket/64531 --- .../phpunit/tests/build-visual-html-tree.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/phpunit/tests/build-visual-html-tree.php b/tests/phpunit/tests/build-visual-html-tree.php index 7c8e7c645010e..aee5e3c80fb64 100644 --- a/tests/phpunit/tests/build-visual-html-tree.php +++ b/tests/phpunit/tests/build-visual-html-tree.php @@ -141,4 +141,41 @@ public function test_build_equivalent_html_semantic_tree_with_non_equivalent_htm $this->assertNotSame( $tree_expected, $tree_actual ); } + + /** + * @ticket 64531 + * + * @covers ::build_visual_html_tree + */ + public function test_spacing() { + $html = <<<'HTML' +

space-surrounded

+

 nbsp-surrounded 

+

+newline-surrounded

+

tab-surrounded

+

ok

+HTML; + + $expected = << + " space-surrounded " +"\n" +

+ "\u{00A0}nbsp-surrounded\u{00A0}" +"\n" +

+ "\nnewline-surrounded\n" +"\n" +

+ "\ttab-surrounded\t" +"\n" +

+ "ok" + +TREE; + + $tree_result = build_visual_html_tree( $html, '' ); + $this->assertSame( $expected, $tree_result ); + } } From 9f672baedc4beb61ac83abadb4784dfedc011edd Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 13:24:59 +0100 Subject: [PATCH 05/21] Add whitespace inside block delimiters --- tests/phpunit/tests/build-visual-html-tree.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/phpunit/tests/build-visual-html-tree.php b/tests/phpunit/tests/build-visual-html-tree.php index aee5e3c80fb64..5d0b3e5f75eb7 100644 --- a/tests/phpunit/tests/build-visual-html-tree.php +++ b/tests/phpunit/tests/build-visual-html-tree.php @@ -29,9 +29,13 @@ public function data_build_equivalent_html_semantic_tree() { } } } + " + "


class="has-custom-classname is-style-default wp-block-separator" style="margin-top:50px;margin-bottom:50px;" + " +" TREE; From 1e9b067c82ef7a02462f31f5e0321c0cb35a422d Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 15:32:22 +0100 Subject: [PATCH 06/21] Correct whitespace in scripts HTML tests --- tests/phpunit/tests/dependencies/scripts.php | 138 +++++++++---------- tests/phpunit/tests/dependencies/styles.php | 5 +- 2 files changed, 70 insertions(+), 73 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 8cca03010cad2..82446bfa9d3e2 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -287,7 +287,7 @@ public function test_delayed_dependent_with_blocking_dependency( $strategy ) { wp_enqueue_script( 'main-script-a2', '/main-script-a2.js', array( 'dependency-script-a2' ), null, compact( 'strategy' ) ); $output = get_echo( 'wp_print_scripts' ); $expected = "\n"; - $expected .= ""; + $expected .= "\n"; $this->assertEqualHTML( $expected, $output, '', 'Dependents of a blocking dependency are free to have any strategy.' ); } @@ -309,8 +309,9 @@ public function test_blocking_dependent_with_delayed_dependency( $strategy ) { wp_enqueue_script( 'dependent-script-a3', '/dependent-script-a3.js', array( 'main-script-a3' ), null ); $output = get_echo( 'wp_print_scripts' ); $expected = << - + + + JS; $this->assertEqualHTML( $expected, $output, '', 'Blocking dependents must force delayed dependencies to become blocking.' ); } @@ -1076,7 +1077,7 @@ public function test_various_strategy_dependency_chains( $set_up, $expected_mark public function test_loading_strategy_with_defer_having_no_dependents_nor_dependencies() { wp_enqueue_script( 'main-script-d1', 'http://example.com/main-script-d1.js', array(), null, array( 'strategy' => 'defer' ) ); $output = get_echo( 'wp_print_scripts' ); - $expected = "\n"; + $expected = ""; $this->assertEqualHTMLScriptTagById( $expected, $output, 'Expected defer, as there is no dependent or dependency' ); } @@ -1285,22 +1286,20 @@ public function data_provider_to_test_fetchpriority_bumping(): array { return array( 'enqueue_bajo' => array( 'enqueues' => array( 'bajo' ), - 'expected' => '', + 'expected' => "\n", ), 'enqueue_auto' => array( 'enqueues' => array( 'auto' ), - 'expected' => ' - - - ', + 'expected' => + "\n" . + "\n", ), 'enqueue_alto' => array( 'enqueues' => array( 'alto' ), - 'expected' => ' - - - - ', + 'expected' => + "\n" . + "\n" . + "\n", ), ); } @@ -1354,16 +1353,17 @@ public function test_fetchpriority_bumping_a_to_z() { wp_enqueue_script( 'x' ); $actual = get_echo( 'wp_print_scripts' ); - $expected = ' - - - - - - - - - '; + $expected = <<<'HTML' + + + + + + + + + +HTML; $this->assertEqualHTML( $expected, $actual, '', "Snapshot:\n$actual" ); } @@ -1419,7 +1419,7 @@ public function test_priority_of_dependency_for_non_enqueued_dependent() { $actual = $this->normalize_markup_for_snapshot( get_echo( array( $wp_scripts, 'print_scripts' ) ) ); $this->assertEqualHTML( - '', + "\n", $actual, '', "Snapshot:\n$actual" @@ -1456,7 +1456,7 @@ public function test_printing_default_script_comment_reply_enqueued_or_not_enque $this->assertEqualHTML( sprintf( - '', + "\n", includes_url( 'js/comment-reply.js' ) ), $markup @@ -1497,7 +1497,7 @@ public function test_loading_strategy_with_invalid_defer_registration() { wp_enqueue_script( 'dependent-script-d4-3', '/dependent-script-d4-3.js', array( 'dependent-script-d4-2' ), null, array( 'strategy' => 'defer' ) ); $output = get_echo( 'wp_print_scripts' ); - $expected = "\n"; + $expected = ""; $this->assertEqualHTMLScriptTagById( $expected, $output, 'Scripts registered as defer but that have all dependents with no strategy, should become blocking (no strategy).' ); } @@ -2210,6 +2210,7 @@ public function test_wp_add_inline_script_before() { console.log("before"); //# sourceURL=test-example-js-before + HTML; $expected .= "\n"; @@ -2229,6 +2230,7 @@ public function test_wp_add_inline_script_after() { console.log("after"); //# sourceURL=test-example-js-after + HTML; $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); @@ -2574,13 +2576,13 @@ public function test_wp_add_inline_script_customize_dependency() { _print_scripts(); $print_scripts = $this->getActualOutput(); - $expected = "\n"; + $expected = ""; $this->assertEqualHTMLScriptTagById( $expected, $print_scripts ); $expected = "\n"; + $expected .= ""; $this->assertEqualHTMLScriptTagById( $expected, $print_scripts ); } @@ -3518,6 +3520,9 @@ public function test_wp_scripts_move_to_footer( $set_up, $expected_header, $expe wp_scripts()->do_footer_items(); $footer = ob_get_clean(); + // $expected_footer = trim( $expected_footer, "\n\t" ); + // $expected_header = trim( $expected_header, "\n\t" ); + $this->assertEqualHTML( $expected_header, $header, '', 'Expected header script markup to match.' ); $this->assertEqualHTML( $expected_footer, $footer, '', 'Expected footer script markup to match.' ); $this->assertEqualSets( $expected_in_footer, wp_scripts()->in_footer, 'Expected to have the same handles for in_footer.' ); @@ -3567,10 +3572,9 @@ public function data_provider_script_move_to_footer() { wp_enqueue_script( 'script-b', 'https://example.com/script-b.js', array( 'script-a' ), null, array( 'in_footer' => true ) ); }, 'expected_header' => '', - 'expected_footer' => ' - - - ', + 'expected_footer' => + "\n" . + "\n", 'expected_in_footer' => array( 'script-a', 'script-b', @@ -3588,10 +3592,9 @@ public function data_provider_script_move_to_footer() { wp_enqueue_script( 'script-b', 'https://example.com/script-b.js', array( 'script-a' ), null, array( 'in_footer' => true ) ); }, 'expected_header' => '', - 'expected_footer' => ' - - - ', + 'expected_footer' => + "\n" . + "\n", 'expected_in_footer' => array( 'script-a', 'script-b', @@ -3608,10 +3611,9 @@ public function data_provider_script_move_to_footer() { wp_enqueue_script( 'script-a', 'https://example.com/script-a.js', array(), null, array( 'strategy' => 'defer' ) ); wp_enqueue_script( 'script-b', 'https://example.com/script-b.js', array( 'script-a' ), null, array( 'in_footer' => false ) ); }, - 'expected_header' => ' - - - ', + 'expected_header' => + "\n" . + "\n", 'expected_footer' => '', 'expected_in_footer' => array(), 'expected_groups' => array( @@ -3635,12 +3637,10 @@ public function data_provider_script_move_to_footer() { ) ); }, - 'expected_header' => ' - - ', - 'expected_footer' => ' - - ', + 'expected_header' => + "\n", + 'expected_footer' => + "\n", 'expected_in_footer' => array( 'script-b', ), @@ -3685,14 +3685,12 @@ public function data_provider_script_move_to_footer() { ) ); }, - 'expected_header' => ' - - - ', - 'expected_footer' => ' - - - ', + 'expected_header' => + "\n" . + "\n", + 'expected_footer' => + "\n" . + "\n", 'expected_in_footer' => array( 'script-c', 'script-d', @@ -3732,12 +3730,11 @@ public function data_provider_script_move_to_footer() { ); }, 'expected_header' => '', - 'expected_footer' => ' - - - - - ', + 'expected_footer' => + "\n" . + "\n" . + "\n" . + "\n", 'expected_in_footer' => array( 'script-a', 'script-b', @@ -3779,14 +3776,12 @@ public function data_provider_script_move_to_footer() { ) ); }, - 'expected_header' => ' - - - ', - 'expected_footer' => ' - - - ', + 'expected_header' => + "\n" . + "\n", + 'expected_footer' => + "\n" . + "\n", 'expected_in_footer' => array( 'script-c', 'script-d', @@ -3997,6 +3992,7 @@ public function test_source_url_with_concat() { $print_scripts = get_echo( '_print_scripts' ); $expected = << var one = {"key":"val"};var two = {"key":"val"}; //# sourceURL=js-inline-concat-one%2Ctwo @@ -4070,7 +4066,7 @@ public function test_varying_versions_added_to_handle_args_enqueued_scripts( $ve wp_enqueue_script( 'test-script?qs1=q1&qs2=q2', '/test-script.js', array(), $version ); $markup = get_echo( 'wp_print_scripts' ); - $expected = ""; + $expected = "\n"; $this->assertEqualHTML( $expected, $markup, '', 'Expected equal snapshot for wp_print_scripts() with version ' . var_export( $version, true ) . ":\n$markup" ); } @@ -4091,7 +4087,7 @@ public function test_varying_versions_added_to_handle_args_registered_then_enque wp_enqueue_script( 'test-script?qs1=q1&qs2=q2' ); $markup = get_echo( 'wp_print_scripts' ); - $expected = ""; + $expected = "\n"; $this->assertEqualHTML( $expected, $markup, '', 'Expected equal snapshot for wp_print_scripts() with version ' . var_export( $version, true ) . ":\n$markup" ); } diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php index 57687752f6a08..bbaf9432d8df0 100644 --- a/tests/phpunit/tests/dependencies/styles.php +++ b/tests/phpunit/tests/dependencies/styles.php @@ -882,6 +882,7 @@ public function test_source_url_with_concat() { h1 { background: blue; }h2 { color: green; } /*# sourceURL=css-inline-concat-one%2Ctwo */ + HTML; $this->assertEqualHTML( $expected, $printed ); @@ -935,7 +936,7 @@ public function test_varying_versions_added_to_handle_args_enqueued_styles( $ver wp_enqueue_style( 'test-style?qs1=q1&qs2=q2', '/test-style.css', array(), $version ); $markup = get_echo( 'wp_print_styles' ); - $expected = ""; + $expected = "\n"; $this->assertEqualHTML( $expected, $markup, '', 'Expected equal snapshot for wp_print_styles() with version ' . var_export( $version, true ) . ":\n$markup" ); } @@ -956,7 +957,7 @@ public function test_varying_versions_added_to_handle_args_registered_then_enque wp_enqueue_style( 'test-style?qs1=q1&qs2=q2' ); $markup = get_echo( 'wp_print_styles' ); - $expected = ""; + $expected = "\n"; $this->assertEqualHTML( $expected, $markup, '', 'Expected equal snapshot for wp_print_styles() with version ' . var_export( $version, true ) . ":\n$markup" ); } From 76ec5b1b98f09b5cba4db9f32e298a23c8e10618 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 15:37:00 +0100 Subject: [PATCH 07/21] lint --- tests/phpunit/tests/dependencies/scripts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 82446bfa9d3e2..0d03f40731666 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -2582,7 +2582,7 @@ public function test_wp_add_inline_script_customize_dependency() { $expected = ""; + $expected .= ''; $this->assertEqualHTMLScriptTagById( $expected, $print_scripts ); } From 79d0a66f8ab152213050b48847b11dc0e4a21114 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 15:47:34 +0100 Subject: [PATCH 08/21] Cleanup debug code --- tests/phpunit/tests/dependencies/scripts.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 0d03f40731666..125ba9ea333ed 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -3520,9 +3520,6 @@ public function test_wp_scripts_move_to_footer( $set_up, $expected_header, $expe wp_scripts()->do_footer_items(); $footer = ob_get_clean(); - // $expected_footer = trim( $expected_footer, "\n\t" ); - // $expected_header = trim( $expected_header, "\n\t" ); - $this->assertEqualHTML( $expected_header, $header, '', 'Expected header script markup to match.' ); $this->assertEqualHTML( $expected_footer, $footer, '', 'Expected footer script markup to match.' ); $this->assertEqualSets( $expected_in_footer, wp_scripts()->in_footer, 'Expected to have the same handles for in_footer.' ); From e90bfbfb724b9b4a0d283ceaf6d43b17cb966368 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 16:10:05 +0100 Subject: [PATCH 09/21] Fix script modules tests --- .../tests/script-modules/wpScriptModules.php | 119 +++++++++--------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/tests/phpunit/tests/script-modules/wpScriptModules.php b/tests/phpunit/tests/script-modules/wpScriptModules.php index 047176bdb2d8b..a20b8385487a5 100644 --- a/tests/phpunit/tests/script-modules/wpScriptModules.php +++ b/tests/phpunit/tests/script-modules/wpScriptModules.php @@ -572,12 +572,14 @@ static function ( $src, $id ) { 10, 2 ); - $actual = get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ); + $actual = get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ); + $expected = <<<'HTML' + + + +HTML; $this->assertEqualHTML( - ' - - - ', + $expected, $actual, '', "Expected only one SCRIPT tag to be printed. Snapshot:\n$actual" @@ -1476,23 +1478,29 @@ public function test_in_footer_methods() { $actual_head = get_echo( array( wp_script_modules(), 'print_head_enqueued_script_modules' ) ); $actual_footer = get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ); + $expected = <<<'HTML' + + + + +HTML; + $this->assertEqualHTML( $actual_head, - ' - - - - ', + $expected, '', "Expected equal script modules in the HEAD. Snapshot:\n$actual_head" ); + + $expected = <<<'HTML' + + + + +HTML; $this->assertEqualHTML( $actual_footer, - ' - - - - ', + $expected, '', "Expected equal script modules in the footer. Snapshot:\n$actual_footer" ); @@ -1746,16 +1754,17 @@ public function test_fetchpriority_bumping_a_to_z() { $actual = get_echo( array( wp_script_modules(), 'print_script_module_preloads' ) ); $actual .= get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ); - $expected = ' - - - - - - - - - '; + $expected = <<<'HTML' + + + + + + + + + +HTML; $this->assertEqualHTML( $expected, $actual, '', "Snapshot:\n$actual" ); } @@ -1791,17 +1800,18 @@ public function test_fetchpriority_propagation() { $actual = get_echo( array( wp_script_modules(), 'print_script_module_preloads' ) ); $actual .= get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ); - $expected = ' - - - - - - - - - - '; + $expected = <<<'HTML' + + + + + + + + + + +HTML; $this->assertEqualHTML( $expected, $actual, '', "Snapshot:\n$actual" ); } @@ -1822,9 +1832,7 @@ public function test_default_script_modules() { $actual_preloads = $this->normalize_markup_for_snapshot( get_echo( array( wp_script_modules(), 'print_script_module_preloads' ) ) ); $this->assertEqualHTML( - ' - - ', + "\n", $actual_preloads, '', "Snapshot:\n$actual_preloads" @@ -1839,11 +1847,13 @@ public function test_default_script_modules() { ); $actual_footer_script_modules = $this->normalize_markup_for_snapshot( get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ) ); + $expected = <<<'HTML' + + + +HTML; $this->assertEqualHTML( - ' - - - ', + $expected, $actual_footer_script_modules, '', "Snapshot:\n$actual_footer_script_modules" @@ -1866,7 +1876,7 @@ public function test_priority_of_dependency_for_non_enqueued_dependent() { $actual = $this->normalize_markup_for_snapshot( get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ) ); $this->assertEqualHTML( - '', + "\n", $actual, '', "Snapshot:\n$actual" @@ -1895,12 +1905,13 @@ public function test_dependent_of_default_script_modules() { $actual = $this->normalize_markup_for_snapshot( $actual ); - $expected = ' - - - - - '; + $expected = <<<'HTML' + + + + + +HTML; $this->assertEqualHTML( $expected, $actual, '', "Snapshot:\n$actual" ); } @@ -2340,17 +2351,13 @@ public function test_static_import_dependency_with_dynamic_imports_depending_on_ "Expected import map to match snapshot:\n" . var_export( $import_map, true ) ); $this->assertEqualHTML( - ' - - ', + "\n", $preload_links, '', "Expected preload links to match snapshot:\n$preload_links" ); $this->assertEqualHTML( - ' - - ', + "\n", $script_modules, '', "Expected script modules to match snapshot:\n$script_modules" From e205a2c499577305684505fe478da4576ee459ee Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 16:14:19 +0100 Subject: [PATCH 10/21] Remove redundant "snapshots" from assertEqualHTML test assertion messages The diff in the HTML is already presented by these tests. Printing again just introduces more noise. --- .../tests/script-modules/wpScriptModules.php | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/tests/phpunit/tests/script-modules/wpScriptModules.php b/tests/phpunit/tests/script-modules/wpScriptModules.php index a20b8385487a5..1bd8b5c1663d3 100644 --- a/tests/phpunit/tests/script-modules/wpScriptModules.php +++ b/tests/phpunit/tests/script-modules/wpScriptModules.php @@ -582,7 +582,7 @@ static function ( $src, $id ) { $expected, $actual, '', - "Expected only one SCRIPT tag to be printed. Snapshot:\n$actual" + 'Expected only one SCRIPT tag to be printed.' ); } @@ -1489,7 +1489,7 @@ public function test_in_footer_methods() { $actual_head, $expected, '', - "Expected equal script modules in the HEAD. Snapshot:\n$actual_head" + 'Expected equal script modules in the HEAD.' ); $expected = <<<'HTML' @@ -1502,7 +1502,7 @@ public function test_in_footer_methods() { $actual_footer, $expected, '', - "Expected equal script modules in the footer. Snapshot:\n$actual_footer" + 'Expected equal script modules in the footer.' ); } @@ -1765,7 +1765,7 @@ public function test_fetchpriority_bumping_a_to_z() { HTML; - $this->assertEqualHTML( $expected, $actual, '', "Snapshot:\n$actual" ); + $this->assertEqualHTML( $expected, $actual ); } /** @@ -1812,7 +1812,7 @@ public function test_fetchpriority_propagation() { HTML; - $this->assertEqualHTML( $expected, $actual, '', "Snapshot:\n$actual" ); + $this->assertEqualHTML( $expected, $actual ); } /** @@ -1833,30 +1833,24 @@ public function test_default_script_modules() { $actual_preloads = $this->normalize_markup_for_snapshot( get_echo( array( wp_script_modules(), 'print_script_module_preloads' ) ) ); $this->assertEqualHTML( "\n", - $actual_preloads, - '', - "Snapshot:\n$actual_preloads" + $actual_preloads ); $actual_head_script_modules = $this->normalize_markup_for_snapshot( get_echo( array( wp_script_modules(), 'print_head_enqueued_script_modules' ) ) ); $this->assertEqualHTML( '', - $actual_head_script_modules, - '', - "Snapshot:\n$actual_head_script_modules" + $actual_head_script_modules ); $actual_footer_script_modules = $this->normalize_markup_for_snapshot( get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ) ); - $expected = <<<'HTML' + $expected = <<<'HTML' HTML; $this->assertEqualHTML( $expected, - $actual_footer_script_modules, - '', - "Snapshot:\n$actual_footer_script_modules" + $actual_footer_script_modules ); } @@ -1877,9 +1871,7 @@ public function test_priority_of_dependency_for_non_enqueued_dependent() { $actual = $this->normalize_markup_for_snapshot( get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) ) ); $this->assertEqualHTML( "\n", - $actual, - '', - "Snapshot:\n$actual" + $actual ); } @@ -1912,7 +1904,7 @@ public function test_dependent_of_default_script_modules() { HTML; - $this->assertEqualHTML( $expected, $actual, '', "Snapshot:\n$actual" ); + $this->assertEqualHTML( $expected, $actual ); } /** @@ -2354,13 +2346,13 @@ public function test_static_import_dependency_with_dynamic_imports_depending_on_ "\n", $preload_links, '', - "Expected preload links to match snapshot:\n$preload_links" + 'Expected preload links to match.' ); $this->assertEqualHTML( "\n", $script_modules, '', - "Expected script modules to match snapshot:\n$script_modules" + 'Expected script modules to match.' ); } From 2493b2654e72b4be2561dfc569ab7acf48c6e2ae Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 16:39:28 +0100 Subject: [PATCH 11/21] Fix archives tests --- tests/phpunit/tests/functions/wpGetArchives.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/functions/wpGetArchives.php b/tests/phpunit/tests/functions/wpGetArchives.php index 3f98d5c5644f6..99967e9be3211 100644 --- a/tests/phpunit/tests/functions/wpGetArchives.php +++ b/tests/phpunit/tests/functions/wpGetArchives.php @@ -221,10 +221,10 @@ static function ( $args ) { $ids = array_slice( array_reverse( self::$post_ids ), 0, 3 ); $expected = join( - "\n", + '', array_map( static function ( $id ) { - return sprintf( '
  • %s
  • ', get_permalink( $id ), get_the_title( $id ) ); + return sprintf( "\t
  • %s
  • \n", get_permalink( $id ), get_the_title( $id ) ); }, $ids ) From b2cca856878d6d4b0c1b92cee0673602a0c42271 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 16:40:12 +0100 Subject: [PATCH 12/21] Use nowdoc without indentation for block_markup --- tests/phpunit/tests/blocks/wpBlock.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index f7c4710c9c3fe..71839c42c0a71 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -368,19 +368,19 @@ public function test_render_applies_dynamic_render_block_filter() { * @return array */ public function data_provider_test_render_enqueues_scripts_and_styles(): array { - $block_markup = ' - -
    - -
    First child
    - - - -
    Last child
    - -
    - - '; + $block_markup = <<<'HTML' + +
    + +
    First child
    + + + +
    Last child
    + +
    + +HTML; // TODO: Add case where a dynamic block renders other blocks? return array( From 1bfbe890982a803114bf0d69a56c5391a5adb6aa Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 16:41:53 +0100 Subject: [PATCH 13/21] Remove redundant snapshot from assertion message assertEqualHTML already displays HTML differences --- tests/phpunit/tests/blocks/wpBlock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index 71839c42c0a71..e8e1cd60f87b8 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -682,7 +682,7 @@ public function test_render_enqueues_scripts_and_styles( ?Closure $set_up, strin $expected_rendered_block, $rendered_block, '', - "Rendered block does not contain expected HTML:\n$rendered_block" + 'Rendered block does not contain expected HTML.' ); } From 1580d3bc9a91010e9f8aad78bc54a6c0140e8c80 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 16:43:12 +0100 Subject: [PATCH 14/21] Fix simple test, remove extra whitespace --- tests/phpunit/tests/blocks/wpBlock.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index e8e1cd60f87b8..b3c11ad084386 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -562,9 +562,8 @@ static function ( $content ) { ); }, 'block_markup' => '
    ', - 'expected_rendered_block' => ' -
    - ', + 'expected_rendered_block' => + '
    ', 'expected_styles' => array( 'static-view-style', 'admin-bar' ), 'expected_scripts' => array( 'static-view-script', 'admin-bar' ), 'expected_script_modules' => array( 'static-view-script-module' ), From e44a2ad04d1798996aa554e8e271335583b214c4 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 16:59:15 +0100 Subject: [PATCH 15/21] Add nested blocks text nodes test --- .../phpunit/tests/build-visual-html-tree.php | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/build-visual-html-tree.php b/tests/phpunit/tests/build-visual-html-tree.php index 5d0b3e5f75eb7..d377092565c04 100644 --- a/tests/phpunit/tests/build-visual-html-tree.php +++ b/tests/phpunit/tests/build-visual-html-tree.php @@ -39,9 +39,40 @@ class="has-custom-classname is-style-default wp-block-separator" TREE; - return array( - 'Block delimiter' => array( $block_markup, $tree_structure ), - ); + yield 'Block delimiter' => array( $block_markup, $tree_structure ); + + $block_markup = <<<'HTML' + + One + + Two + + Three + + Four + +HTML; + + $tree_structure = <<<'TREE' +BLOCK["example/block"] + " + One + " + BLOCK["example/nested-void"] + " + Two + " + BLOCK["example/nested"] + " + Three + " + " + Four +" + +TREE; + + yield 'Text nodes in blocks' => array( $block_markup, $tree_structure ); } /** From 951307e9a815bdf3c4fd56c360f6d18a224052ce Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 17:35:05 +0100 Subject: [PATCH 16/21] Fix whitespace in blocks tests --- tests/phpunit/tests/blocks/wpBlock.php | 115 +++++++++++++++++-------- 1 file changed, 78 insertions(+), 37 deletions(-) diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index b3c11ad084386..85fa6e7151d46 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -387,13 +387,20 @@ public function data_provider_test_render_enqueues_scripts_and_styles(): array { 'all_printed' => array( 'set_up' => null, 'block_markup' => $block_markup, - 'expected_rendered_block' => ' -
    -
    First child
    -

    Hello World!

    -
    Last child
    -
    - ', + 'expected_rendered_block' => <<<'HTML' + +
    + +
    First child
    + +

    Hello World!

    + +
    Last child
    + +
    + +HTML + , 'expected_styles' => array( 'static-view-style', 'static-child-view-style', 'dynamic-view-style' ), 'expected_scripts' => array( 'static-view-script', 'static-child-view-script', 'dynamic-view-script' ), 'expected_script_modules' => array( 'static-view-script-module', 'static-child-view-script-module', 'dynamic-view-script-module' ), @@ -414,13 +421,20 @@ static function ( $content ) { ); }, 'block_markup' => $block_markup, - 'expected_rendered_block' => ' -
    -
    First child
    -

    Hello World!

    -
    Last child
    -
    - ', + 'expected_rendered_block' => <<<'HTML' + +
    + +
    First child
    + +

    Hello World!

    + +
    Last child
    + +
    + +HTML + , 'expected_styles' => array( 'static-view-style', 'dynamic-extra', 'static-child-view-style', 'dynamic-view-style' ), 'expected_scripts' => array( 'static-view-script', 'static-child-view-script', 'dynamic-view-script' ), 'expected_script_modules' => array( 'static-view-script-module', 'static-child-view-script-module', 'dynamic-view-script-module' ), @@ -430,12 +444,20 @@ static function ( $content ) { add_filter( 'render_block_core/dynamic', '__return_empty_string' ); }, 'block_markup' => $block_markup, - 'expected_rendered_block' => ' -
    -
    First child
    -
    Last child
    -
    - ', + 'expected_rendered_block' => <<<'HTML' + +
    + +
    First child
    + + + +
    Last child
    + +
    + +HTML + , 'expected_styles' => array( 'static-view-style', 'static-child-view-style' ), 'expected_scripts' => array( 'static-view-script', 'static-child-view-script' ), 'expected_script_modules' => array( 'static-view-script-module', 'static-child-view-script-module' ), @@ -456,12 +478,20 @@ static function ( $enqueue, $block_name ) { ); }, 'block_markup' => $block_markup, - 'expected_rendered_block' => ' -
    -
    First child
    -
    Last child
    -
    - ', + 'expected_rendered_block' => <<<'HTML' + +
    + +
    First child
    + + + +
    Last child
    + +
    + +HTML + , 'expected_styles' => array( 'static-view-style', 'static-child-view-style', 'dynamic-view-style' ), 'expected_scripts' => array( 'static-view-script', 'static-child-view-script', 'dynamic-view-script' ), 'expected_script_modules' => array( 'static-view-script-module', 'static-child-view-script-module', 'dynamic-view-script-module' ), @@ -488,11 +518,16 @@ static function ( $content ) { add_filter( 'render_block_core/static-child', '__return_empty_string' ); }, 'block_markup' => $block_markup, - 'expected_rendered_block' => ' -
    -

    Hello World!

    -
    - ', + 'expected_rendered_block' => <<<'HTML' + +
    + +

    Hello World!

    + +
    + +HTML + , 'expected_styles' => array( 'static-view-style', 'dynamic-view-style' ), 'expected_scripts' => array( 'static-view-script', 'dynamic-view-script' ), 'expected_script_modules' => array( 'static-view-script-module', 'dynamic-view-script-module' ), @@ -512,12 +547,18 @@ static function ( $content ) { ); }, 'block_markup' => $block_markup, - 'expected_rendered_block' => ' -
    -
    First child
    -

    Hello World!

    -
    - ', + 'expected_rendered_block' => <<<'HTML' + +
    + +
    First child
    + +

    Hello World!

    + +
    + +HTML + , 'expected_styles' => array( 'static-view-style', 'static-child-view-style', 'dynamic-view-style' ), 'expected_scripts' => array( 'static-view-script', 'static-child-view-script', 'dynamic-view-script' ), 'expected_script_modules' => array( 'static-view-script-module', 'static-child-view-script-module', 'dynamic-view-script-module' ), From 23e18f767c0eaf7b912c4b5174e5e922f8395672 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 17:35:33 +0100 Subject: [PATCH 17/21] Debugging code with invis chars --- tests/phpunit/tests/blocks/wpBlock.php | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index 85fa6e7151d46..4ac27548568f1 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -718,6 +718,16 @@ public function test_render_enqueues_scripts_and_styles( ?Closure $set_up, strin $this->assertSameSets( $expected_scripts, wp_scripts()->queue, 'Enqueued scripts do not meet expectations' ); $this->assertSameSets( $expected_script_modules, wp_script_modules()->get_queue(), 'Enqueued script modules do not meet expectations' ); + //echo "\n===\n"; + //var_export( $rendered_block ); + echo "\n===\n"; + var_export( self::replaceInvisible( $rendered_block ) ); + //echo "\n===\n"; + //var_export( $expected_rendered_block ); + echo "\n===\n"; + var_export( self::replaceInvisible( $expected_rendered_block ) ); + echo "\n===\n"; + $this->assertEqualHTML( $expected_rendered_block, $rendered_block, @@ -1481,4 +1491,26 @@ public function test_block_filters_for_inner_blocks() { $this->assertSame( 2, $render_block_data_callback->get_call_count() ); $this->assertSame( 2, $render_block_context_callback->get_call_count() ); } + + private static function replaceInvisible( string $s ): string { + return preg_replace_callback( + '/[\\x00-\\x1F\\x7F]/u', + static function ( array $matches ): string { + $codePoint = /** @type {number} */ ord($matches[0]); + switch ( $codePoint ) { + // U+007F DELETE -> U+2421 SYMBOL FOR DELETE + case 0x7f: + return "\u{2421}"; + + // Include a newline with newline replacement + case 0x0a: + return "\u{240A}\n"; + } + + // There's a nice Control Pictures Block at 0x2400 offset for the matched range + return mb_chr( $codePoint + 0x2400 ); + }, + $s + ); + } } From d2a297785b5764aee2cc860ea875572292b0a877 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 17:35:43 +0100 Subject: [PATCH 18/21] Revert "Debugging code with invis chars" This reverts commit 23e18f767c0eaf7b912c4b5174e5e922f8395672. --- tests/phpunit/tests/blocks/wpBlock.php | 32 -------------------------- 1 file changed, 32 deletions(-) diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index 4ac27548568f1..85fa6e7151d46 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -718,16 +718,6 @@ public function test_render_enqueues_scripts_and_styles( ?Closure $set_up, strin $this->assertSameSets( $expected_scripts, wp_scripts()->queue, 'Enqueued scripts do not meet expectations' ); $this->assertSameSets( $expected_script_modules, wp_script_modules()->get_queue(), 'Enqueued script modules do not meet expectations' ); - //echo "\n===\n"; - //var_export( $rendered_block ); - echo "\n===\n"; - var_export( self::replaceInvisible( $rendered_block ) ); - //echo "\n===\n"; - //var_export( $expected_rendered_block ); - echo "\n===\n"; - var_export( self::replaceInvisible( $expected_rendered_block ) ); - echo "\n===\n"; - $this->assertEqualHTML( $expected_rendered_block, $rendered_block, @@ -1491,26 +1481,4 @@ public function test_block_filters_for_inner_blocks() { $this->assertSame( 2, $render_block_data_callback->get_call_count() ); $this->assertSame( 2, $render_block_context_callback->get_call_count() ); } - - private static function replaceInvisible( string $s ): string { - return preg_replace_callback( - '/[\\x00-\\x1F\\x7F]/u', - static function ( array $matches ): string { - $codePoint = /** @type {number} */ ord($matches[0]); - switch ( $codePoint ) { - // U+007F DELETE -> U+2421 SYMBOL FOR DELETE - case 0x7f: - return "\u{2421}"; - - // Include a newline with newline replacement - case 0x0a: - return "\u{240A}\n"; - } - - // There's a nice Control Pictures Block at 0x2400 offset for the matched range - return mb_chr( $codePoint + 0x2400 ); - }, - $s - ); - } } From 29faaf546a2a410bf66688fad96c9559b8bdc611 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 17:48:42 +0100 Subject: [PATCH 19/21] remove block indentation --- tests/phpunit/tests/blocks/wpBlock.php | 86 +++++++++++++------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index 85fa6e7151d46..ae067e7d79bbd 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -371,13 +371,13 @@ public function data_provider_test_render_enqueues_scripts_and_styles(): array { $block_markup = <<<'HTML'
    - -
    First child
    - - - -
    Last child
    - + +
    First child
    + + + +
    Last child
    +
    HTML; @@ -390,13 +390,13 @@ public function data_provider_test_render_enqueues_scripts_and_styles(): array { 'expected_rendered_block' => <<<'HTML'
    - -
    First child
    - -

    Hello World!

    - -
    Last child
    - + +
    First child
    + +

    Hello World!

    + +
    Last child
    +
    HTML @@ -424,13 +424,13 @@ static function ( $content ) { 'expected_rendered_block' => <<<'HTML'
    - -
    First child
    - -

    Hello World!

    - -
    Last child
    - + +
    First child
    + +

    Hello World!

    + +
    Last child
    +
    HTML @@ -447,13 +447,13 @@ static function ( $content ) { 'expected_rendered_block' => <<<'HTML'
    - -
    First child
    - - - -
    Last child
    - + +
    First child
    + + + +
    Last child
    +
    HTML @@ -481,13 +481,13 @@ static function ( $enqueue, $block_name ) { 'expected_rendered_block' => <<<'HTML'
    - -
    First child
    - - - -
    Last child
    - + +
    First child
    + + + +
    Last child
    +
    HTML @@ -521,9 +521,9 @@ static function ( $content ) { 'expected_rendered_block' => <<<'HTML'
    - -

    Hello World!

    - + +

    Hello World!

    +
    HTML @@ -550,11 +550,11 @@ static function ( $content ) { 'expected_rendered_block' => <<<'HTML'
    - -
    First child
    - -

    Hello World!

    - + +
    First child
    + +

    Hello World!

    +
    HTML From 236267ac5a4b50a1ce0b22d0c1a1b7a1eb3b9816 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 20 Jan 2026 18:02:09 +0100 Subject: [PATCH 20/21] Fix block-template-utils HTML whitespace in tests --- tests/phpunit/tests/block-template-utils.php | 28 +++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php index b446ede299efa..d89aa35f06e72 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -306,10 +306,9 @@ public function data_remove_theme_attribute_in_block_template_content() { */ public function test_block_template_add_skip_link_inserts_link_and_adds_main_id_when_missing() { $template_html = '
    Content
    '; - $expected = ' - -
    Content
    - '; + $expected = + '' . + '
    Content
    '; $this->assertEqualHTML( $expected, _block_template_add_skip_link( $template_html ) ); } @@ -323,10 +322,9 @@ public function test_block_template_add_skip_link_inserts_link_and_adds_main_id_ */ public function test_block_template_add_skip_link_uses_existing_main_id() { $template_html = '
    Content
    '; - $expected = ' - -
    Content
    - '; + $expected = + '' . + '
    Content
    '; $this->assertEqualHTML( $expected, _block_template_add_skip_link( $template_html ) ); } @@ -340,10 +338,9 @@ public function test_block_template_add_skip_link_uses_existing_main_id() { */ public function test_block_template_add_skip_link_handles_boolean_main_id() { $template_html = '
    Content
    '; - $expected = ' - -
    Content
    - '; + $expected = + '' . + '
    Content
    '; $this->assertEqualHTML( $expected, _block_template_add_skip_link( $template_html ) ); } @@ -357,10 +354,9 @@ public function test_block_template_add_skip_link_handles_boolean_main_id() { */ public function test_block_template_add_skip_link_preserves_whitespace_main_id() { $template_html = '
    Content
    '; - $expected = ' - -
    Content
    - '; + $expected = + '' . + '
    Content
    '; $this->assertEqualHTML( $expected, _block_template_add_skip_link( $template_html ) ); } From f670eb844b9bbc6afed835211e628ce54889f4b4 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 21 Jan 2026 11:30:01 +0100 Subject: [PATCH 21/21] Improve comment language --- tests/phpunit/includes/build-visual-html-tree.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/includes/build-visual-html-tree.php b/tests/phpunit/includes/build-visual-html-tree.php index d2c63990a12b0..5187ea960e1e1 100644 --- a/tests/phpunit/includes/build-visual-html-tree.php +++ b/tests/phpunit/includes/build-visual-html-tree.php @@ -237,7 +237,7 @@ static function ( $a, $b ) { ++$indent_level; } - // If there are no attributes, we're done here. + // When no attributes are present, there’s nothing left to do. if ( empty( $block_attrs ) ) { break; }