Make WordPress Core

Changeset 60486


Ignore:
Timestamp:
07/18/2025 09:39:21 PM (13 months ago)
Author:
dmsnell
Message:

HTML API: Use assertEqualHTML() in wp_kses() tests.

Developed in https://github.com/WordPress/wordpress-develop/pull/9257
Discussed in https://core.trac.wordpress.org/ticket/63694

Props dmsnell, jonsurrell.
See #63694.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment.php

    r60485 r60486  
    169169
    170170                $comment = get_comment( $comment_id );
    171                 $this->assertEqualHTML( '<a href="http://example.localhost/something.html" rel="nofollow ugc">click</a>', $comment->comment_content, '<body>', 'Comment: ' . $comment->comment_content );
     171                $this->assertEqualHTML(
     172                        '<a href="http://example.localhost/something.html" rel="nofollow ugc">click</a>',
     173                        $comment->comment_content,
     174                        '<body>',
     175                        'Comment: ' . $comment->comment_content
     176                );
    172177        }
    173178
  • trunk/tests/phpunit/tests/kses.php

    r60446 r60486  
    1818                global $allowedposttags;
    1919
    20                 $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
     20                $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
    2121        }
    2222
     
    6666                global $allowedposttags;
    6767
    68                 $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
     68                $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
    6969        }
    7070
     
    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
     
    172172                global $allowedposttags;
    173173
    174                 $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
     174                $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
    175175        }
    176176
     
    233233EOF;
    234234
    235                 $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
     235                $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
    236236        }
    237237
     
    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
     
    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
     
    626626                global $allowedposttags;
    627627
    628                 return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
     628                return $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
    629629        }
    630630
     
    663663                global $allowedposttags;
    664664
    665                 return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
     665                return $this->assertEqualHTML( $expected, wp_kses( $content, $allowedposttags ) );
    666666        }
    667667
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    14571457                $actual = wp_kses( $content, $allowed_html );
    14581458
    1459                 $this->assertSame( $expected, $actual );
     1459                $this->assertEqualHTML( $expected, $actual );
    14601460        }
    14611461
     
    14771477                $actual = wp_kses( $content, $allowed_html );
    14781478
    1479                 $this->assertSame( $expected, $actual );
     1479                $this->assertEqualHTML( $expected, $actual );
    14801480        }
    14811481
     
    17621762                $html = implode( ' ', $html );
    17631763
    1764                 $this->assertSame( $html, wp_kses_post( $html ) );
     1764                $this->assertEqualHTML( $html, wp_kses_post( $html ) );
    17651765        }
    17661766
     
    17801780                $html = implode( ' ', $test );
    17811781
    1782                 $this->assertSame( $html, wp_kses_post( $html ) );
     1782                $this->assertEqualHTML( $html, wp_kses_post( $html ) );
    17831783        }
    17841784
     
    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
     
    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
     
    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
     
    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                );
     
    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
     
    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
     
    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
Note: See TracChangeset for help on using the changeset viewer.