Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
00617e7
Tests: Add assertEqualMarkup trait
ockham Jun 2, 2025
cbba80a
Add test coverage for assertion helper method
ockham Jun 2, 2025
0602711
Fix include path
ockham Jun 2, 2025
c01a3c1
Remove now-obsolete method of the same name from Tests_Dependencies_S…
ockham Jun 2, 2025
5a5b2b1
Remove obsolete require_lib
ockham Jun 2, 2025
1cb1f23
Add since PHPDoc
ockham Jun 2, 2025
38b575a
Move assertion to class WP_UnitTestCase_Base
ockham Jun 2, 2025
8204474
Get rid of trait
ockham Jun 2, 2025
03f7b09
WPCS
ockham Jun 2, 2025
09cf449
Remove potentially obsolete PHPCS ignore
ockham Jun 2, 2025
b2fc3ff
Revert "Remove now-obsolete method of the same name from Tests_Depend…
ockham Jun 2, 2025
ef27f4f
Bring back assertEqualMarkup override, harmonize signature
ockham Jun 2, 2025
51e4613
Remove trailing newline
ockham Jun 2, 2025
2258487
Fix class name
ockham Jun 2, 2025
5bfdf9b
Tweak tests
ockham Jun 2, 2025
2b33187
Remove strict_types declaration
ockham Jun 2, 2025
82d57b6
Fix heredoc indentation for PHP 7.2 compat :rolleyes:
ockham Jun 2, 2025
3fbf857
Use WP_Block_Parser for block parsing
ockham Jun 3, 2025
3090d65
Handle void blocks correctly
ockham Jun 3, 2025
47dccc1
Rearrange logic
ockham Jun 3, 2025
bb2404b
Allow for different whitespace in class attribute
ockham Jun 3, 2025
192009b
De-duplicate block class names
ockham Jun 3, 2025
7cf7c64
Change Html5lib test format reference link
ockham Jun 4, 2025
d0d46fe
Add more PHPDoc and an example to build_tree_representation
ockham Jun 4, 2025
252569d
Use Tag Processor to normalize block class names
ockham Jun 4, 2025
eae650f
Whitespace :rolleyes:
ockham Jun 4, 2025
e8ceff2
Rename function to build_equivalent_html_semantic_tree
ockham Jun 4, 2025
5c44e1a
Add covers PHPDoc to tests
ockham Jun 4, 2025
5ff8ad4
Fall back to DOM\HTMLDocument for PHP 8.4+
ockham Jun 4, 2025
90f958d
Revert "Bring back assertEqualMarkup override, harmonize signature"
ockham Jun 4, 2025
7735df4
Rename new method to assertEqualBlockMarkup
ockham Jun 4, 2025
7581a94
Add @todo note to "old" assertEqualMarkup
ockham Jun 4, 2025
8d7e402
Update PHPDoc for assertEqualBlockMarkup
ockham Jun 4, 2025
51600e6
Add test with capitalization/lower case letters.
ockham Jun 5, 2025
ddaec5e
Update to use the new assertEqualMarkup helper
sirreal Jun 5, 2025
98ad4c9
Rename test helper to assertEqualMarkup
sirreal Jun 5, 2025
492316d
Fix script async/defer strategy expectation to match printed scripts
sirreal Jun 5, 2025
c7317e7
Add CDATA inline script wrappers where they appear in markup
sirreal Jun 5, 2025
7472609
FIXME: Skip an inaccurate test
sirreal Jun 5, 2025
844a076
Adjust expected output to use attributes as generated
sirreal Jun 5, 2025
514967f
Add html5 support to a test that expects html5 support
sirreal Jun 5, 2025
fed7647
Script quotes in IE7 conditional _comments_ produce semantically _dif…
sirreal Jun 5, 2025
28e1fd7
Revert irrelevant change
sirreal Jun 5, 2025
c2f1bfa
Fix more missing CDATA comments
sirreal Jun 5, 2025
5a60a70
Remove scripts specific assertEqualMarkup implementation
sirreal Jun 5, 2025
b0df96a
Use more consistent code backticks in docblock
sirreal Jun 5, 2025
1cb1daf
Fix phpcs issues
sirreal Jun 5, 2025
defbe92
Remove now-obsolete parse_markup_fragment() method
ockham Jun 5, 2025
2b66454
Fix PHPDoc param order
ockham Jun 10, 2025
95ddd9a
Tweak PHPDoc description of build_equivalent_semantic_tree
ockham Jun 10, 2025
6a79216
Add return type, tweak PHPDoc
ockham Jun 10, 2025
9469f43
Rename to build_visual_html_tree
ockham Jun 10, 2025
b07677e
Rename to assertEqualHTML
ockham Jun 10, 2025
f7736c4
Fix indentation
ockham Jun 10, 2025
a83ff2b
Add ticket annotations
ockham Jun 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test coverage for assertion helper method
  • Loading branch information
ockham committed Jun 2, 2025
commit cbba80a81c1ef6297ed7bf4e74dd8d16afbbe198
116 changes: 116 additions & 0 deletions tests/phpunit/tests/assert-equal-markup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php declare( strict_types = 1 );

/**
* Tests for the assertEqualMarkup() assertion.
*
* @package WordPress
*
* @group testsuite
*/
class Tests_Assert_Equal_Markup extends WP_UnitTestCase {
use AssertEqualMarkup; // This gives us access to the private `build_tree_representation()` method.

public function data_build_tree_representation() {
return array(
'Block delimiter' => array(
<<<END
<!-- wp:separator {"className":"is-style-default has-custom-classname","style":{"spacing":{"margin":{"top":"50px","bottom":"50px"}}},"backgroundColor":"accent-1"} -->
<hr class="wp-block-separator is-style-default has-custom-classname" style="margin-top: 50px; margin-bottom: 50px" />
<!-- /wp:separator -->
END,
<<<END
BLOCK["core/separator"]
{
"backgroundColor": "accent-1",
"className": "has-custom-classname is-style-default",
"style": {
"spacing": {
"margin": {
"top": "50px",
"bottom": "50px"
}
}
}
}
<hr>
class="has-custom-classname is-style-default wp-block-separator"
style="margin-top:50px;margin-bottom:50px;"

END,
),
);
}

/**
* @dataProvider data_build_tree_representation
*/
public function test_build_tree_representation( $markup, $expected ) {
$actual = self::build_tree_representation( $markup, '<body>' );
$this->assertSame( $expected, $actual );
}

public function data_assert_equal_markup_passes_for_equivalent_html() {
return array(
'Different attribute order' => array(
'<img src="wp.png" alt="The WordPress logo">',
'<img alt="The WordPress logo" src="wp.png">',
),
'Different class name order' => array(
'<hr class="wp-block-separator is-style-default">',
'<hr class="is-style-default wp-block-separator">',
),
'Differences in style attribute whitespace and trailing semicolon' => array(
'<hr style="margin-top: 50px; margin-bottom: 50px;">',
'<hr style="margin-top:50px;margin-bottom: 50px">',
),
'Different block attribute order' => array(
'<!-- wp:separator {"className":"is-style-default","backgroundColor":"accent-1"} -->',
'<!-- wp:separator {"backgroundColor":"accent-1","className":"is-style-default"} -->',
),
'Different block class name order' => array(
'<!-- wp:separator {"className":"is-style-default has-custom-classname"} -->',
'<!-- wp:separator {"className":"has-custom-classname is-style-default"} -->',
),
);
}

/**
* @dataProvider data_assert_equal_markup_passes_for_equivalent_html
*/
public function test_assert_equal_markup_passes_for_equivalent_html( $expected, $actual ) {
$this->assertEqualMarkup( $expected, $actual );
}

public function data_assert_equal_markup_fails_for_non_equivalent_html() {
return array(
'Different attributes' => array(
'<img src="wp.png" alt="The WordPress logo">',
'<img alt="The WordPress logo" src="wp.png" title="WordPress">',
),
'Different class names' => array(
'<hr class="wp-block-separator is-style-default">',
'<hr class="is-style-default wp-block-hairline">',
),
'Different styles' => array(
'<hr style="margin-top: 50px; margin-bottom: 50px;">',
'<hr style="margin-top: 50px; margin-bottom: 100px">',
),
'Different comments' => array(
'<!-- abc -->',
'<!-- xyz -->',
),
'Semantically relevant whitespace' => array(
'<div style="color: rgb(50 139 31)">Test</div>',
'<div style="color:rgb(5013931)">Test</div>',
),
);
}

/**
* @dataProvider data_assert_equal_markup_fails_for_non_equivalent_html
*/
public function test_assert_equal_markup_fails_for_non_equivalent_html( $expected, $actual ) {
$this->expectException( 'PHPUnit\Framework\ExpectationFailedException' );
$this->assertEqualMarkup( $expected, $actual );
}
}