From 802b33c09ae1b30e939db7efe390e6624d442125 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 15:33:48 +0200 Subject: [PATCH 01/12] Update to use the new assertEqualMarkup helper --- tests/phpunit/tests/dependencies/scripts.php | 134 ++++++++++--------- 1 file changed, 68 insertions(+), 66 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index f96539f5c3256..7f667ac5c42e1 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -41,7 +41,7 @@ public function set_up() { $GLOBALS['wp_styles'] = new WP_Styles(); $this->wp_scripts_print_translations_output = << +\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -125,7 +125,7 @@ public function test_after_inline_script_with_delayed_main_script( $strategy ) { 'id' => 'ms-isa-1-js-after', ) ); - $this->assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a deferred main script, are failing to print/execute.' ); + $this->_assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a deferred main script, are failing to print/execute.' ); } /** @@ -154,7 +154,7 @@ public function test_after_inline_script_with_blocking_main_script() { ) ); - $this->assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a blocking main script, are failing to print/execute.' ); + $this->_assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a blocking main script, are failing to print/execute.' ); } /** @@ -199,7 +199,7 @@ public function test_before_inline_scripts_with_delayed_main_script( $strategy ) ); $expected .= "\n"; - $this->assertEqualMarkup( $expected, $output, 'Inline scripts in the "before" position, that are attached to a deferred main script, are failing to print/execute.' ); + $this->_assertEqualMarkup( $expected, $output, 'Inline scripts in the "before" position, that are attached to a deferred main script, are failing to print/execute.' ); } /** @@ -217,7 +217,7 @@ public function test_loading_strategy_with_valid_async_registration() { wp_enqueue_script( 'main-script-a1', '/main-script-a1.js', array(), null, array( 'strategy' => 'async' ) ); $output = get_echo( 'wp_print_scripts' ); $expected = "\n"; - $this->assertEqualMarkup( $expected, $output, 'Scripts enqueued with an async loading strategy are failing to have the async attribute applied to the script handle when being printed.' ); + $this->_assertEqualMarkup( $expected, $output, 'Scripts enqueued with an async loading strategy are failing to have the async attribute applied to the script handle when being printed.' ); } /** @@ -240,7 +240,7 @@ public function test_delayed_dependent_with_blocking_dependency( $strategy ) { $output = get_echo( 'wp_print_scripts' ); $expected = "\n"; $expected .= ""; - $this->assertEqualMarkup( $expected, $output, 'Dependents of a blocking dependency are free to have any strategy.' ); + $this->_assertEqualMarkup( $expected, $output, 'Dependents of a blocking dependency are free to have any strategy.' ); } /** @@ -264,7 +264,7 @@ public function test_blocking_dependent_with_delayed_dependency( $strategy ) { JS; - $this->assertEqualMarkup( $expected, $output, 'Blocking dependents must force delayed dependencies to become blocking.' ); + $this->_assertEqualMarkup( $expected, $output, 'Blocking dependents must force delayed dependencies to become blocking.' ); } /** @@ -960,7 +960,7 @@ public function data_provider_to_test_various_strategy_dependency_chains() { public function test_various_strategy_dependency_chains( $set_up, $expected_markup ) { $set_up(); $actual_markup = get_echo( 'wp_print_scripts' ); - $this->assertEqualMarkup( trim( $expected_markup ), trim( $actual_markup ), "Actual markup:\n{$actual_markup}" ); + $this->_assertEqualMarkup( trim( $expected_markup ), trim( $actual_markup ), "Actual markup:\n{$actual_markup}" ); } /** @@ -1041,7 +1041,7 @@ public function test_defer_with_async_dependent() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, $output, 'Scripts registered as defer but that have dependents that are async are expected to have said dependents deferred.' ); + $this->_assertEqualMarkup( $expected, $output, 'Scripts registered as defer but that have dependents that are async are expected to have said dependents deferred.' ); } /** @@ -1113,7 +1113,7 @@ public function test_scripts_targeting_head() { $expected_header .= "\n"; $expected_header .= "\n"; - $this->assertEqualMarkup( $expected_header, $actual_header, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); + $this->_assertEqualMarkup( $expected_header, $actual_header, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); $this->assertEmpty( $actual_footer, 'Expected footer to be empty since all scripts were for head.' ); } @@ -1141,7 +1141,7 @@ public function test_scripts_targeting_footer() { $expected_footer .= "\n"; $this->assertEmpty( $actual_header, 'Expected header to be empty since all scripts targeted footer.' ); - $this->assertEqualMarkup( $expected_footer, $actual_footer, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); + $this->_assertEqualMarkup( $expected_footer, $actual_footer, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); } /** @@ -1260,7 +1260,7 @@ public function test_script_strategy_doing_it_wrong_via_register() { wp_register_script( 'invalid-strategy', '/defaults.js', array(), null, array( 'strategy' => 'random-strategy' ) ); wp_enqueue_script( 'invalid-strategy' ); - $this->assertEqualMarkup( + $this->_assertEqualMarkup( "\n", get_echo( 'wp_print_scripts' ) ); @@ -1285,7 +1285,7 @@ public function test_script_strategy_doing_it_wrong_via_add_data() { wp_script_add_data( 'invalid-strategy', 'strategy', 'random-strategy' ); wp_enqueue_script( 'invalid-strategy' ); - $this->assertEqualMarkup( + $this->_assertEqualMarkup( "\n", get_echo( 'wp_print_scripts' ) ); @@ -1306,7 +1306,7 @@ public function test_script_strategy_doing_it_wrong_via_add_data() { public function test_script_strategy_doing_it_wrong_via_enqueue() { wp_enqueue_script( 'invalid-strategy', '/defaults.js', array(), null, array( 'strategy' => 'random-strategy' ) ); - $this->assertEqualMarkup( + $this->_assertEqualMarkup( "\n", get_echo( 'wp_print_scripts' ) ); @@ -1344,7 +1344,7 @@ public function test_concatenate_with_defer_strategy() { $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' ); + $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' ); } /** @@ -1379,7 +1379,7 @@ public function test_concatenate_with_async_strategy() { $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' ); + $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' ); } /** @@ -1418,7 +1418,7 @@ public function test_concatenate_with_blocking_script_before_and_after_script_wi $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' ); + $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' ); } /** @@ -1434,7 +1434,7 @@ public function test_wp_enqueue_script_with_html5_support_does_not_contain_type_ $expected = "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1473,7 +1473,7 @@ public function test_protocols() { $expected .= "\n"; // Go! - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1516,7 +1516,7 @@ public function test_wp_script_add_data_with_data_key() { $expected .= "\n"; // Go! - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1534,7 +1534,7 @@ public function test_wp_script_add_data_with_conditional_key() { $expected = "\n"; // Go! - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1555,7 +1555,7 @@ public function test_wp_script_add_data_with_data_and_conditional_keys() { $expected = str_replace( "'", '"', $expected ); // Go! - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1573,10 +1573,10 @@ public function test_wp_script_add_data_with_invalid_key() { $expected = "\n"; // Go! - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. - $this->assertEqualMarkup( '', get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( '', get_echo( 'wp_print_scripts' ) ); } /** @@ -1602,7 +1602,7 @@ public function test_wp_register_script_with_handle_without_source() { wp_enqueue_script( 'handle-three' ); - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1690,8 +1690,8 @@ public function test_wp_register_script_with_dependencies_in_head_and_footer() { $expected_header .= "\n"; $expected_footer = "\n"; - $this->assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); - $this->assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); + $this->_assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); + $this->_assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); } /** @@ -1711,8 +1711,8 @@ public function test_wp_register_script_with_dependencies_in_head_and_footer_in_ $expected_footer = "\n"; $expected_footer .= "\n"; - $this->assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); - $this->assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); + $this->_assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); + $this->_assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); } /** @@ -1742,8 +1742,8 @@ public function test_wp_register_script_with_dependencies_in_head_and_footer_in_ $expected_footer .= "\n"; $expected_footer .= "\n"; - $this->assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); - $this->assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); + $this->_assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); + $this->_assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); } /** @@ -1773,7 +1773,7 @@ public function test_wp_add_inline_script_before() { $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1786,7 +1786,7 @@ public function test_wp_add_inline_script_after() { $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1801,7 +1801,7 @@ public function test_wp_add_inline_script_before_and_after() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1814,7 +1814,7 @@ public function test_wp_add_inline_script_before_for_handle_without_source() { $expected = "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1827,7 +1827,7 @@ public function test_wp_add_inline_script_after_for_handle_without_source() { $expected = "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1842,7 +1842,7 @@ public function test_wp_add_inline_script_before_and_after_for_handle_without_so $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1859,7 +1859,7 @@ public function test_wp_add_inline_script_multiple() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1876,7 +1876,7 @@ public function test_wp_add_inline_script_localized_data_is_added_first() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1901,7 +1901,7 @@ public function test_wp_add_inline_script_before_with_concat() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1924,7 +1924,7 @@ public function test_wp_add_inline_script_before_with_concat2() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1951,7 +1951,7 @@ public function test_wp_add_inline_script_after_with_concat() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1982,7 +1982,7 @@ public function test_wp_add_inline_script_after_and_before_with_concat_and_condi wp_script_add_data( 'test-example', 'conditional', 'gte IE 9' ); $this->assertSame( $expected_localized, get_echo( 'wp_print_scripts' ) ); - $this->assertEqualMarkup( $expected, $wp_scripts->print_html ); + $this->_assertEqualMarkup( $expected, $wp_scripts->print_html ); $this->assertTrue( $wp_scripts->do_concat ); } @@ -2007,7 +2007,7 @@ public function test_wp_add_inline_script_after_with_concat_and_core_dependency( wp_print_scripts(); $print_scripts = get_echo( '_print_scripts' ); - $this->assertEqualMarkup( $expected, $print_scripts ); + $this->_assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2034,7 +2034,7 @@ public function test_wp_add_inline_script_after_with_concat_and_conditional_and_ wp_print_scripts(); $print_scripts = get_echo( '_print_scripts' ); - $this->assertEqualMarkup( $expected, $print_scripts ); + $this->_assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2059,7 +2059,7 @@ public function test_wp_add_inline_script_before_with_concat_and_core_dependency wp_print_scripts(); $print_scripts = get_echo( '_print_scripts' ); - $this->assertEqualMarkup( $expected, $print_scripts ); + $this->_assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2109,7 +2109,7 @@ public function test_wp_add_inline_script_before_after_concat_with_core_dependen $print_scripts // Printed scripts. ); - $this->assertEqualMarkup( $expected, $print_scripts ); + $this->_assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2142,7 +2142,7 @@ public function test_wp_add_inline_script_customize_dependency() { $tail = substr( $print_scripts, strrpos( $print_scripts, '\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2189,7 +2189,7 @@ public function test_wp_add_inline_script_before_third_core_script_prints_two_co $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2287,13 +2287,13 @@ public function test_get_inline_script( $position, $inline_scripts, $delayed, $e $this->assertSame( $expected_data, $wp_scripts->get_inline_script_data( $handle, $position ) ); $this->assertSame( $expected_data, $wp_scripts->print_inline_script( $handle, $position, false ) ); - $this->assertEqualMarkup( + $this->_assertEqualMarkup( $expected_tag, $wp_scripts->get_inline_script_tag( $handle, $position ) ); ob_start(); $output = $wp_scripts->print_inline_script( $handle, $position, true ); - $this->assertEqualMarkup( $expected_tag, ob_get_clean() ); + $this->_assertEqualMarkup( $expected_tag, ob_get_clean() ); $this->assertEquals( $expected_data, $output ); } @@ -2321,7 +2321,7 @@ public function test_wp_set_script_translations() { ); $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2348,7 +2348,7 @@ public function test_wp_set_script_translations_for_plugin() { ); $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2375,7 +2375,7 @@ public function test_wp_set_script_translations_for_theme() { ); $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2402,7 +2402,7 @@ public function test_wp_set_script_translations_with_handle_file() { ); $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2432,7 +2432,7 @@ public function test_wp_set_script_translations_when_translation_file_does_not_e $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2461,7 +2461,7 @@ public function test_wp_set_script_translations_after_register() { ); $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2491,7 +2491,7 @@ public function test_wp_set_script_translations_dependency() { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2880,7 +2880,7 @@ public function test_wp_localize_script_data_formats( $l10n_data, $expected ) { $expected = "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2945,7 +2945,7 @@ static function () { $expected .= "\n"; $expected .= "\n"; - $this->assertEqualMarkup( $expected, $print_scripts ); + $this->_assertEqualMarkup( $expected, $print_scripts ); } /** @@ -3017,13 +3017,15 @@ protected function parse_markup_fragment( $markup ) { /** * Assert markup is equal after normalizing script tags. * - * @todo Retire in favor of WP_UnitTestCase::assertEqualMarkup(). + * @todo Retire in favor of WP_UnitTestCase::_assertEqualMarkup(). * * @param string $expected Expected markup. * @param string $actual Actual markup. * @param string $message Message. */ - protected function assertEqualMarkup( $expected, $actual, $message = '' ) { + protected function _assertEqualMarkup( $expected, $actual, $message = '' ) { + $this->assertEqualMarkup( $expected, $actual, '', $message ); + return; $expected_dom = $this->parse_markup_fragment( $expected ); $actual_dom = $this->parse_markup_fragment( $actual ); foreach ( array( $expected_dom, $actual_dom ) as $dom ) { @@ -3102,8 +3104,8 @@ public function test_wp_scripts_move_to_footer( $set_up, $expected_header, $expe wp_scripts()->do_footer_items(); $footer = ob_get_clean(); - $this->assertEqualMarkup( $expected_header, $header, 'Expected header script markup to match.' ); - $this->assertEqualMarkup( $expected_footer, $footer, 'Expected footer script markup to match.' ); + $this->_assertEqualMarkup( $expected_header, $header, 'Expected header script markup to match.' ); + $this->_assertEqualMarkup( $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.' ); $this->assertEquals( $expected_groups, wp_scripts()->groups, 'Expected groups to match.' ); } From 3fbc667760230284c7b18b4e8507aa909a8d7102 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 15:48:06 +0200 Subject: [PATCH 02/12] Rename test helper to assertEqualMarkup --- tests/phpunit/includes/abstract-testcase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 150ff1d7bfc91..f2cfeeae99fb8 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1199,7 +1199,7 @@ public function assertQueryTrue( ...$prop ) { * Set to null to parse a full HTML document. * @param string|null $message Optional. The assertion error message. */ - public function assertEqualBlockMarkup( string $expected, string $actual, ?string $fragment_context = '', $message = 'HTML markup was not equivalent.' ): void { + public function assertEqualMarkup( string $expected, string $actual, ?string $fragment_context = '', $message = 'HTML markup was not equivalent.' ): void { try { $tree_expected = build_equivalent_html_semantic_tree( $expected, $fragment_context ); $tree_actual = build_equivalent_html_semantic_tree( $actual, $fragment_context ); From 6ec1a670e15f7a9d40b9c830a8afaf57f85a60d8 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 15:49:38 +0200 Subject: [PATCH 03/12] Fix script async/defer strategy expectation to match printed scripts --- tests/phpunit/tests/dependencies/scripts.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 7f667ac5c42e1..25151c23170ad 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -187,9 +187,9 @@ public function test_before_inline_scripts_with_delayed_main_script( $strategy ) 'id' => 'ds-i1-1-js-before', ) ); - $expected .= "\n"; - $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; + $expected .= "\n"; + $expected .= "\n"; $expected .= wp_get_inline_script_tag( 'console.log("before last");', array( @@ -197,7 +197,7 @@ public function test_before_inline_scripts_with_delayed_main_script( $strategy ) 'type' => 'text/javascript', ) ); - $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, $output, 'Inline scripts in the "before" position, that are attached to a deferred main script, are failing to print/execute.' ); } @@ -216,7 +216,7 @@ public function test_loading_strategy_with_valid_async_registration() { // No dependents, No dependencies then async. wp_enqueue_script( 'main-script-a1', '/main-script-a1.js', array(), null, array( 'strategy' => 'async' ) ); $output = get_echo( 'wp_print_scripts' ); - $expected = "\n"; + $expected = "\n"; $this->_assertEqualMarkup( $expected, $output, 'Scripts enqueued with an async loading strategy are failing to have the async attribute applied to the script handle when being printed.' ); } @@ -238,8 +238,8 @@ public function test_delayed_dependent_with_blocking_dependency( $strategy ) { wp_enqueue_script( 'dependency-script-a2', '/dependency-script-a2.js', array(), null ); 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"; + $expected .= ""; $this->_assertEqualMarkup( $expected, $output, 'Dependents of a blocking dependency are free to have any strategy.' ); } From 11a62c7a1180dbc6fa5e9c101206706c5bef79b8 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 16:10:29 +0200 Subject: [PATCH 04/12] Add CDATA inline script wrappers where they appear in markup --- tests/phpunit/tests/dependencies/scripts.php | 104 +++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 25151c23170ad..b57e3ed391242 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -511,18 +511,26 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -548,25 +556,37 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -584,18 +604,26 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -613,18 +641,26 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -645,17 +681,25 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -679,25 +723,37 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -720,17 +776,25 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -751,25 +815,37 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -790,25 +866,37 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -826,18 +914,26 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML , @@ -851,7 +947,9 @@ public function data_provider_to_test_various_strategy_dependency_chains() { }, 'expected_markup' => << +/* */ HTML @@ -867,7 +965,9 @@ public function data_provider_to_test_various_strategy_dependency_chains() { 'expected_markup' => << HTML , @@ -912,11 +1012,15 @@ public function data_provider_to_test_various_strategy_dependency_chains() { HTML , From d7faf356677701bf14cbff794d18cf65f02faffd Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 16:10:57 +0200 Subject: [PATCH 05/12] FIXME: Skip an inaccurate test --- tests/phpunit/tests/dependencies/scripts.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index b57e3ed391242..3ec359ca69bd5 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -951,7 +951,7 @@ public function data_provider_to_test_various_strategy_dependency_chains() { scriptEventLog.push( "defer-with-before-inline: before inline" ) /* ]]> */ - + HTML , ), @@ -1538,6 +1538,7 @@ public function test_wp_enqueue_script_with_html5_support_does_not_contain_type_ $expected = "\n"; + $this->markTestSkipped( 'This test has a bug. The output does contain the type.' ); $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } From 0ea3520829193fdfcd5a354bd53e31e92e92e8ac Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 16:12:45 +0200 Subject: [PATCH 06/12] Adjust expected output to use attributes as generated The generated HTML produces async="async" or defer="defer". Match this in the expected HTML. --- tests/phpunit/tests/dependencies/scripts.php | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 3ec359ca69bd5..37b972c7105a0 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -983,9 +983,9 @@ public function data_provider_to_test_various_strategy_dependency_chains() { wp_enqueue_script( 'theme-functions', 'https://example.com/theme-functions.js', array( 'jquery' ), null, array( 'strategy' => 'defer' ) ); }, 'expected_markup' => << - - + + + HTML , ), @@ -1039,9 +1039,9 @@ public function data_provider_to_test_various_strategy_dependency_chains() { $this->enqueue_test_script( 'defer-dependent-of-async-aliases', 'defer', array( $alias_handle ) ); }, 'expected_markup' => << - - + + + HTML , ), @@ -1140,10 +1140,10 @@ public function test_defer_with_async_dependent() { wp_enqueue_script( 'dependent-script-d4-2', '/dependent-script-d4-2.js', array( 'dependent-script-d4-1' ), null, array( 'strategy' => 'async' ) ); 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 .= "\n"; - $expected .= "\n"; - $expected .= "\n"; + $expected = "\n"; + $expected .= "\n"; + $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, $output, 'Scripts registered as defer but that have dependents that are async are expected to have said dependents deferred.' ); } @@ -1446,7 +1446,7 @@ public function test_concatenate_with_defer_strategy() { $concatenate_scripts = $old_value; $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' ); } @@ -1481,7 +1481,7 @@ public function test_concatenate_with_async_strategy() { $concatenate_scripts = $old_value; $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' ); } @@ -1520,7 +1520,7 @@ public function test_concatenate_with_blocking_script_before_and_after_script_wi $concatenate_scripts = $old_value; $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' ); } From f47af78482fbc7836c5102c761876bf0c7c0de96 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 16:20:24 +0200 Subject: [PATCH 07/12] Add html5 support to a test that expects html5 support --- tests/phpunit/tests/dependencies/scripts.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 37b972c7105a0..7e9cdf8977129 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -1531,6 +1531,8 @@ public function test_concatenate_with_blocking_script_before_and_after_script_wi public function test_wp_enqueue_script_with_html5_support_does_not_contain_type_attribute() { global $wp_version; + $this->add_html5_script_theme_support(); + $GLOBALS['wp_scripts'] = new WP_Scripts(); $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); @@ -1538,7 +1540,6 @@ public function test_wp_enqueue_script_with_html5_support_does_not_contain_type_ $expected = "\n"; - $this->markTestSkipped( 'This test has a bug. The output does contain the type.' ); $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } From 1740a9092f2f9c2efc6c00fc73a55567ea1cd98c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 16:27:42 +0200 Subject: [PATCH 08/12] Script quotes in IE7 conditional _comments_ produce semantically _different_ HTML --- 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 7e9cdf8977129..cf0de99bdbefd 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -1637,7 +1637,7 @@ public function test_wp_script_add_data_with_conditional_key() { // Enqueue and add conditional comments. wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null ); wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' ); - $expected = "\n"; + $expected = "\n"; // Go! $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); From 03c58ab4a4b42b913bdfc01b27138183b6ab3e3d Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 16:43:39 +0200 Subject: [PATCH 09/12] Revert irrelevant change --- 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 cf0de99bdbefd..c7bc8d97b8ebc 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -41,7 +41,7 @@ public function set_up() { $GLOBALS['wp_styles'] = new WP_Styles(); $this->wp_scripts_print_translations_output = << +\n"; + $expected = << +/* */ + +HTML; $expected .= "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); @@ -1890,7 +1896,13 @@ public function test_wp_add_inline_script_after() { wp_add_inline_script( 'test-example', 'console.log("after");' ); $expected = "\n"; - $expected .= "\n"; + $expected .= << +/* */ + +HTML; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } @@ -1903,9 +1915,9 @@ public function test_wp_add_inline_script_before_and_after() { wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); wp_add_inline_script( 'test-example', 'console.log("after");' ); - $expected = "\n"; + $expected = "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } @@ -1918,7 +1930,7 @@ public function test_wp_add_inline_script_before_for_handle_without_source() { wp_enqueue_script( 'test-example' ); wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); - $expected = "\n"; + $expected = "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } @@ -1931,7 +1943,7 @@ public function test_wp_add_inline_script_after_for_handle_without_source() { wp_enqueue_script( 'test-example' ); wp_add_inline_script( 'test-example', 'console.log("after");' ); - $expected = "\n"; + $expected = "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } @@ -1945,8 +1957,8 @@ public function test_wp_add_inline_script_before_and_after_for_handle_without_so wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); wp_add_inline_script( 'test-example', 'console.log("after");' ); - $expected = "\n"; - $expected .= "\n"; + $expected = "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } @@ -1961,9 +1973,9 @@ public function test_wp_add_inline_script_multiple() { wp_add_inline_script( 'test-example', 'console.log("after");' ); wp_add_inline_script( 'test-example', 'console.log("after");' ); - $expected = "\n"; + $expected = "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } @@ -1978,9 +1990,9 @@ public function test_wp_add_inline_script_localized_data_is_added_first() { wp_add_inline_script( 'test-example', 'console.log("after");' ); $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } @@ -2001,9 +2013,9 @@ public function test_wp_add_inline_script_before_with_concat() { wp_add_inline_script( 'one', 'console.log("before one");', 'before' ); wp_add_inline_script( 'two', 'console.log("before two");', 'before' ); - $expected = "\n"; + $expected = "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; @@ -2025,7 +2037,7 @@ public function test_wp_add_inline_script_before_with_concat2() { wp_add_inline_script( 'one', 'console.log("before one");', 'before' ); - $expected = "\n"; + $expected = "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; @@ -2052,9 +2064,9 @@ public function test_wp_add_inline_script_after_with_concat() { $expected = "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); @@ -2075,9 +2087,9 @@ public function test_wp_add_inline_script_after_and_before_with_concat_and_condi $expected_localized = str_replace( "'", '"', $expected_localized ); $expected = "\n"; $expected = str_replace( "'", '"', $expected ); @@ -2105,7 +2117,7 @@ public function test_wp_add_inline_script_after_with_concat_and_core_dependency( $expected = "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); wp_add_inline_script( 'test-example', 'console.log("after");' ); @@ -2129,8 +2141,8 @@ public function test_wp_add_inline_script_after_with_concat_and_conditional_and_ $expected = "\n"; $expected .= "\n"; wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); @@ -2156,7 +2168,7 @@ public function test_wp_add_inline_script_before_with_concat_and_core_dependency $wp_scripts->do_concat = true; $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); @@ -2181,15 +2193,17 @@ public function test_wp_add_inline_script_before_after_concat_with_core_dependen $wp_scripts->do_concat = true; $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; - $expected .= "\n"; + $expected .= "\n"; wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); @@ -2232,7 +2246,9 @@ public function test_wp_add_inline_script_customize_dependency() { $expected_tail = "\n"; $expected_tail .= "\n"; $handle = 'customize-dependency'; @@ -2267,7 +2283,7 @@ public function test_wp_add_inline_script_after_for_core_scripts_with_concat_is_ wp_enqueue_script( 'four', '/wp-includes/js/script4.js' ); $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; @@ -2291,7 +2307,7 @@ public function test_wp_add_inline_script_before_third_core_script_prints_two_co wp_enqueue_script( 'four', '/wp-includes/js/script4.js' ); $expected = "\n"; - $expected .= "\n"; + $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; @@ -2312,7 +2328,7 @@ public function data_provider_to_test_get_inline_script() { ), 'delayed' => false, 'expected_data' => '/*before foo 1*/', - 'expected_tag' => "\n", + 'expected_tag' => "\n", ), 'after-blocking' => array( 'position' => 'after', @@ -2322,7 +2338,7 @@ public function data_provider_to_test_get_inline_script() { ), 'delayed' => false, 'expected_data' => "/*after foo 1*/\n/*after foo 2*/", - 'expected_tag' => "\n", + 'expected_tag' => "\n", ), 'before-delayed' => array( 'position' => 'before', @@ -2331,7 +2347,7 @@ public function data_provider_to_test_get_inline_script() { ), 'delayed' => true, 'expected_data' => '/*before foo 1*/', - 'expected_tag' => "\n", + 'expected_tag' => "\n", ), 'after-delayed' => array( 'position' => 'after', @@ -2341,7 +2357,7 @@ public function data_provider_to_test_get_inline_script() { ), 'delayed' => true, 'expected_data' => "/*after foo 1*/\n/*after foo 2*/", - 'expected_tag' => "\n", + 'expected_tag' => "\n", ), ); } From f2941255d739740cf51f2232201fbc62891d3b8b Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 18:32:02 +0200 Subject: [PATCH 11/12] Remove scripts specific assertEqualMarkup implementation --- tests/phpunit/tests/dependencies/scripts.php | 177 +++++++------------ 1 file changed, 63 insertions(+), 114 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index d10a5d87f42e7..03d118bca1045 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -79,7 +79,7 @@ public function test_wp_enqueue_script() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -125,7 +125,7 @@ public function test_after_inline_script_with_delayed_main_script( $strategy ) { 'id' => 'ms-isa-1-js-after', ) ); - $this->_assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a deferred main script, are failing to print/execute.' ); + $this->assertEqualMarkup( $expected, $output, '', 'Inline scripts in the "after" position, that are attached to a deferred main script, are failing to print/execute.' ); } /** @@ -154,7 +154,7 @@ public function test_after_inline_script_with_blocking_main_script() { ) ); - $this->_assertEqualMarkup( $expected, $output, 'Inline scripts in the "after" position, that are attached to a blocking main script, are failing to print/execute.' ); + $this->assertEqualMarkup( $expected, $output, '', 'Inline scripts in the "after" position, that are attached to a blocking main script, are failing to print/execute.' ); } /** @@ -199,7 +199,7 @@ public function test_before_inline_scripts_with_delayed_main_script( $strategy ) ); $expected .= "\n"; - $this->_assertEqualMarkup( $expected, $output, 'Inline scripts in the "before" position, that are attached to a deferred main script, are failing to print/execute.' ); + $this->assertEqualMarkup( $expected, $output, '', 'Inline scripts in the "before" position, that are attached to a deferred main script, are failing to print/execute.' ); } /** @@ -217,7 +217,7 @@ public function test_loading_strategy_with_valid_async_registration() { wp_enqueue_script( 'main-script-a1', '/main-script-a1.js', array(), null, array( 'strategy' => 'async' ) ); $output = get_echo( 'wp_print_scripts' ); $expected = "\n"; - $this->_assertEqualMarkup( $expected, $output, 'Scripts enqueued with an async loading strategy are failing to have the async attribute applied to the script handle when being printed.' ); + $this->assertEqualMarkup( $expected, $output, '', 'Scripts enqueued with an async loading strategy are failing to have the async attribute applied to the script handle when being printed.' ); } /** @@ -240,7 +240,7 @@ public function test_delayed_dependent_with_blocking_dependency( $strategy ) { $output = get_echo( 'wp_print_scripts' ); $expected = "\n"; $expected .= ""; - $this->_assertEqualMarkup( $expected, $output, 'Dependents of a blocking dependency are free to have any strategy.' ); + $this->assertEqualMarkup( $expected, $output, '', 'Dependents of a blocking dependency are free to have any strategy.' ); } /** @@ -264,7 +264,7 @@ public function test_blocking_dependent_with_delayed_dependency( $strategy ) { JS; - $this->_assertEqualMarkup( $expected, $output, 'Blocking dependents must force delayed dependencies to become blocking.' ); + $this->assertEqualMarkup( $expected, $output, '', 'Blocking dependents must force delayed dependencies to become blocking.' ); } /** @@ -1064,7 +1064,7 @@ public function data_provider_to_test_various_strategy_dependency_chains() { public function test_various_strategy_dependency_chains( $set_up, $expected_markup ) { $set_up(); $actual_markup = get_echo( 'wp_print_scripts' ); - $this->_assertEqualMarkup( trim( $expected_markup ), trim( $actual_markup ), "Actual markup:\n{$actual_markup}" ); + $this->assertEqualMarkup( trim( $expected_markup ), trim( $actual_markup ), '', "Actual markup:\n{$actual_markup}" ); } /** @@ -1145,7 +1145,7 @@ public function test_defer_with_async_dependent() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, $output, 'Scripts registered as defer but that have dependents that are async are expected to have said dependents deferred.' ); + $this->assertEqualMarkup( $expected, $output, '', 'Scripts registered as defer but that have dependents that are async are expected to have said dependents deferred.' ); } /** @@ -1217,7 +1217,7 @@ public function test_scripts_targeting_head() { $expected_header .= "\n"; $expected_header .= "\n"; - $this->_assertEqualMarkup( $expected_header, $actual_header, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); + $this->assertEqualMarkup( $expected_header, $actual_header, '', 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); $this->assertEmpty( $actual_footer, 'Expected footer to be empty since all scripts were for head.' ); } @@ -1245,7 +1245,7 @@ public function test_scripts_targeting_footer() { $expected_footer .= "\n"; $this->assertEmpty( $actual_header, 'Expected header to be empty since all scripts targeted footer.' ); - $this->_assertEqualMarkup( $expected_footer, $actual_footer, 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); + $this->assertEqualMarkup( $expected_footer, $actual_footer, '', 'Scripts registered/enqueued using the older $in_footer parameter or the newer $args parameter should have the same outcome.' ); } /** @@ -1364,7 +1364,7 @@ public function test_script_strategy_doing_it_wrong_via_register() { wp_register_script( 'invalid-strategy', '/defaults.js', array(), null, array( 'strategy' => 'random-strategy' ) ); wp_enqueue_script( 'invalid-strategy' ); - $this->_assertEqualMarkup( + $this->assertEqualMarkup( "\n", get_echo( 'wp_print_scripts' ) ); @@ -1389,7 +1389,7 @@ public function test_script_strategy_doing_it_wrong_via_add_data() { wp_script_add_data( 'invalid-strategy', 'strategy', 'random-strategy' ); wp_enqueue_script( 'invalid-strategy' ); - $this->_assertEqualMarkup( + $this->assertEqualMarkup( "\n", get_echo( 'wp_print_scripts' ) ); @@ -1410,7 +1410,7 @@ public function test_script_strategy_doing_it_wrong_via_add_data() { public function test_script_strategy_doing_it_wrong_via_enqueue() { wp_enqueue_script( 'invalid-strategy', '/defaults.js', array(), null, array( 'strategy' => 'random-strategy' ) ); - $this->_assertEqualMarkup( + $this->assertEqualMarkup( "\n", get_echo( 'wp_print_scripts' ) ); @@ -1448,7 +1448,7 @@ public function test_concatenate_with_defer_strategy() { $expected = "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' ); + $this->assertEqualMarkup( $expected, $print_scripts, '', 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' ); } /** @@ -1483,7 +1483,7 @@ public function test_concatenate_with_async_strategy() { $expected = "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' ); + $this->assertEqualMarkup( $expected, $print_scripts, '', 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' ); } /** @@ -1522,7 +1522,7 @@ public function test_concatenate_with_blocking_script_before_and_after_script_wi $expected = "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, $print_scripts, 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' ); + $this->assertEqualMarkup( $expected, $print_scripts, '', 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' ); } /** @@ -1540,7 +1540,7 @@ public function test_wp_enqueue_script_with_html5_support_does_not_contain_type_ $expected = "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1579,7 +1579,7 @@ public function test_protocols() { $expected .= "\n"; // Go! - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1622,7 +1622,7 @@ public function test_wp_script_add_data_with_data_key() { $expected .= "\n"; // Go! - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1640,7 +1640,7 @@ public function test_wp_script_add_data_with_conditional_key() { $expected = "\n"; // Go! - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1661,7 +1661,7 @@ public function test_wp_script_add_data_with_data_and_conditional_keys() { $expected = str_replace( "'", '"', $expected ); // Go! - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. $this->assertSame( '', get_echo( 'wp_print_scripts' ) ); @@ -1679,10 +1679,10 @@ public function test_wp_script_add_data_with_invalid_key() { $expected = "\n"; // Go! - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); // No scripts left to print. - $this->_assertEqualMarkup( '', get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( '', get_echo( 'wp_print_scripts' ) ); } /** @@ -1708,7 +1708,7 @@ public function test_wp_register_script_with_handle_without_source() { wp_enqueue_script( 'handle-three' ); - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1796,8 +1796,8 @@ public function test_wp_register_script_with_dependencies_in_head_and_footer() { $expected_header .= "\n"; $expected_footer = "\n"; - $this->_assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); - $this->_assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); + $this->assertEqualMarkup( $expected_header, $header, '', 'Expected same header markup.' ); + $this->assertEqualMarkup( $expected_footer, $footer, '', 'Expected same footer markup.' ); } /** @@ -1817,8 +1817,8 @@ public function test_wp_register_script_with_dependencies_in_head_and_footer_in_ $expected_footer = "\n"; $expected_footer .= "\n"; - $this->_assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); - $this->_assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); + $this->assertEqualMarkup( $expected_header, $header, '', 'Expected same header markup.' ); + $this->assertEqualMarkup( $expected_footer, $footer, '', 'Expected same footer markup.' ); } /** @@ -1848,8 +1848,8 @@ public function test_wp_register_script_with_dependencies_in_head_and_footer_in_ $expected_footer .= "\n"; $expected_footer .= "\n"; - $this->_assertEqualMarkup( $expected_header, $header, 'Expected same header markup.' ); - $this->_assertEqualMarkup( $expected_footer, $footer, 'Expected same footer markup.' ); + $this->assertEqualMarkup( $expected_header, $header, '', 'Expected same header markup.' ); + $this->assertEqualMarkup( $expected_footer, $footer, '', 'Expected same footer markup.' ); } /** @@ -1885,7 +1885,7 @@ public function test_wp_add_inline_script_before() { HTML; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1904,7 +1904,7 @@ public function test_wp_add_inline_script_after() { HTML; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1919,7 +1919,7 @@ public function test_wp_add_inline_script_before_and_after() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1932,7 +1932,7 @@ public function test_wp_add_inline_script_before_for_handle_without_source() { $expected = "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1945,7 +1945,7 @@ public function test_wp_add_inline_script_after_for_handle_without_source() { $expected = "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1960,7 +1960,7 @@ public function test_wp_add_inline_script_before_and_after_for_handle_without_so $expected = "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1977,7 +1977,7 @@ public function test_wp_add_inline_script_multiple() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -1994,7 +1994,7 @@ public function test_wp_add_inline_script_localized_data_is_added_first() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2019,7 +2019,7 @@ public function test_wp_add_inline_script_before_with_concat() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2042,7 +2042,7 @@ public function test_wp_add_inline_script_before_with_concat2() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2069,7 +2069,7 @@ public function test_wp_add_inline_script_after_with_concat() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2100,7 +2100,7 @@ public function test_wp_add_inline_script_after_and_before_with_concat_and_condi wp_script_add_data( 'test-example', 'conditional', 'gte IE 9' ); $this->assertSame( $expected_localized, get_echo( 'wp_print_scripts' ) ); - $this->_assertEqualMarkup( $expected, $wp_scripts->print_html ); + $this->assertEqualMarkup( $expected, $wp_scripts->print_html ); $this->assertTrue( $wp_scripts->do_concat ); } @@ -2125,7 +2125,7 @@ public function test_wp_add_inline_script_after_with_concat_and_core_dependency( wp_print_scripts(); $print_scripts = get_echo( '_print_scripts' ); - $this->_assertEqualMarkup( $expected, $print_scripts ); + $this->assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2152,7 +2152,7 @@ public function test_wp_add_inline_script_after_with_concat_and_conditional_and_ wp_print_scripts(); $print_scripts = get_echo( '_print_scripts' ); - $this->_assertEqualMarkup( $expected, $print_scripts ); + $this->assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2177,7 +2177,7 @@ public function test_wp_add_inline_script_before_with_concat_and_core_dependency wp_print_scripts(); $print_scripts = get_echo( '_print_scripts' ); - $this->_assertEqualMarkup( $expected, $print_scripts ); + $this->assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2229,7 +2229,7 @@ public function test_wp_add_inline_script_before_after_concat_with_core_dependen $print_scripts // Printed scripts. ); - $this->_assertEqualMarkup( $expected, $print_scripts ); + $this->assertEqualMarkup( $expected, $print_scripts ); } /** @@ -2264,7 +2264,7 @@ public function test_wp_add_inline_script_customize_dependency() { $tail = substr( $print_scripts, strrpos( $print_scripts, '\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2311,7 +2311,7 @@ public function test_wp_add_inline_script_before_third_core_script_prints_two_co $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2409,13 +2409,13 @@ public function test_get_inline_script( $position, $inline_scripts, $delayed, $e $this->assertSame( $expected_data, $wp_scripts->get_inline_script_data( $handle, $position ) ); $this->assertSame( $expected_data, $wp_scripts->print_inline_script( $handle, $position, false ) ); - $this->_assertEqualMarkup( + $this->assertEqualMarkup( $expected_tag, $wp_scripts->get_inline_script_tag( $handle, $position ) ); ob_start(); $output = $wp_scripts->print_inline_script( $handle, $position, true ); - $this->_assertEqualMarkup( $expected_tag, ob_get_clean() ); + $this->assertEqualMarkup( $expected_tag, ob_get_clean() ); $this->assertEquals( $expected_data, $output ); } @@ -2443,7 +2443,7 @@ public function test_wp_set_script_translations() { ); $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2470,7 +2470,7 @@ public function test_wp_set_script_translations_for_plugin() { ); $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2497,7 +2497,7 @@ public function test_wp_set_script_translations_for_theme() { ); $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2524,7 +2524,7 @@ public function test_wp_set_script_translations_with_handle_file() { ); $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2554,7 +2554,7 @@ public function test_wp_set_script_translations_when_translation_file_does_not_e $expected = "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2583,7 +2583,7 @@ public function test_wp_set_script_translations_after_register() { ); $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -2613,7 +2613,7 @@ public function test_wp_set_script_translations_dependency() { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -3002,7 +3002,7 @@ public function test_wp_localize_script_data_formats( $l10n_data, $expected ) { $expected = "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); + $this->assertEqualMarkup( $expected, get_echo( 'wp_print_scripts' ) ); } /** @@ -3067,7 +3067,7 @@ static function () { $expected .= "\n"; $expected .= "\n"; - $this->_assertEqualMarkup( $expected, $print_scripts ); + $this->assertEqualMarkup( $expected, $print_scripts ); } /** @@ -3136,57 +3136,6 @@ protected function parse_markup_fragment( $markup ) { return $dom; } - /** - * Assert markup is equal after normalizing script tags. - * - * @todo Retire in favor of WP_UnitTestCase::_assertEqualMarkup(). - * - * @param string $expected Expected markup. - * @param string $actual Actual markup. - * @param string $message Message. - */ - protected function _assertEqualMarkup( $expected, $actual, $message = '' ) { - $this->assertEqualMarkup( $expected, $actual, '', $message ); - return; - $expected_dom = $this->parse_markup_fragment( $expected ); - $actual_dom = $this->parse_markup_fragment( $actual ); - foreach ( array( $expected_dom, $actual_dom ) as $dom ) { - $xpath = new DOMXPath( $dom ); - /** @var DOMElement $script */ - - // Normalize type attribute. When missing, it defaults to text/javascript. - foreach ( $xpath->query( '//script[ not( @type ) ]' ) as $script ) { - $script->setAttribute( 'type', 'text/javascript' ); - } - - // Normalize script contents to remove CDATA wrapper. - foreach ( $xpath->query( '//script[ contains( text(), "textContent = str_replace( - array( - "/* */", - ), - '', - $script->textContent - ); - } - - // Normalize XHTML-compatible boolean attributes to HTML5 ones. - foreach ( array( 'async', 'defer' ) as $attribute ) { - foreach ( iterator_to_array( $xpath->query( "//script[ @{$attribute} = '{$attribute}' ]" ) ) as $script ) { - $script->removeAttribute( $attribute ); - $script->setAttributeNode( $dom->createAttribute( $attribute ) ); - } - } - } - - $this->assertEquals( - $expected_dom->getElementsByTagName( 'body' )->item( 0 ), - $actual_dom->getElementsByTagName( 'body' )->item( 0 ), - $message - ); - } - /** * Adds html5 script theme support. */ @@ -3226,8 +3175,8 @@ public function test_wp_scripts_move_to_footer( $set_up, $expected_header, $expe wp_scripts()->do_footer_items(); $footer = ob_get_clean(); - $this->_assertEqualMarkup( $expected_header, $header, 'Expected header script markup to match.' ); - $this->_assertEqualMarkup( $expected_footer, $footer, 'Expected footer script markup to match.' ); + $this->assertEqualMarkup( $expected_header, $header, '', 'Expected header script markup to match.' ); + $this->assertEqualMarkup( $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.' ); $this->assertEquals( $expected_groups, wp_scripts()->groups, 'Expected groups to match.' ); } From e97bfbb56a56ecb2f5491a69025ca5ab7c6fea21 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 5 Jun 2025 18:34:04 +0200 Subject: [PATCH 12/12] Use more consistent code backticks in docblock --- tests/phpunit/includes/abstract-testcase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index f2cfeeae99fb8..096230063cc12 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1195,8 +1195,8 @@ public function assertQueryTrue( ...$prop ) { * @param string $actual The actual HTML. * @param string|null $fragment_context Optional. The fragment context, for example "" expected HTML * must occur within "" fragment context. Default "". - * Only `` or `null` are supported at this time. - * Set to null to parse a full HTML document. + * Only "" or `null` are supported at this time. + * Set to `null` to parse a full HTML document. * @param string|null $message Optional. The assertion error message. */ public function assertEqualMarkup( string $expected, string $actual, ?string $fragment_context = '', $message = 'HTML markup was not equivalent.' ): void {