WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (15 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

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

    r47122 r48937  
    1010        $content  = '<p>Links: <a href="/" target="_blank">No rel</a></p>';
    1111        $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">No rel</a></p>';
    12         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     12        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    1313    }
    1414
     
    1616        $content  = '<p>Links: <a href="/" target="foo">No rel</a></p>';
    1717        $expected = '<p>Links: <a href="/" target="foo" rel="noopener noreferrer">No rel</a></p>';
    18         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     18        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    1919    }
    2020
     
    2222        $content  = '<p>Links: <a target="_blank" href="#">No rel</a></p>';
    2323        $expected = '<p>Links: <a target="_blank" href="#" rel="noopener noreferrer">No rel</a></p>';
    24         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     24        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    2525    }
    2626
     
    2828        $content  = '<p>Links: <a href="/" rel="existing values" target="_blank">Existing rel</a></p>';
    2929        $expected = '<p>Links: <a href="/" rel="existing values noopener noreferrer" target="_blank">Existing rel</a></p>';
    30         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     30        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    3131    }
    3232
     
    3434        $content  = '<p>Links: <a href="/" rel="existing noopener values" target="_blank">Existing rel</a></p>';
    3535        $expected = '<p>Links: <a href="/" rel="existing noopener values noreferrer" target="_blank">Existing rel</a></p>';
    36         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     36        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    3737    }
    3838
     
    4040        $content  = '<p>Links: <a href="/" rel=\'existing values\' target="_blank">Existing rel</a></p>';
    4141        $expected = '<p>Links: <a href="/" rel="existing values noopener noreferrer" target="_blank">Existing rel</a></p>';
    42         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     42        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    4343    }
    4444
     
    4646        $content  = '<p>Links: <a href="/" rel=existing target="_blank">Existing rel</a></p>';
    4747        $expected = '<p>Links: <a href="/" rel="existing noopener noreferrer" target="_blank">Existing rel</a></p>';
    48         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     48        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    4949    }
    5050
     
    5252        $content  = '<p>Links: <a href="/" rel = existing target="_blank">Existing rel</a></p>';
    5353        $expected = '<p>Links: <a href="/" rel="existing noopener noreferrer" target="_blank">Existing rel</a></p>';
    54         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     54        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    5555    }
    5656
     
    5858        $content  = '<p>Links: <a href=\"/\" rel=\"existing values\" target=\"_blank\">Existing rel</a></p>';
    5959        $expected = '<p>Links: <a href=\"/\" rel=\"existing values noopener noreferrer\" target=\"_blank\">Existing rel</a></p>';
    60         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     60        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    6161    }
    6262
     
    6464        $content  = '<p>Links: <a href="/" target="_blank">Change me</a> <a href="/">Do not change me</a></p>';
    6565        $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">Change me</a> <a href="/">Do not change me</a></p>';
    66         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     66        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    6767    }
    6868
     
    7676        $content  = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>';
    7777        $expected = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>';
    78         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     78        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    7979    }
    8080
     
    9494        );
    9595
    96         $this->assertEquals( $expected, $post->post_content );
     96        $this->assertSame( $expected, $post->post_content );
    9797    }
    9898
     
    105105        $content  = '<p>Links: <a href=\"\/\" target=\"_blank\">No rel<\/a><\/p>';
    106106        $expected = '<p>Links: <a href=\"\/\" target=\"_blank\" rel=\"noopener noreferrer\">No rel<\/a><\/p>';
    107         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     107        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    108108    }
    109109
     
    116116        $content  = '<style><a href="/" target=a></style><p>Links: <script>console.log("<a href=\'/\' target=a>hi</a>");</script><script>alert(1);</script>here <a href="/" target=_blank>aq</a></p><script>console.log("<a href=\'last\' target=\'_blank\'")</script>';
    117117        $expected = '<style><a href="/" target=a></style><p>Links: <script>console.log("<a href=\'/\' target=a>hi</a>");</script><script>alert(1);</script>here <a href="/" target="_blank" rel="noopener noreferrer">aq</a></p><script>console.log("<a href=\'last\' target=\'_blank\'")</script>';
    118         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     118        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    119119    }
    120120
     
    127127        $content  = 'a:1:{s:4:"html";s:52:"<p>Links: <a href="/" target="_blank">No Rel</a></p>";}';
    128128        $expected = 'a:1:{s:4:"html";s:52:"<p>Links: <a href="/" target="_blank">No Rel</a></p>";}';
    129         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     129        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    130130    }
    131131
     
    133133        $content  = "<p>Links: <a href=\"/\" target=\"_blank\" rel=\"ugc\t\tnoopener\t\">No rel</a></p>";
    134134        $expected = '<p>Links: <a href="/" target="_blank" rel="ugc noopener noreferrer">No rel</a></p>';
    135         $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     135        $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
    136136    }
    137137
Note: See TracChangeset for help on using the changeset viewer.