-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Tests: Ensure whitespace appears in assertEqualHTML tests #10765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
11e758e
84c65af
d483c8d
72e7c40
9f672ba
19ed504
1e9b067
76ec5b1
79d0a66
e90bfbf
e205a2c
2493b26
b2cca85
1bfbe89
1580d3b
e44a2ad
951307e
23e18f7
d2a2977
29faaf5
236267a
f670eb8
6e9877b
6dd1ee6
96e63f6
fd4f95f
a1ca3f0
f9110f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = "<script id='dependency-script-a2-js' src='/dependency-script-a2.js'></script>\n"; | ||
| $expected .= "<script src='/main-script-a2.js' id='main-script-a2-js' {$strategy} data-wp-strategy='{$strategy}'></script>"; | ||
| $expected .= "<script src='/main-script-a2.js' id='main-script-a2-js' {$strategy} data-wp-strategy='{$strategy}'></script>\n"; | ||
| $this->assertEqualHTML( $expected, $output, '<body>', '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 | ||
| <script src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script> | ||
| <script id="dependent-script-a3-js" src="/dependent-script-a3.js"></script> | ||
| <script src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script> | ||
| <script id="dependent-script-a3-js" src="/dependent-script-a3.js"></script> | ||
|
|
||
| JS; | ||
| $this->assertEqualHTML( $expected, $output, '<body>', '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 = "<script src='http://example.com/main-script-d1.js' id='main-script-d1-js' defer data-wp-strategy='defer'></script>\n"; | ||
| $expected = "<script src='http://example.com/main-script-d1.js' id='main-script-d1-js' defer data-wp-strategy='defer'></script>"; | ||
| $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' => '<script fetchpriority="low" id="bajo-js" src="/bajo.js"></script>', | ||
| 'expected' => "<script fetchpriority='low' id='bajo-js' src='/bajo.js'></script>\n", | ||
| ), | ||
| 'enqueue_auto' => array( | ||
| 'enqueues' => array( 'auto' ), | ||
| 'expected' => ' | ||
| <script src="/bajo.js" id="bajo-js" data-wp-fetchpriority="low"></script> | ||
| <script src="/auto.js" id="auto-js"></script> | ||
| ', | ||
| 'expected' => | ||
| "<script src='/bajo.js' id='bajo-js' data-wp-fetchpriority='low'></script>\n" . | ||
| "<script src='/auto.js' id='auto-js'></script>\n", | ||
| ), | ||
| 'enqueue_alto' => array( | ||
| 'enqueues' => array( 'alto' ), | ||
| 'expected' => ' | ||
| <script src="/bajo.js" id="bajo-js" fetchpriority="high" data-wp-fetchpriority="low"></script> | ||
| <script src="/auto.js" id="auto-js" fetchpriority="high" data-wp-fetchpriority="auto"></script> | ||
| <script src="/alto.js" id="alto-js" fetchpriority="high"></script> | ||
| ', | ||
| 'expected' => | ||
| "<script src='/bajo.js' id='bajo-js' fetchpriority='high' data-wp-fetchpriority='low'></script>\n" . | ||
| "<script src='/auto.js' id='auto-js' fetchpriority='high' data-wp-fetchpriority='auto'></script>\n" . | ||
| "<script src='/alto.js' id='alto-js' fetchpriority='high'></script>\n", | ||
| ), | ||
| ); | ||
| } | ||
|
|
@@ -1354,16 +1353,17 @@ public function test_fetchpriority_bumping_a_to_z() { | |
| wp_enqueue_script( 'x' ); | ||
|
|
||
| $actual = get_echo( 'wp_print_scripts' ); | ||
| $expected = ' | ||
| <script src="/z.js" id="z-js" fetchpriority="high" data-wp-fetchpriority="auto"></script> | ||
| <script src="/d.js" id="d-js" fetchpriority="high"></script> | ||
| <script src="/e.js" id="e-js"></script> | ||
| <script src="/c.js" id="c-js"></script> | ||
| <script src="/b.js" id="b-js"></script> | ||
| <script src="/a.js" id="a-js" fetchpriority="low"></script> | ||
| <script src="/y.js" id="y-js" fetchpriority="high" data-wp-fetchpriority="auto"></script> | ||
| <script src="/x.js" id="x-js" fetchpriority="high"></script> | ||
| '; | ||
| $expected = <<<'HTML' | ||
| <script src="/z.js" id="z-js" fetchpriority="high" data-wp-fetchpriority="auto"></script> | ||
| <script src="/d.js" id="d-js" fetchpriority="high"></script> | ||
| <script src="/e.js" id="e-js"></script> | ||
| <script src="/c.js" id="c-js"></script> | ||
| <script src="/b.js" id="b-js"></script> | ||
| <script src="/a.js" id="a-js" fetchpriority="low"></script> | ||
| <script src="/y.js" id="y-js" fetchpriority="high" data-wp-fetchpriority="auto"></script> | ||
| <script src="/x.js" id="x-js" fetchpriority="high"></script> | ||
|
|
||
| HTML; | ||
| $this->assertEqualHTML( $expected, $actual, '<body>', "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( | ||
| '<script src="/wp-includes/js/comment-reply.js" id="comment-reply-js" async data-wp-strategy="async" fetchpriority="low"></script>', | ||
| "<script src='/wp-includes/js/comment-reply.js' id='comment-reply-js' async data-wp-strategy='async' fetchpriority='low'></script>\n", | ||
| $actual, | ||
| '<body>', | ||
| "Snapshot:\n$actual" | ||
|
|
@@ -1456,7 +1456,7 @@ public function test_printing_default_script_comment_reply_enqueued_or_not_enque | |
|
|
||
| $this->assertEqualHTML( | ||
| sprintf( | ||
| '<script src="%s" id="comment-reply-js" async data-wp-strategy="async" fetchpriority="low"></script>', | ||
| "<script src='%s' id='comment-reply-js' async data-wp-strategy='async' fetchpriority='low'></script>\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 = "<script src='/main-script-d4.js' id='main-script-d4-js' data-wp-strategy='defer'></script>\n"; | ||
| $expected = "<script src='/main-script-d4.js' id='main-script-d4-js' data-wp-strategy='defer'></script>"; | ||
| $this->assertEqualHTMLScriptTagById( $expected, $output, 'Scripts registered as defer but that have all dependents with no strategy, should become blocking (no strategy).' ); | ||
|
Comment on lines
+1500
to
1501
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may seem surprising that this assertion removes a trailing newline. This is using
|
||
| } | ||
|
|
||
|
|
@@ -2210,6 +2210,7 @@ public function test_wp_add_inline_script_before() { | |
| console.log("before"); | ||
| //# sourceURL=test-example-js-before | ||
| </script> | ||
|
|
||
| HTML; | ||
| $expected .= "<script src='http://example.com' id='test-example-js'></script>\n"; | ||
|
|
||
|
|
@@ -2229,6 +2230,7 @@ public function test_wp_add_inline_script_after() { | |
| console.log("after"); | ||
| //# sourceURL=test-example-js-after | ||
| </script> | ||
|
|
||
| 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 = "<script src='/customize-dependency.js' id='customize-dependency-js'></script>\n"; | ||
| $expected = "<script src='/customize-dependency.js' id='customize-dependency-js'></script>"; | ||
| $this->assertEqualHTMLScriptTagById( $expected, $print_scripts ); | ||
|
|
||
| $expected = "<script id='customize-dependency-js-after'>\n"; | ||
| $expected .= "tryCustomizeDependency()\n"; | ||
| $expected .= "//# sourceURL=customize-dependency-js-after\n"; | ||
| $expected .= "</script>\n"; | ||
| $expected .= '</script>'; | ||
| $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, '<body>', 'Expected header script markup to match.' ); | ||
| $this->assertEqualHTML( $expected_footer, $footer, '<body>', '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' => ' | ||
| <script src="https://example.com/script-a.js" id="script-a-js" data-wp-strategy="defer"></script> | ||
| <script src="https://example.com/script-b.js" id="script-b-js"></script> | ||
| ', | ||
| 'expected_footer' => | ||
| "<script src='https://example.com/script-a.js' id='script-a-js' data-wp-strategy='defer'></script>\n" . | ||
| "<script src='https://example.com/script-b.js' id='script-b-js'></script>\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' => ' | ||
| <script src="https://example.com/script-a.js" id="script-a-js" data-wp-strategy="async"></script> | ||
| <script src="https://example.com/script-b.js" id="script-b-js"></script> | ||
| ', | ||
| 'expected_footer' => | ||
| "<script src='https://example.com/script-a.js' id='script-a-js' data-wp-strategy='async'></script>\n" . | ||
| "<script src='https://example.com/script-b.js' id='script-b-js'></script>\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' => ' | ||
| <script src="https://example.com/script-a.js" id="script-a-js" data-wp-strategy="defer"></script> | ||
| <script src="https://example.com/script-b.js" id="script-b-js"></script> | ||
| ', | ||
| 'expected_header' => | ||
| "<script src='https://example.com/script-a.js' id='script-a-js' data-wp-strategy='defer'></script>\n" . | ||
| "<script src='https://example.com/script-b.js' id='script-b-js'></script>\n", | ||
| 'expected_footer' => '', | ||
| 'expected_in_footer' => array(), | ||
| 'expected_groups' => array( | ||
|
|
@@ -3635,12 +3637,10 @@ public function data_provider_script_move_to_footer() { | |
| ) | ||
| ); | ||
| }, | ||
| 'expected_header' => ' | ||
| <script src="https://example.com/script-a.js" id="script-a-js" defer data-wp-strategy="defer"></script> | ||
| ', | ||
| 'expected_footer' => ' | ||
| <script src="https://example.com/script-b.js" id="script-b-js" defer data-wp-strategy="defer"></script> | ||
| ', | ||
| 'expected_header' => | ||
| "<script src='https://example.com/script-a.js' id='script-a-js' defer data-wp-strategy='defer'></script>\n", | ||
| 'expected_footer' => | ||
| "<script src='https://example.com/script-b.js' id='script-b-js' defer data-wp-strategy='defer'></script>\n", | ||
| 'expected_in_footer' => array( | ||
| 'script-b', | ||
| ), | ||
|
|
@@ -3685,14 +3685,12 @@ public function data_provider_script_move_to_footer() { | |
| ) | ||
| ); | ||
| }, | ||
| 'expected_header' => ' | ||
| <script src="https://example.com/script-a.js" id="script-a-js" defer data-wp-strategy="defer"></script> | ||
| <script src="https://example.com/script-b.js" id="script-b-js" defer data-wp-strategy="defer"></script> | ||
| ', | ||
| 'expected_footer' => ' | ||
| <script src="https://example.com/script-c.js" id="script-c-js" defer data-wp-strategy="defer"></script> | ||
| <script src="https://example.com/script-d.js" id="script-d-js" defer data-wp-strategy="defer"></script> | ||
| ', | ||
| 'expected_header' => | ||
| "<script src='https://example.com/script-a.js' id='script-a-js' defer data-wp-strategy='defer'></script>\n" . | ||
| "<script src='https://example.com/script-b.js' id='script-b-js' defer data-wp-strategy='defer'></script>\n", | ||
| 'expected_footer' => | ||
| "<script src='https://example.com/script-c.js' id='script-c-js' defer data-wp-strategy='defer'></script>\n" . | ||
| "<script src='https://example.com/script-d.js' id='script-d-js' defer data-wp-strategy='defer'></script>\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' => ' | ||
| <script src="https://example.com/script-a.js" id="script-a-js" data-wp-strategy="defer"></script> | ||
| <script src="https://example.com/script-b.js" id="script-b-js" defer data-wp-strategy="defer"></script> | ||
| <script src="https://example.com/script-c.js" id="script-c-js"></script> | ||
| <script src="https://example.com/script-d.js" id="script-d-js" defer data-wp-strategy="defer"></script> | ||
| ', | ||
| 'expected_footer' => | ||
| "<script src='https://example.com/script-a.js' id='script-a-js' data-wp-strategy='defer'></script>\n" . | ||
| "<script src='https://example.com/script-b.js' id='script-b-js' defer data-wp-strategy='defer'></script>\n" . | ||
| "<script src='https://example.com/script-c.js' id='script-c-js'></script>\n" . | ||
| "<script src='https://example.com/script-d.js' id='script-d-js' defer data-wp-strategy='defer'></script>\n", | ||
| 'expected_in_footer' => array( | ||
| 'script-a', | ||
| 'script-b', | ||
|
|
@@ -3779,14 +3776,12 @@ public function data_provider_script_move_to_footer() { | |
| ) | ||
| ); | ||
| }, | ||
| 'expected_header' => ' | ||
| <script src="https://example.com/script-a.js" id="script-a-js" data-wp-strategy="defer"></script> | ||
| <script src="https://example.com/script-b.js" id="script-b-js" defer data-wp-strategy="defer"></script> | ||
| ', | ||
| 'expected_footer' => ' | ||
| <script src="https://example.com/script-c.js" id="script-c-js"></script> | ||
| <script src="https://example.com/script-d.js" id="script-d-js" defer data-wp-strategy="defer"></script> | ||
| ', | ||
| 'expected_header' => | ||
| "<script src='https://example.com/script-a.js' id='script-a-js' data-wp-strategy='defer'></script>\n" . | ||
| "<script src='https://example.com/script-b.js' id='script-b-js' defer data-wp-strategy='defer'></script>\n", | ||
| 'expected_footer' => | ||
| "<script src='https://example.com/script-c.js' id='script-c-js'></script>\n" . | ||
| "<script src='https://example.com/script-d.js' id='script-d-js' defer data-wp-strategy='defer'></script>\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 = <<<HTML | ||
|
|
||
| <script> | ||
| 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 = "<script src='/test-script.js?{$expected_query_string}' id='test-script-js'></script>"; | ||
| $expected = "<script src='/test-script.js?{$expected_query_string}' id='test-script-js'></script>\n"; | ||
| $this->assertEqualHTML( $expected, $markup, '<body>', '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 = "<script src='/test-script.js?{$expected_query_string}' id='test-script-js'></script>"; | ||
| $expected = "<script src='/test-script.js?{$expected_query_string}' id='test-script-js'></script>\n"; | ||
| $this->assertEqualHTML( $expected, $markup, '<body>', 'Expected equal snapshot for wp_print_scripts() with version ' . var_export( $version, true ) . ":\n$markup" ); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the main problem, it effectively eliminated whitespace text completely, and leading whitespace from existing text nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added in the first place? The
trim()here occurs after decoding, meaning that any raw markup would have already been processed and whitespace normalized.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was introduced as part of block delimiters appearing in the HTML tree. That change is not open source, this was largely developed in another project before being proposed for Core.