Skip to content

Commit 21dd4a6

Browse files
committed
HTML API: Use assertEqualHTML() in wp_kses() tests. (WordPress#9257)
Prep work for WordPress#9248.
2 parents b7c0beb + c9c3da7 commit 21dd4a6

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

tests/phpunit/tests/kses.php

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Tests_Kses extends WP_UnitTestCase {
1717
public function test_wp_filter_post_kses_address( $content, $expected ) {
1818
global $allowedposttags;
1919

20-
$this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
20+
$this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
2121
}
2222

2323
/**
@@ -65,7 +65,7 @@ public function data_wp_filter_post_kses_address() {
6565
public function test_wp_filter_post_kses_a( $content, $expected ) {
6666
global $allowedposttags;
6767

68-
$this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
68+
$this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
6969
}
7070

7171
/**
@@ -120,7 +120,7 @@ public function data_wp_filter_post_kses_a() {
120120
* @param string $expected Expected output following KSES parsing.
121121
*/
122122
public function test_wp_kses_video( $source, $context, $expected ) {
123-
$this->assertSame( $expected, wp_kses( $source, $context ) );
123+
$this->assertEqualHTML( $expected, wp_kses( $source, $context ) );
124124
}
125125

126126
/**
@@ -171,7 +171,7 @@ public function data_wp_kses_video() {
171171
public function test_wp_filter_post_kses_abbr( $content, $expected ) {
172172
global $allowedposttags;
173173

174-
$this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
174+
$this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
175175
}
176176

177177
/**
@@ -232,7 +232,7 @@ public function test_feed_links() {
232232
<a href="">CLICK ME</a>
233233
EOF;
234234

235-
$this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
235+
$this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
236236
}
237237

238238
public function test_wp_kses_bad_protocol() {
@@ -546,8 +546,8 @@ public function test_hyphenated_tag() {
546546
$expect_stripped_content = 'Alot of hyphens.';
547547
$expect_valid_content = '<hyphenated-tag attribute="value">Alot of hyphens.</hyphenated-tag>';
548548

549-
$this->assertSame( $expect_stripped_content, wp_kses_post( $content ) );
550-
$this->assertSame( $expect_valid_content, wp_kses( $content, $custom_tags ) );
549+
$this->assertEqualHTML( $expect_stripped_content, wp_kses_post( $content ) );
550+
$this->assertEqualHTML( $expect_valid_content, wp_kses( $content, $custom_tags ) );
551551
}
552552

553553
/**
@@ -613,7 +613,7 @@ public static function data_normalize_entities(): array {
613613
* @dataProvider data_normalize_entities
614614
*/
615615
public function test_wp_kses_normalize_entities( string $input, string $expected ) {
616-
$this->assertSame( $expected, wp_kses_normalize_entities( $input ) );
616+
$this->assertEqualHTML( $expected, wp_kses_normalize_entities( $input ) );
617617
}
618618

619619
/**
@@ -625,7 +625,7 @@ public function test_wp_kses_normalize_entities( string $input, string $expected
625625
public function test_ctrl_removal( $content, $expected ) {
626626
global $allowedposttags;
627627

628-
return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
628+
return $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
629629
}
630630

631631
public function data_ctrl_removal() {
@@ -662,7 +662,7 @@ public function data_ctrl_removal() {
662662
public function test_slash_zero_removal( $content, $expected ) {
663663
global $allowedposttags;
664664

665-
return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
665+
return $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
666666
}
667667

668668
public function data_slash_zero_removal() {
@@ -917,7 +917,7 @@ public function test_bdo_tag_allowed() {
917917

918918
$content = '<p>This is <bdo dir="rtl">a BDO tag</bdo>. Weird, <bdo dir="ltr">right?</bdo></p>';
919919

920-
$this->assertSame( $content, wp_kses( $content, $allowedposttags ) );
920+
$this->assertEqualHTML( $content, wp_kses( $content, $allowedposttags ) );
921921
}
922922

923923
/**
@@ -928,7 +928,7 @@ public function test_ruby_tag_allowed() {
928928

929929
$content = '<ruby>✶<rp>: </rp><rt>Star</rt><rp>, </rp><rt lang="fr">Étoile</rt><rp>.</rp></ruby>';
930930

931-
$this->assertSame( $content, wp_kses( $content, $allowedposttags ) );
931+
$this->assertEqualHTML( $content, wp_kses( $content, $allowedposttags ) );
932932
}
933933

934934
/**
@@ -939,7 +939,7 @@ public function test_ol_reversed_attribute_allowed() {
939939

940940
$content = '<ol reversed="reversed"><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>';
941941

942-
$this->assertSame( $content, wp_kses( $content, $allowedposttags ) );
942+
$this->assertEqualHTML( $content, wp_kses( $content, $allowedposttags ) );
943943
}
944944

945945
/**
@@ -949,7 +949,7 @@ public function test_wp_kses_attr_no_attributes_allowed_with_empty_array() {
949949
$element = 'foo';
950950
$attribute = 'title="foo" class="bar"';
951951

952-
$this->assertSame( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => array() ), array() ) );
952+
$this->assertEqualHTML( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => array() ), array() ) );
953953
}
954954

955955
/**
@@ -959,7 +959,7 @@ public function test_wp_kses_attr_no_attributes_allowed_with_true() {
959959
$element = 'foo';
960960
$attribute = 'title="foo" class="bar"';
961961

962-
$this->assertSame( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => true ), array() ) );
962+
$this->assertEqualHTML( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => true ), array() ) );
963963
}
964964

965965
/**
@@ -969,7 +969,7 @@ public function test_wp_kses_attr_single_attribute_is_allowed() {
969969
$element = 'foo';
970970
$attribute = 'title="foo" class="bar"';
971971

972-
$this->assertSame( "<{$element} title=\"foo\">", wp_kses_attr( $element, $attribute, array( 'foo' => array( 'title' => true ) ), array() ) );
972+
$this->assertEqualHTML( "<{$element} title=\"foo\">", wp_kses_attr( $element, $attribute, array( 'foo' => array( 'title' => true ) ), array() ) );
973973
}
974974

975975
/**
@@ -979,7 +979,7 @@ public function test_wp_kses_attr_no_attributes_allowed_with_false() {
979979
$element = 'foo';
980980
$attribute = 'title="foo" class="bar"';
981981

982-
$this->assertSame( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => false ), array() ) );
982+
$this->assertEqualHTML( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => false ), array() ) );
983983
}
984984

985985
/**
@@ -1423,7 +1423,7 @@ public function test_wp_kses_attr_data_attribute_is_allowed() {
14231423
$test = '<div data-foo="foo" data-bar="bar" datainvalid="gone" data-two-hyphens="remains">Pens and pencils</div>';
14241424
$expected = '<div data-foo="foo" data-bar="bar" data-two-hyphens="remains">Pens and pencils</div>';
14251425

1426-
$this->assertSame( $expected, wp_kses_post( $test ) );
1426+
$this->assertEqualHTML( $expected, wp_kses_post( $test ) );
14271427
}
14281428

14291429
/**
@@ -1435,7 +1435,7 @@ public function test_wp_kses_attr_data_attribute_hypens_allowed() {
14351435
$test = '<div data--leading="remains" data-trailing-="remains" data-middle--double="remains">Pens and pencils</div>';
14361436
$expected = '<div data--leading="remains" data-trailing-="remains" data-middle--double="remains">Pens and pencils</div>';
14371437

1438-
$this->assertSame( $expected, wp_kses_post( $test ) );
1438+
$this->assertEqualHTML( $expected, wp_kses_post( $test ) );
14391439
}
14401440

14411441
/**
@@ -1456,7 +1456,7 @@ public function test_wildcard_requires_hyphen_after_prefix() {
14561456

14571457
$actual = wp_kses( $content, $allowed_html );
14581458

1459-
$this->assertSame( $expected, $actual );
1459+
$this->assertEqualHTML( $expected, $actual );
14601460
}
14611461

14621462
/**
@@ -1476,7 +1476,7 @@ public function test_wildcard_allows_two_hyphens() {
14761476

14771477
$actual = wp_kses( $content, $allowed_html );
14781478

1479-
$this->assertSame( $expected, $actual );
1479+
$this->assertEqualHTML( $expected, $actual );
14801480
}
14811481

14821482
/**
@@ -1761,7 +1761,7 @@ public function test_wp_kses_img_tag_standard_attributes() {
17611761

17621762
$html = implode( ' ', $html );
17631763

1764-
$this->assertSame( $html, wp_kses_post( $html ) );
1764+
$this->assertEqualHTML( $html, wp_kses_post( $html ) );
17651765
}
17661766

17671767
/**
@@ -1779,7 +1779,7 @@ public function test_wp_kses_main_tag_standard_attributes() {
17791779

17801780
$html = implode( ' ', $test );
17811781

1782-
$this->assertSame( $html, wp_kses_post( $html ) );
1782+
$this->assertEqualHTML( $html, wp_kses_post( $html ) );
17831783
}
17841784

17851785
/**
@@ -1793,7 +1793,7 @@ public function test_wp_kses_main_tag_standard_attributes() {
17931793
* @param string $expected The expected result from KSES.
17941794
*/
17951795
public function test_wp_kses_object_tag_allowed( $html, $expected ) {
1796-
$this->assertSame( $expected, wp_kses_post( $html ) );
1796+
$this->assertEqualHTML( $expected, wp_kses_post( $html ) );
17971797
}
17981798

17991799
/**
@@ -1904,7 +1904,7 @@ public function data_wp_kses_object_tag_allowed() {
19041904
*/
19051905
public function test_wp_kses_object_data_url_with_port_number_allowed( $html, $expected ) {
19061906
add_filter( 'upload_dir', array( $this, 'wp_kses_upload_dir_filter' ), 10, 2 );
1907-
$this->assertSame( $expected, wp_kses_post( $html ) );
1907+
$this->assertEqualHTML( $expected, wp_kses_post( $html ) );
19081908
}
19091909

19101910
/**
@@ -1970,7 +1970,7 @@ public function test_wp_kses_object_added_in_html_filter() {
19701970

19711971
remove_filter( 'wp_kses_allowed_html', array( $this, 'filter_wp_kses_object_added_in_html_filter' ) );
19721972

1973-
$this->assertSame( $html, $filtered_html );
1973+
$this->assertEqualHTML( $html, $filtered_html );
19741974
}
19751975

19761976
public function filter_wp_kses_object_added_in_html_filter( $tags, $context ) {
@@ -2001,9 +2001,10 @@ public function filter_wp_kses_object_added_in_html_filter( $tags, $context ) {
20012001
* @param string $expected_output How `wp_kses()` ought to transform the comment.
20022002
*/
20032003
public function test_wp_kses_preserves_html_comments( $html_comment, $expected_output ) {
2004-
$this->assertSame(
2004+
$this->assertEqualHTML(
20052005
$expected_output,
20062006
wp_kses( $html_comment, array() ),
2007+
'<body>',
20072008
'Failed to properly preserve HTML comment.'
20082009
);
20092010
}
@@ -2033,7 +2034,7 @@ public static function data_html_containing_various_kinds_of_html_comments() {
20332034
* @param array $allowed_html The allowed HTML to pass to KSES.
20342035
*/
20352036
public function test_wp_kses_allowed_values_list( $content, $expected, $allowed_html ) {
2036-
$this->assertSame( $expected, wp_kses( $content, $allowed_html ) );
2037+
$this->assertEqualHTML( $expected, wp_kses( $content, $allowed_html ) );
20372038
}
20382039

20392040
/**
@@ -2091,7 +2092,7 @@ static function ( $datum ) {
20912092
* @param array $allowed_html The allowed HTML to pass to KSES.
20922093
*/
20932094
public function test_wp_kses_required_attribute( $content, $expected, $allowed_html ) {
2094-
$this->assertSame( $expected, wp_kses( $content, $allowed_html ) );
2095+
$this->assertEqualHTML( $expected, wp_kses( $content, $allowed_html ) );
20952096
}
20962097

20972098
/**
@@ -2312,7 +2313,7 @@ public function data_kses_globals_are_defined() {
23122313
public function test_target_attribute_preserved_in_context( $context, $input, $expected ) {
23132314
$allowed = wp_kses_allowed_html( $context );
23142315
$this->assertTrue( isset( $allowed['a']['target'] ), "Target attribute not allowed in {$context}" );
2315-
$this->assertEquals( $expected, wp_kses( $input, $context ) );
2316+
$this->assertEqualHTML( $expected, wp_kses( $input, $context ) );
23162317
}
23172318

23182319
/**

0 commit comments

Comments
 (0)