Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (6 years 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/SanitizeTitleWithDashes.php

    r48593 r48937  
    88                $input    = 'Captain <strong>Awesome</strong>';
    99                $expected = 'captain-awesome';
    10                 $this->assertEquals( $expected, sanitize_title( $input ) );
     10                $this->assertSame( $expected, sanitize_title( $input ) );
    1111        }
    1212
    1313        function test_strips_unencoded_percent_signs() {
    14                 $this->assertEquals( 'fran%c3%a7ois', sanitize_title_with_dashes( 'fran%c3%a7%ois' ) );
     14                $this->assertSame( 'fran%c3%a7ois', sanitize_title_with_dashes( 'fran%c3%a7%ois' ) );
    1515        }
    1616
    1717        function test_makes_title_lowercase() {
    18                 $this->assertEquals( 'abc', sanitize_title_with_dashes( 'ABC' ) );
     18                $this->assertSame( 'abc', sanitize_title_with_dashes( 'ABC' ) );
    1919        }
    2020
    2121        function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
    22                 $this->assertEquals( 'a-t', sanitize_title_with_dashes( 'a          t' ) );
    23                 $this->assertEquals( 'a-t', sanitize_title_with_dashes( "a    \n\n\nt" ) );
     22                $this->assertSame( 'a-t', sanitize_title_with_dashes( 'a          t' ) );
     23                $this->assertSame( 'a-t', sanitize_title_with_dashes( "a    \n\n\nt" ) );
    2424        }
    2525
    2626        function test_replaces_any_number_of_hyphens_with_one_hyphen() {
    27                 $this->assertEquals( 'a-t-t', sanitize_title_with_dashes( 'a----t----t' ) );
     27                $this->assertSame( 'a-t-t', sanitize_title_with_dashes( 'a----t----t' ) );
    2828        }
    2929
    3030        function test_trims_trailing_hyphens() {
    31                 $this->assertEquals( 'a-t-t', sanitize_title_with_dashes( 'a----t----t----' ) );
     31                $this->assertSame( 'a-t-t', sanitize_title_with_dashes( 'a----t----t----' ) );
    3232        }
    3333
    3434        function test_handles_non_entity_ampersands() {
    35                 $this->assertEquals( 'penn-teller-bull', sanitize_title_with_dashes( 'penn & teller bull' ) );
     35                $this->assertSame( 'penn-teller-bull', sanitize_title_with_dashes( 'penn & teller bull' ) );
    3636        }
    3737
    3838        public function test_strips_nbsp_ndash_and_amp() {
    39                 $this->assertEquals( 'no-entities-here', sanitize_title_with_dashes( 'No &nbsp; Entities &ndash; Here &amp;' ) );
     39                $this->assertSame( 'no-entities-here', sanitize_title_with_dashes( 'No &nbsp; Entities &ndash; Here &amp;' ) );
    4040        }
    4141
    4242        public function test_strips_encoded_ampersand() {
    43                 $this->assertEquals( 'one-two', sanitize_title_with_dashes( 'One &amp; Two', '', 'save' ) );
     43                $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One &amp; Two', '', 'save' ) );
    4444        }
    4545
    4646        public function test_strips_url_encoded_ampersand() {
    47                 $this->assertEquals( 'one-two', sanitize_title_with_dashes( 'One &#123; Two;', '', 'save' ) );
     47                $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One &#123; Two;', '', 'save' ) );
    4848        }
    4949
    5050        public function test_strips_trademark_symbol() {
    51                 $this->assertEquals( 'one-two', sanitize_title_with_dashes( 'One Two™;', '', 'save' ) );
     51                $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One Two™;', '', 'save' ) );
    5252        }
    5353
    5454        public function test_strips_unencoded_ampersand_followed_by_encoded_ampersand() {
    55                 $this->assertEquals( 'one-two', sanitize_title_with_dashes( 'One &&amp; Two;', '', 'save' ) );
     55                $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One &&amp; Two;', '', 'save' ) );
    5656        }
    5757
    5858        public function test_strips_unencoded_ampersand_when_not_surrounded_by_spaces() {
    59                 $this->assertEquals( 'onetwo', sanitize_title_with_dashes( 'One&Two', '', 'save' ) );
     59                $this->assertSame( 'onetwo', sanitize_title_with_dashes( 'One&Two', '', 'save' ) );
    6060        }
    6161
    6262        function test_replaces_nbsp() {
    63                 $this->assertEquals( 'dont-break-the-space', sanitize_title_with_dashes( "don't break the space", '', 'save' ) );
     63                $this->assertSame( 'dont-break-the-space', sanitize_title_with_dashes( "don't break the space", '', 'save' ) );
    6464        }
    6565
    … …  
    6868         */
    6969        function test_replaces_nbsp_entities() {
    70                 $this->assertEquals( 'dont-break-the-space', sanitize_title_with_dashes( "don't&nbsp;break&#160;the&nbsp;space", '', 'save' ) );
     70                $this->assertSame( 'dont-break-the-space', sanitize_title_with_dashes( "don't&nbsp;break&#160;the&nbsp;space", '', 'save' ) );
    7171        }
    7272
    7373        function test_replaces_ndash_mdash() {
    74                 $this->assertEquals( 'do-the-dash', sanitize_title_with_dashes( 'Do – the Dash', '', 'save' ) );
    75                 $this->assertEquals( 'do-the-dash', sanitize_title_with_dashes( 'Do the — Dash', '', 'save' ) );
     74                $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do – the Dash', '', 'save' ) );
     75                $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do the — Dash', '', 'save' ) );
    7676        }
    7777
    … …  
    8080         */
    8181        function test_replaces_ndash_mdash_entities() {
    82                 $this->assertEquals( 'do-the-dash', sanitize_title_with_dashes( 'Do &ndash; the &#8211; Dash', '', 'save' ) );
    83                 $this->assertEquals( 'do-the-dash', sanitize_title_with_dashes( 'Do &mdash; the &#8212; Dash', '', 'save' ) );
     82                $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do &ndash; the &#8211; Dash', '', 'save' ) );
     83                $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do &mdash; the &#8212; Dash', '', 'save' ) );
    8484        }
    8585
    8686        function test_replaces_iexcel_iquest() {
    87                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( 'Just ¡a Slug', '', 'save' ) );
    88                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( 'Just a Slug¿', '', 'save' ) );
     87                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just ¡a Slug', '', 'save' ) );
     88                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just a Slug¿', '', 'save' ) );
    8989        }
    9090
    9191        function test_replaces_angle_quotes() {
    92                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( '‹Just a Slug›', '', 'save' ) );
    93                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( '«Just a Slug»', '', 'save' ) );
     92                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( '‹Just a Slug›', '', 'save' ) );
     93                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( '«Just a Slug»', '', 'save' ) );
    9494        }
    9595
    9696        function test_replaces_curly_quotes() {
    97                 $this->assertEquals( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its “Curly Joe”', '', 'save' ) );
    98                 $this->assertEquals( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its ‘Curly Joe’', '', 'save' ) );
    99                 $this->assertEquals( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its „Curly Joe“', '', 'save' ) );
    100                 $this->assertEquals( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its ‚Curly Joe‛', '', 'save' ) );
    101                 $this->assertEquals( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its „Curly Joe‟', '', 'save' ) );
     97                $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its “Curly Joe”', '', 'save' ) );
     98                $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its ‘Curly Joe’', '', 'save' ) );
     99                $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its „Curly Joe“', '', 'save' ) );
     100                $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its ‚Curly Joe‛', '', 'save' ) );
     101                $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its „Curly Joe‟', '', 'save' ) );
    102102        }
    103103
    … …  
    106106         */
    107107        function test_replaces_bullet() {
    108                 $this->assertEquals( 'fancy-title-amazing', sanitize_title_with_dashes( 'Fancy Title • Amazing', '', 'save' ) );
     108                $this->assertSame( 'fancy-title-amazing', sanitize_title_with_dashes( 'Fancy Title • Amazing', '', 'save' ) );
    109109        }
    110110
    111111        function test_replaces_copy_reg_deg_trade() {
    112                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( 'Just © a Slug', '', 'save' ) );
    113                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( '® Just a Slug', '', 'save' ) );
    114                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( 'Just a ° Slug', '', 'save' ) );
    115                 $this->assertEquals( 'just-a-slug', sanitize_title_with_dashes( 'Just ™ a Slug', '', 'save' ) );
     112                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just © a Slug', '', 'save' ) );
     113                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( '® Just a Slug', '', 'save' ) );
     114                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just a ° Slug', '', 'save' ) );
     115                $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just ™ a Slug', '', 'save' ) );
    116116        }
    117117
    … …  
    120120         */
    121121        function test_replaces_forward_slash() {
    122                 $this->assertEquals( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon/McCartney', '', 'save' ) );
    123                 $this->assertEquals( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon//McCartney', '', 'save' ) );
    124                 $this->assertEquals( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon///McCartney', '', 'save' ) );
    125                 $this->assertEquals( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon/-McCartney', '', 'save' ) );
    126                 $this->assertEquals( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( '//songs by Lennon/McCartney', '', 'save' ) );
     122                $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon/McCartney', '', 'save' ) );
     123                $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon//McCartney', '', 'save' ) );
     124                $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon///McCartney', '', 'save' ) );
     125                $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon/-McCartney', '', 'save' ) );
     126                $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( '//songs by Lennon/McCartney', '', 'save' ) );
    127127        }
    128128
    … …  
    131131         */
    132132        function test_replaces_multiply_sign() {
    133                 $this->assertEquals( '6x7-is-42', sanitize_title_with_dashes( '6×7 is 42', '', 'save' ) );
     133                $this->assertSame( '6x7-is-42', sanitize_title_with_dashes( '6×7 is 42', '', 'save' ) );
    134134        }
    135135
    … …  
    138138         */
    139139        function test_replaces_standalone_diacritic() {
    140                 $this->assertEquals( 'aaaa', sanitize_title_with_dashes( 'āáǎà', '', 'save' ) );
     140                $this->assertSame( 'aaaa', sanitize_title_with_dashes( 'āáǎà', '', 'save' ) );
    141141        }
    142142
    … …  
    145145         */
    146146        function test_replaces_acute_accents() {
    147                 $this->assertEquals( 'aaaa', sanitize_title_with_dashes( 'ááa´aˊ', '', 'save' ) );
     147                $this->assertSame( 'aaaa', sanitize_title_with_dashes( 'ááa´aˊ', '', 'save' ) );
    148148        }
    149149
Note: See TracChangeset for help on using the changeset viewer.