Skip to content

Commit aa6c1b4

Browse files
juanmaguitarclaude
andcommitted
Fix test broken by assertEqualHTML whitespace fix (WP 7.0 / #64531)
WordPress core ticket #64531 (fixed in 6.9.1, included in 7.0) corrected build_visual_html_tree() to stop trimming leading whitespace from text nodes. Whitespace-only text nodes between elements are now preserved and compared. The test_card_block_renders_with_background_color test had a multi-line $expected string that started with a newline before <div> and had newlines and tabs between </div...> and <p>. These became text nodes in the parsed tree that don't exist in the actual render output, causing the assertion to fail on WP 7.0. Fix: remove the leading newline before <div> and close the gap between the opening tag and <p> so no whitespace text nodes are introduced. Attributes can still span multiple lines for readability — whitespace inside a tag is not a text node. Also bump .wp-env.json to wordpress-7.0-beta1 to reflect the WP version this fix targets. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent df1e62d commit aa6c1b4

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎.wp-env.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3-
"core": "https://wordpress.org/wordpress-6.9.zip",
3+
"core": "https://wordpress.org/wordpress-7.0-beta1.zip",
44
"plugins": ["."],
55
"phpVersion": "8.2",
66
"env": {

‎tests/RenderCardBlockTest.php‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ class RenderCardBlockTest extends WP_UnitTestCase {
1616
* Note: assertEqualHTML normalizes class order — so it doesn't matter
1717
* whether add_class() puts "is-style-outlined" before or after
1818
* "wp-block-my-plugin-card".
19+
*
20+
* Whitespace tip: attributes can span multiple lines (they are part of the
21+
* opening tag, not text nodes). But whitespace *between* elements — like a
22+
* newline between `>` and `<p>` — creates a text node that must match the
23+
* actual output. Since the render callback concatenates $content directly
24+
* with no surrounding whitespace, the expected string must do the same:
25+
* `...><p>...</p></div>` with no gaps.
1926
*/
2027
public function test_card_block_renders_with_background_color(): void {
2128
$attributes = array(
@@ -28,14 +35,13 @@ public function test_card_block_renders_with_background_color(): void {
2835
$output = my_plugin_render_card_block( $attributes, $inner_content );
2936

3037
// Attribute order and class order don't need to match exactly.
31-
$expected = '
32-
<div
33-
class="is-style-outlined my-custom-class wp-block-my-plugin-card"
34-
style="background-color: #f5f5f5;"
35-
>
36-
<p class="wp-block-paragraph">Hello</p>
37-
</div>
38-
';
38+
// Attributes may be on separate lines for readability — that's fine.
39+
// But there must be no whitespace between > and <p>, since the actual
40+
// output has none (whitespace-only text nodes are compared as-is).
41+
$expected = '<div
42+
class="is-style-outlined my-custom-class wp-block-my-plugin-card"
43+
style="background-color: #f5f5f5;"
44+
><p class="wp-block-paragraph">Hello</p></div>';
3945

4046
$this->assertEqualHTML( $expected, $output );
4147
}

0 commit comments

Comments
 (0)