-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
11e758e
84c65af
d483c8d
72e7c40
9f672ba
19ed504
1e9b067
76ec5b1
79d0a66
e90bfbf
e205a2c
2493b26
b2cca85
1bfbe89
1580d3b
e44a2ad
951307e
23e18f7
d2a2977
29faaf5
236267a
f670eb8
6e9877b
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -368,32 +368,39 @@ public function test_render_applies_dynamic_render_block_filter() { | |||||||||||||||||||||||||||
| * @return array | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| public function data_provider_test_render_enqueues_scripts_and_styles(): array { | ||||||||||||||||||||||||||||
| $block_markup = ' | ||||||||||||||||||||||||||||
| <!-- wp:static --> | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <!-- wp:static-child --> | ||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
| <!-- /wp:static-child --> | ||||||||||||||||||||||||||||
| <!-- wp:dynamic /--> | ||||||||||||||||||||||||||||
| <!-- wp:static-child --> | ||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
| <!-- /wp:static-child --> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| <!-- /wp:static --> | ||||||||||||||||||||||||||||
| '; | ||||||||||||||||||||||||||||
| $block_markup = <<<'HTML' | ||||||||||||||||||||||||||||
| <!-- wp:static --> | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <!-- wp:static-child --> | ||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
| <!-- /wp:static-child --> | ||||||||||||||||||||||||||||
| <!-- wp:dynamic /--> | ||||||||||||||||||||||||||||
| <!-- wp:static-child --> | ||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
| <!-- /wp:static-child --> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| <!-- /wp:static --> | ||||||||||||||||||||||||||||
| HTML; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // TODO: Add case where a dynamic block renders other blocks? | ||||||||||||||||||||||||||||
| return array( | ||||||||||||||||||||||||||||
| 'all_printed' => array( | ||||||||||||||||||||||||||||
| 'set_up' => null, | ||||||||||||||||||||||||||||
| 'block_markup' => $block_markup, | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => ' | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
| <p class="dynamic">Hello World!</p> | ||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => <<<'HTML' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Member
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. I’m not sure how to think through this, and I think you are alluding to it in how we split blocks from the HTML, but is this right? It seems to be producing two newlines which I wouldn’t have expected. Also, the test code itself performs an initial // test_render_enqueues_scripts_and_styles:L670
// TODO: Why not use do_blocks() instead?
$parsed_blocks = parse_blocks( trim( $block_markup ) );
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.
The block markup is this (after removing leading whitespace in this PR): <!-- wp:static -->
<div class="static">
<!-- wp:static-child -->
<div class="static-child">First child</div>
<!-- /wp:static-child -->
<!-- wp:dynamic /-->
<!-- wp:static-child -->
<div class="static-child">Last child</div>
<!-- /wp:static-child -->
</div>
<!-- /wp:static -->Rendering removes the block delimiters (and replaces the registered dynamic block), but preserves everything else. The result is this: <div class="static">
<div class="static-child">First child</div>
<p class="dynamic">Hello World!</p>
<div class="static-child">Last child</div>
</div>Before removing the indentation, this is what caused the <!-- wp:static -->␊
␉ <div class="static">␊
␉ <!-- wp:static-child -->␊
␉ <div class="static-child">First child</div>␊
␉ <!-- /wp:static-child -->␊
␉ <!-- wp:dynamic /-->␊
␉ <!-- wp:static-child -->␊
␉ <div class="static-child">Last child</div>␊
␉ <!-- /wp:static-child -->␊
␉ </div>␊
<!-- /wp:static -->Becomes: ␊
␉ <div class="static">␊
␉ ␊
␉ <div class="static-child">First child</div>␊
␉ ␊
␉ <p class="dynamic">Hello World!</p>␊
␉ ␊
␉ <div class="static-child">Last child</div>␊
␉ ␊
␉ </div>␊I've noticed here that the indentation was inconsistent, with the wordpress-develop/tests/phpunit/tests/blocks/wpBlock.php Lines 371 to 383 in 6ba48db
|
||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <p class="dynamic">Hello World!</p> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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' => ' | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
| <p class="dynamic filtered">Hello World!</p> | ||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => <<<'HTML' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <p class="dynamic filtered">Hello World!</p> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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' => ' | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => <<<'HTML' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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' => ' | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => <<<'HTML' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">Last child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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' => ' | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <p class="dynamic">Hello World!</p> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => <<<'HTML' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <p class="dynamic">Hello World!</p> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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' => ' | ||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
| <p class="dynamic">Hello World!</p> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => <<<'HTML' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static"> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <div class="static-child">First child</div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <p class="dynamic">Hello World!</p> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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' ), | ||||||||||||||||||||||||||||
|
|
@@ -562,9 +603,8 @@ static function ( $content ) { | |||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| 'block_markup' => '<!-- wp:static --><div class="static"></div><!-- /wp:static -->', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => ' | ||||||||||||||||||||||||||||
| <div class="static yes-admin-bar-script-enqueued yes-admin-bar-style-enqueued"></div> | ||||||||||||||||||||||||||||
| ', | ||||||||||||||||||||||||||||
| 'expected_rendered_block' => | ||||||||||||||||||||||||||||
| '<div class="static yes-admin-bar-script-enqueued yes-admin-bar-style-enqueued"></div>', | ||||||||||||||||||||||||||||
| 'expected_styles' => array( 'static-view-style', 'admin-bar' ), | ||||||||||||||||||||||||||||
| 'expected_scripts' => array( 'static-view-script', 'admin-bar' ), | ||||||||||||||||||||||||||||
| 'expected_script_modules' => array( 'static-view-script-module' ), | ||||||||||||||||||||||||||||
|
|
@@ -682,7 +722,7 @@ public function test_render_enqueues_scripts_and_styles( ?Closure $set_up, strin | |||||||||||||||||||||||||||
| $expected_rendered_block, | ||||||||||||||||||||||||||||
| $rendered_block, | ||||||||||||||||||||||||||||
| '<body>', | ||||||||||||||||||||||||||||
| "Rendered block does not contain expected HTML:\n$rendered_block" | ||||||||||||||||||||||||||||
| 'Rendered block does not contain expected HTML.' | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
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.