WordPress.org

Make WordPress Core


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

    r47122 r48937  
    66class Tests_Formatting_RemoveAccents extends WP_UnitTestCase {
    77    public function test_remove_accents_simple() {
    8         $this->assertEquals( 'abcdefghijkl', remove_accents( 'abcdefghijkl' ) );
     8        $this->assertSame( 'abcdefghijkl', remove_accents( 'abcdefghijkl' ) );
    99    }
    1010
     
    1616        $output = 'aoAAAAAAAECEEEEIIIIDNOOOOOOUUUUYTHsaaaaaaaeceeeeiiiidnoooooouuuuythy';
    1717
    18         $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin-1 Supplement' );
     18        $this->assertSame( $output, remove_accents( $input ), 'remove_accents replaces Latin-1 Supplement' );
    1919    }
    2020
     
    2323        $output = 'AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkkLlLlLlLlLlNnNnNnnNnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs';
    2424
    25         $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin Extended A' );
     25        $this->assertSame( $output, remove_accents( $input ), 'remove_accents replaces Latin Extended A' );
    2626    }
    2727
    2828    public function test_remove_accents_latin_extended_b() {
    29         $this->assertEquals( 'SsTt', remove_accents( 'ȘșȚț' ), 'remove_accents replaces Latin Extended B' );
     29        $this->assertSame( 'SsTt', remove_accents( 'ȘșȚț' ), 'remove_accents replaces Latin Extended B' );
    3030    }
    3131
    3232    public function test_remove_accents_euro_pound_signs() {
    33         $this->assertEquals( 'E', remove_accents( '€' ), 'remove_accents replaces euro sign' );
    34         $this->assertEquals( '', remove_accents( '£' ), 'remove_accents replaces pound sign' );
     33        $this->assertSame( 'E', remove_accents( '€' ), 'remove_accents replaces euro sign' );
     34        $this->assertSame( '', remove_accents( '£' ), 'remove_accents replaces pound sign' );
    3535    }
    3636
     
    4242        $output = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyOEoeAEDHTHssaedhth';
    4343
    44         $this->assertEquals( $output, remove_accents( $input ), 'remove_accents from ISO-8859-1 text' );
     44        $this->assertSame( $output, remove_accents( $input ), 'remove_accents from ISO-8859-1 text' );
    4545    }
    4646
     
    5151        // Vowels with diacritic.
    5252        // Unmarked.
    53         $this->assertEquals( 'OoUu', remove_accents( 'ƠơƯư' ) );
     53        $this->assertSame( 'OoUu', remove_accents( 'ƠơƯư' ) );
    5454        // Grave accent.
    55         $this->assertEquals( 'AaAaEeOoOoUuYy', remove_accents( 'ẦầẰằỀềỒồỜờỪừỲỳ' ) );
     55        $this->assertSame( 'AaAaEeOoOoUuYy', remove_accents( 'ẦầẰằỀềỒồỜờỪừỲỳ' ) );
    5656        // Hook.
    57         $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẢảẨẩẲẳẺẻỂểỈỉỎỏỔổỞởỦủỬửỶỷ' ) );
     57        $this->assertSame( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẢảẨẩẲẳẺẻỂểỈỉỎỏỔổỞởỦủỬửỶỷ' ) );
    5858        // Tilde.
    59         $this->assertEquals( 'AaAaEeEeOoOoUuYy', remove_accents( 'ẪẫẴẵẼẽỄễỖỗỠỡỮữỸỹ' ) );
     59        $this->assertSame( 'AaAaEeEeOoOoUuYy', remove_accents( 'ẪẫẴẵẼẽỄễỖỗỠỡỮữỸỹ' ) );
    6060        // Acute accent.
    61         $this->assertEquals( 'AaAaEeOoOoUu', remove_accents( 'ẤấẮắẾếỐốỚớỨứ' ) );
     61        $this->assertSame( 'AaAaEeOoOoUu', remove_accents( 'ẤấẮắẾếỐốỚớỨứ' ) );
    6262        // Dot below.
    63         $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẠạẬậẶặẸẹỆệỊịỌọỘộỢợỤụỰựỴỵ' ) );
     63        $this->assertSame( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẠạẬậẶặẸẹỆệỊịỌọỘộỢợỤụỰựỴỵ' ) );
    6464    }
    6565
     
    7070        // Vowels with diacritic (Chinese, Hanyu Pinyin).
    7171        // Macron.
    72         $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'āēīōūǖĀĒĪŌŪǕ' ) );
     72        $this->assertSame( 'aeiouuAEIOUU', remove_accents( 'āēīōūǖĀĒĪŌŪǕ' ) );
    7373        // Acute accent.
    74         $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'áéíóúǘÁÉÍÓÚǗ' ) );
     74        $this->assertSame( 'aeiouuAEIOUU', remove_accents( 'áéíóúǘÁÉÍÓÚǗ' ) );
    7575        // Caron.
    76         $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'ǎěǐǒǔǚǍĚǏǑǓǙ' ) );
     76        $this->assertSame( 'aeiouuAEIOUU', remove_accents( 'ǎěǐǒǔǚǍĚǏǑǓǙ' ) );
    7777        // Grave accent.
    78         $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'àèìòùǜÀÈÌÒÙǛ' ) );
     78        $this->assertSame( 'aeiouuAEIOUU', remove_accents( 'àèìòùǜÀÈÌÒÙǛ' ) );
    7979        // Unmarked.
    80         $this->assertEquals( 'aaeiouuAEIOUU', remove_accents( 'aɑeiouüAEIOUÜ' ) );
     80        $this->assertSame( 'aaeiouuAEIOUU', remove_accents( 'aɑeiouüAEIOUÜ' ) );
    8181    }
    8282
     
    9191        add_filter( 'locale', array( $this, '_remove_accents_germanic_umlauts_cb' ) );
    9292
    93         $this->assertEquals( 'AeOeUeaeoeuess', remove_accents( 'ÄÖÜäöüß' ) );
     93        $this->assertSame( 'AeOeUeaeoeuess', remove_accents( 'ÄÖÜäöüß' ) );
    9494
    9595        remove_filter( 'locale', array( $this, '_remove_accents_germanic_umlauts_cb' ) );
     
    106106        add_filter( 'locale', array( $this, '_set_locale_to_danish' ) );
    107107
    108         $this->assertEquals( 'AeOeAaaeoeaa', remove_accents( 'ÆØÅæøå' ) );
     108        $this->assertSame( 'AeOeAaaeoeaa', remove_accents( 'ÆØÅæøå' ) );
    109109
    110110        remove_filter( 'locale', array( $this, '_set_locale_to_danish' ) );
     
    121121        add_filter( 'locale', array( $this, '_set_locale_to_catalan' ) );
    122122
    123         $this->assertEquals( 'allallalla', remove_accents( 'al·lallaŀla' ) );
     123        $this->assertSame( 'allallalla', remove_accents( 'al·lallaŀla' ) );
    124124
    125125        remove_filter( 'locale', array( $this, '_set_locale_to_catalan' ) );
    126126
    127         $this->assertEquals( 'al·lallalla', remove_accents( 'al·lallaŀla' ) );
     127        $this->assertSame( 'al·lallalla', remove_accents( 'al·lallaŀla' ) );
    128128    }
    129129
     
    138138        add_filter( 'locale', array( $this, '_set_locale_to_serbian' ) );
    139139
    140         $this->assertEquals( 'DJdj', remove_accents( 'Đđ' ) );
     140        $this->assertSame( 'DJdj', remove_accents( 'Đđ' ) );
    141141
    142142        remove_filter( 'locale', array( $this, '_set_locale_to_serbian' ) );
    143143
    144         $this->assertEquals( 'Dd', remove_accents( 'Đđ' ) );
     144        $this->assertSame( 'Dd', remove_accents( 'Đđ' ) );
    145145    }
    146146}
Note: See TracChangeset for help on using the changeset viewer.