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/pomo/po.php

    r47122 r48937  
    4444    function test_prepend_each_line() {
    4545        $po = new PO();
    46         $this->assertEquals( 'baba_', $po->prepend_each_line( '', 'baba_' ) );
    47         $this->assertEquals( 'baba_dyado', $po->prepend_each_line( 'dyado', 'baba_' ) );
    48         $this->assertEquals( "# baba\n# dyado\n# \n", $po->prepend_each_line( "baba\ndyado\n\n", '# ' ) );
     46        $this->assertSame( 'baba_', $po->prepend_each_line( '', 'baba_' ) );
     47        $this->assertSame( 'baba_dyado', $po->prepend_each_line( 'dyado', 'baba_' ) );
     48        $this->assertSame( "# baba\n# dyado\n# \n", $po->prepend_each_line( "baba\ndyado\n\n", '# ' ) );
    4949    }
    5050
     
    5252        $po = new PO();
    5353        // Simple.
    54         $this->assertEquals( '"baba"', $po->poify( 'baba' ) );
     54        $this->assertSame( '"baba"', $po->poify( 'baba' ) );
    5555        // Long word.
    56         $this->assertEquals( $this->po_a90, $po->poify( $this->a90 ) );
     56        $this->assertSame( $this->po_a90, $po->poify( $this->a90 ) );
    5757        // Tab.
    58         $this->assertEquals( '"ba\tba"', $po->poify( "ba\tba" ) );
     58        $this->assertSame( '"ba\tba"', $po->poify( "ba\tba" ) );
    5959        // Do not add leading empty string of one-line string ending on a newline.
    60         $this->assertEquals( '"\\\\a\\\\n\\n"', $po->poify( "\a\\n\n" ) );
     60        $this->assertSame( '"\\\\a\\\\n\\n"', $po->poify( "\a\\n\n" ) );
    6161        // Backslash.
    62         $this->assertEquals( '"ba\\\\ba"', $po->poify( 'ba\\ba' ) );
     62        $this->assertSame( '"ba\\\\ba"', $po->poify( 'ba\\ba' ) );
    6363        // Random wordpress.pot string.
    6464        $src = 'Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.';
    65         $this->assertEquals( '"Categories can be selectively converted to tags using the <a href=\\"%s\\">category to tag converter</a>."', $po->poify( $src ) );
    66 
    67         $this->assertEqualsIgnoreEOL( $this->po_mail, $po->poify( $this->mail ) );
     65        $this->assertSame( '"Categories can be selectively converted to tags using the <a href=\\"%s\\">category to tag converter</a>."', $po->poify( $src ) );
     66
     67        $this->assertSameIgnoreEOL( $this->po_mail, $po->poify( $this->mail ) );
    6868    }
    6969
    7070    function test_unpoify() {
    7171        $po = new PO();
    72         $this->assertEquals( 'baba', $po->unpoify( '"baba"' ) );
    73         $this->assertEquals( "baba\ngugu", $po->unpoify( '"baba\n"' . "\t\t\t\n" . '"gugu"' ) );
    74         $this->assertEquals( $this->a90, $po->unpoify( $this->po_a90 ) );
    75         $this->assertEquals( '\\t\\n', $po->unpoify( '"\\\\t\\\\n"' ) );
     72        $this->assertSame( 'baba', $po->unpoify( '"baba"' ) );
     73        $this->assertSame( "baba\ngugu", $po->unpoify( '"baba\n"' . "\t\t\t\n" . '"gugu"' ) );
     74        $this->assertSame( $this->a90, $po->unpoify( $this->po_a90 ) );
     75        $this->assertSame( '\\t\\n', $po->unpoify( '"\\\\t\\\\n"' ) );
    7676        // Wordwrapped.
    77         $this->assertEquals( 'babadyado', $po->unpoify( "\"\"\n\"baba\"\n\"dyado\"" ) );
    78         $this->assertEqualsIgnoreEOL( $this->mail, $po->unpoify( $this->po_mail ) );
     77        $this->assertSame( 'babadyado', $po->unpoify( "\"\"\n\"baba\"\n\"dyado\"" ) );
     78        $this->assertSameIgnoreEOL( $this->mail, $po->unpoify( $this->po_mail ) );
    7979    }
    8080
     
    8282        $po    = new PO();
    8383        $entry = new Translation_Entry( array( 'singular' => 'baba' ) );
    84         $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"", $po->export_entry( $entry ) );
     84        $this->assertSame( "msgid \"baba\"\nmsgstr \"\"", $po->export_entry( $entry ) );
    8585        // Plural.
    8686        $entry = new Translation_Entry(
     
    9090            )
    9191        );
    92         $this->assertEqualsIgnoreEOL(
     92        $this->assertSameIgnoreEOL(
    9393            'msgid "baba"
    9494msgid_plural "babas"
     
    103103            )
    104104        );
    105         $this->assertEqualsIgnoreEOL(
     105        $this->assertSameIgnoreEOL(
    106106            '#  baba
    107107#  dyado
     
    116116            )
    117117        );
    118         $this->assertEqualsIgnoreEOL(
     118        $this->assertSameIgnoreEOL(
    119119            '#. baba
    120120msgid "baba"
     
    129129            )
    130130        );
    131         $this->assertEqualsIgnoreEOL(
     131        $this->assertSameIgnoreEOL(
    132132            '#. baba
    133133#: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
     
    143143            )
    144144        );
    145         $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"", $po->export_entry( $entry ) );
     145        $this->assertSame( "msgid \"baba\"\nmsgstr \"\"", $po->export_entry( $entry ) );
    146146
    147147        $entry = new Translation_Entry(
     
    151151            )
    152152        );
    153         $this->assertEquals( "msgid \"baba\"\nmsgstr \"куку\"", $po->export_entry( $entry ) );
     153        $this->assertSame( "msgid \"baba\"\nmsgstr \"куку\"", $po->export_entry( $entry ) );
    154154
    155155        $entry = new Translation_Entry(
     
    160160            )
    161161        );
    162         $this->assertEqualsIgnoreEOL(
     162        $this->assertSameIgnoreEOL(
    163163            'msgid "baba"
    164164msgid_plural "babas"
     
    174174            )
    175175        );
    176         $this->assertEqualsIgnoreEOL(
     176        $this->assertSameIgnoreEOL(
    177177            'msgid "baba"
    178178msgid_plural "babas"
     
    192192            )
    193193        );
    194         $this->assertEqualsIgnoreEOL(
     194        $this->assertSameIgnoreEOL(
    195195            '#, fuzzy, php-format
    196196msgctxt "ctxt"
     
    210210        $po->add_entry( $entry );
    211211        $po->add_entry( $entry2 );
    212         $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export_entries() );
     212        $this->assertSame( "msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export_entries() );
    213213    }
    214214
     
    217217        $po->set_header( 'Project-Id-Version', 'WordPress 2.6-bleeding' );
    218218        $po->set_header( 'POT-Creation-Date', '2008-04-08 18:00+0000' );
    219         $this->assertEquals( "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: WordPress 2.6-bleeding\\n\"\n\"POT-Creation-Date: 2008-04-08 18:00+0000\\n\"", $po->export_headers() );
     219        $this->assertSame( "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: WordPress 2.6-bleeding\\n\"\n\"POT-Creation-Date: 2008-04-08 18:00+0000\\n\"", $po->export_headers() );
    220220    }
    221221
     
    228228        $po->add_entry( $entry );
    229229        $po->add_entry( $entry2 );
    230         $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export( false ) );
    231         $this->assertEquals( "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: WordPress 2.6-bleeding\\n\"\n\"POT-Creation-Date: 2008-04-08 18:00+0000\\n\"\n\nmsgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export() );
     230        $this->assertSame( "msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export( false ) );
     231        $this->assertSame( "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: WordPress 2.6-bleeding\\n\"\n\"POT-Creation-Date: 2008-04-08 18:00+0000\\n\"\n\nmsgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export() );
    232232    }
    233233
     
    244244        $temp_fn = $this->temp_filename();
    245245        $po->export_to_file( $temp_fn, false );
    246         $this->assertEquals( $po->export( false ), file_get_contents( $temp_fn ) );
     246        $this->assertSame( $po->export( false ), file_get_contents( $temp_fn ) );
    247247
    248248        $temp_fn2 = $this->temp_filename();
    249249        $po->export_to_file( $temp_fn2 );
    250         $this->assertEquals( $po->export(), file_get_contents( $temp_fn2 ) );
     250        $this->assertSame( $po->export(), file_get_contents( $temp_fn2 ) );
    251251    }
    252252
     
    254254        $po  = new PO();
    255255        $res = $po->import_from_file( DIR_TESTDATA . '/pomo/simple.po' );
    256         $this->assertEquals( true, $res );
    257 
    258         $this->assertEquals(
     256        $this->assertTrue( $res );
     257
     258        $this->assertSame(
    259259            array(
    260260                'Project-Id-Version' => 'WordPress 2.6-bleeding',
     
    318318        $po = new PO();
    319319        $this->assertTrue( $po->import_from_file( DIR_TESTDATA . '/pomo/windows-line-endings.po' ) );
    320         $this->assertEquals( 1, count( $po->entries ) );
     320        $this->assertSame( 1, count( $po->entries ) );
    321321    }
    322322
Note: See TracChangeset for help on using the changeset viewer.