From 27063cf13f8147ee7058ab8ae1af5cd7e1e76a3d Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 13 Jan 2026 14:33:09 +0100 Subject: [PATCH] Use assertEqualHTML for semantic HTML comparison --- tests/phpunit/tests/dependencies/scripts.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index ed742f4040133..8cca03010cad2 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -333,8 +333,8 @@ public function test_delayed_dependent_with_blocking_dependency_not_enqueued( $s // This dependent is registered but not enqueued, so it should not factor into the eligible loading strategy. wp_register_script( 'dependent-script-a4', '/dependent-script-a4.js', array( 'main-script-a4' ), null ); $output = get_echo( 'wp_print_scripts' ); - $expected = str_replace( "'", '"', "" ); - $this->assertStringContainsString( $expected, $output, 'Only enqueued dependents should affect the eligible strategy.' ); + $expected = ""; + $this->assertEqualHTMLScriptTagById( $expected, $output, 'Only enqueued dependents should affect the eligible strategy.' ); } /** @@ -1076,8 +1076,8 @@ 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 = str_replace( "'", '"', "\n" ); - $this->assertStringContainsString( $expected, $output, 'Expected defer, as there is no dependent or dependency' ); + $expected = "\n"; + $this->assertEqualHTMLScriptTagById( $expected, $output, 'Expected defer, as there is no dependent or dependency' ); } /** @@ -1096,7 +1096,7 @@ public function test_loading_strategy_with_defer_dependent_and_varied_dependenci wp_enqueue_script( 'main-script-d2', 'http://example.com/main-script-d2.js', array( 'dependency-script-d2-1', 'dependency-script-d2-3' ), null, array( 'strategy' => 'defer' ) ); $output = get_echo( 'wp_print_scripts' ); $expected = ''; - $this->assertStringContainsString( $expected, $output, 'Expected defer, as all dependencies are either deferred or blocking' ); + $this->assertEqualHTMLScriptTagById( $expected, $output, 'Expected defer, as all dependencies are either deferred or blocking' ); } /** @@ -1115,7 +1115,7 @@ public function test_loading_strategy_with_all_defer_dependencies() { wp_enqueue_script( 'dependent-script-d3-3', 'http://example.com/dependent-script-d3-3.js', array( 'dependent-script-d3-2' ), null, array( 'strategy' => 'defer' ) ); $output = get_echo( 'wp_print_scripts' ); $expected = ''; - $this->assertStringContainsString( $expected, $output, 'Expected defer, as all dependents have defer loading strategy' ); + $this->assertEqualHTMLScriptTagById( $expected, $output, 'Expected defer, as all dependents have defer loading strategy' ); } /** @@ -1495,9 +1495,10 @@ public function test_loading_strategy_with_invalid_defer_registration() { wp_enqueue_script( 'dependent-script-d4-1', '/dependent-script-d4-1.js', array( 'main-script-d4' ), null, array( 'strategy' => 'defer' ) ); wp_enqueue_script( 'dependent-script-d4-2', '/dependent-script-d4-2.js', array( 'dependent-script-d4-1' ), null ); 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 = str_replace( "'", '"', "\n" ); - $this->assertStringContainsString( $expected, $output, 'Scripts registered as defer but that have all dependents with no strategy, should become blocking (no strategy).' ); + $expected = "\n"; + $this->assertEqualHTMLScriptTagById( $expected, $output, 'Scripts registered as defer but that have all dependents with no strategy, should become blocking (no strategy).' ); } /**