Skip to content

Commit badabdf

Browse files
authored
Merge pull request #1 from wptrainingteam/fix/assert-equal-html-whitespace-wp70
Fix test broken by assertEqualHTML whitespace change in WP 7.0 (core #64531)
2 parents f04216b + aa6c1b4 commit badabdf

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)