Make WordPress Core

Changeset 60974


Ignore:
Timestamp:
10/19/2025 12:32:32 AM (less than one hour ago)
Author:
dmsnell
Message:

HTML API: Rely on assertEqualHTML in wp_rel_nofollow() tests.

As part of ongoing work to improve the reliability of HTML parsing code in WordPress, this patch replaces strict string-equality checks with semantic checks via assertEqualHTML() for more-direct assertions.

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

Props dmsnell, jonsurrell.
See #63694

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/wpRelNofollow.php

    r55289 r60974  
    1313    public function test_add_no_follow() {
    1414        $content  = '<p>This is some cool <a href="/">Code</a></p>';
    15         $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow\">Code</a></p>';
    16         $this->assertSame( $expected, wp_rel_nofollow( $content ) );
     15        $expected = '<p>This is some cool <a href="/" rel="nofollow">Code</a></p>';
     16        $this->assertEqualHTML( $expected, stripslashes( wp_rel_nofollow( $content ) ) );
    1717    }
    1818
     
    2222    public function test_convert_no_follow() {
    2323        $content  = '<p>This is some cool <a href="/" rel="weird">Code</a></p>';
    24         $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow\">Code</a></p>';
    25         $this->assertSame( $expected, wp_rel_nofollow( $content ) );
     24        $expected = '<p>This is some cool <a href="/" rel="weird nofollow">Code</a></p>';
     25        $this->assertEqualHTML( $expected, stripslashes( wp_rel_nofollow( $content ) ) );
    2626    }
    2727
     
    3131     */
    3232    public function test_wp_rel_nofollow( $input, $output, $expect_deprecation = false ) {
    33         $this->assertSame( wp_slash( $output ), wp_rel_nofollow( $input ) );
     33        $this->assertEqualHTML( $output, stripslashes( wp_rel_nofollow( $input ) ) );
    3434    }
    3535
     
    8181    public function test_append_no_follow_with_valueless_attribute() {
    8282        $content  = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
    83         $expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow\">Code</a></p>';
    84         $this->assertSame( $expected, wp_rel_nofollow( $content ) );
     83        $expected = '<p>This is some cool <a href="demo.com" download rel="hola nofollow">Code</a></p>';
     84        $this->assertEqualHTML( $expected, stripslashes( wp_rel_nofollow( $content ) ) );
    8585    }
    8686}
Note: See TracChangeset for help on using the changeset viewer.