WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (4 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/pomo/po.php

    r41722 r42343  
    88        require_once ABSPATH . '/wp-includes/pomo/po.php';
    99        // not so random wordpress.pot string -- multiple lines
    10         $this->mail = "Your new WordPress blog has been successfully set up at:
    11 
    12 %1\$s
     10        $this->mail    = 'Your new WordPress blog has been successfully set up at:
     11
     12%1$s
    1313
    1414You can log in to the administrator account with the following information:
    1515
    16 Username: %2\$s
    17 Password: %3\$s
     16Username: %2$s
     17Password: %3$s
    1818
    1919We hope you enjoy your new blog. Thanks!
     
    2121--The WordPress Team
    2222http://wordpress.org/
    23 ";
    24     $this->po_mail = '""
     23';
     24        $this->po_mail = '""
    2525"Your new WordPress blog has been successfully set up at:\n"
    2626"\n"
     
    3636"--The WordPress Team\n"
    3737"http://wordpress.org/\n"';
    38         $this->a90 = str_repeat("a", 90);
    39         $this->po_a90 = "\"$this->a90\"";
    40     }
     38        $this->a90     = str_repeat( 'a', 90 );
     39        $this->po_a90  = "\"$this->a90\"";
     40    }
    4141
    4242    function test_prepend_each_line() {
    4343        $po = new PO();
    44         $this->assertEquals('baba_', $po->prepend_each_line('', 'baba_'));
    45         $this->assertEquals('baba_dyado', $po->prepend_each_line('dyado', 'baba_'));
    46         $this->assertEquals("# baba\n# dyado\n# \n", $po->prepend_each_line("baba\ndyado\n\n", '# '));
     44        $this->assertEquals( 'baba_', $po->prepend_each_line( '', 'baba_' ) );
     45        $this->assertEquals( 'baba_dyado', $po->prepend_each_line( 'dyado', 'baba_' ) );
     46        $this->assertEquals( "# baba\n# dyado\n# \n", $po->prepend_each_line( "baba\ndyado\n\n", '# ' ) );
    4747    }
    4848
     
    5050        $po = new PO();
    5151        //simple
    52         $this->assertEquals('"baba"', $po->poify('baba'));
     52        $this->assertEquals( '"baba"', $po->poify( 'baba' ) );
    5353        //long word
    54         $this->assertEquals($this->po_a90, $po->poify($this->a90));
     54        $this->assertEquals( $this->po_a90, $po->poify( $this->a90 ) );
    5555        // tab
    56         $this->assertEquals('"ba\tba"', $po->poify("ba\tba"));
     56        $this->assertEquals( '"ba\tba"', $po->poify( "ba\tba" ) );
    5757        // do not add leading empty string of one-line string ending on a newline
    58         $this->assertEquals('"\\\\a\\\\n\\n"', $po->poify("\a\\n\n"));
     58        $this->assertEquals( '"\\\\a\\\\n\\n"', $po->poify( "\a\\n\n" ) );
    5959        // backslash
    60         $this->assertEquals('"ba\\\\ba"', $po->poify('ba\\ba'));
     60        $this->assertEquals( '"ba\\\\ba"', $po->poify( 'ba\\ba' ) );
    6161        // random wordpress.pot string
    6262        $src = 'Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.';
    63         $this->assertEquals("\"Categories can be selectively converted to tags using the <a href=\\\"%s\\\">category to tag converter</a>.\"", $po->poify($src));
    64 
    65         $this->assertEquals($this->po_mail, $po->poify($this->mail));
     63        $this->assertEquals( '"Categories can be selectively converted to tags using the <a href=\\"%s\\">category to tag converter</a>."', $po->poify( $src ) );
     64
     65        $this->assertEquals( $this->po_mail, $po->poify( $this->mail ) );
    6666    }
    6767
    6868    function test_unpoify() {
    6969        $po = new PO();
    70         $this->assertEquals('baba', $po->unpoify('"baba"'));
    71         $this->assertEquals("baba\ngugu", $po->unpoify('"baba\n"'."\t\t\t\n".'"gugu"'));
    72         $this->assertEquals($this->a90, $po->unpoify($this->po_a90));
    73         $this->assertEquals('\\t\\n', $po->unpoify('"\\\\t\\\\n"'));
     70        $this->assertEquals( 'baba', $po->unpoify( '"baba"' ) );
     71        $this->assertEquals( "baba\ngugu", $po->unpoify( '"baba\n"' . "\t\t\t\n" . '"gugu"' ) );
     72        $this->assertEquals( $this->a90, $po->unpoify( $this->po_a90 ) );
     73        $this->assertEquals( '\\t\\n', $po->unpoify( '"\\\\t\\\\n"' ) );
    7474        // wordwrapped
    75         $this->assertEquals('babadyado', $po->unpoify("\"\"\n\"baba\"\n\"dyado\""));
    76         $this->assertEquals($this->mail, $po->unpoify($this->po_mail));
     75        $this->assertEquals( 'babadyado', $po->unpoify( "\"\"\n\"baba\"\n\"dyado\"" ) );
     76        $this->assertEquals( $this->mail, $po->unpoify( $this->po_mail ) );
    7777    }
    7878
    7979    function test_export_entry() {
    80         $po = new PO();
    81         $entry = new Translation_Entry(array('singular' => 'baba'));
    82         $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", $po->export_entry($entry));
     80        $po    = new PO();
     81        $entry = new Translation_Entry( array( 'singular' => 'baba' ) );
     82        $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"", $po->export_entry( $entry ) );
    8383        // plural
    84         $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas'));
    85         $this->assertEquals('msgid "baba"
     84        $entry = new Translation_Entry(
     85            array(
     86                'singular' => 'baba',
     87                'plural'   => 'babas',
     88            )
     89        );
     90        $this->assertEquals(
     91            'msgid "baba"
    8692msgid_plural "babas"
    8793msgstr[0] ""
    88 msgstr[1] ""', $po->export_entry($entry));
    89         $entry = new Translation_Entry(array('singular' => 'baba', 'translator_comments' => "baba\ndyado"));
    90         $this->assertEquals('#  baba
     94msgstr[1] ""', $po->export_entry( $entry )
     95        );
     96        $entry = new Translation_Entry(
     97            array(
     98                'singular'            => 'baba',
     99                'translator_comments' => "baba\ndyado",
     100            )
     101        );
     102        $this->assertEquals(
     103            '#  baba
    91104#  dyado
    92105msgid "baba"
    93 msgstr ""', $po->export_entry($entry));
    94         $entry = new Translation_Entry(array('singular' => 'baba', 'extracted_comments' => "baba"));
    95         $this->assertEquals('#. baba
     106msgstr ""', $po->export_entry( $entry )
     107        );
     108        $entry = new Translation_Entry(
     109            array(
     110                'singular'           => 'baba',
     111                'extracted_comments' => 'baba',
     112            )
     113        );
     114        $this->assertEquals(
     115            '#. baba
    96116msgid "baba"
    97 msgstr ""', $po->export_entry($entry));
    98         $entry = new Translation_Entry(array(
    99             'singular' => 'baba',
    100             'extracted_comments' => "baba",
    101             'references' => range(1, 29)));
    102         $this->assertEquals('#. baba
     117msgstr ""', $po->export_entry( $entry )
     118        );
     119        $entry = new Translation_Entry(
     120            array(
     121                'singular'           => 'baba',
     122                'extracted_comments' => 'baba',
     123                'references'         => range( 1, 29 ),
     124            )
     125        );
     126        $this->assertEquals(
     127            '#. baba
    103128#: 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
    104129#: 29
    105130msgid "baba"
    106 msgstr ""', $po->export_entry($entry));
    107         $entry = new Translation_Entry(array('singular' => 'baba', 'translations' => array()));
    108         $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", $po->export_entry($entry));
    109 
    110         $entry = new Translation_Entry(array('singular' => 'baba', 'translations' => array('куку', 'буку')));
    111         $this->assertEquals("msgid \"baba\"\nmsgstr \"куку\"", $po->export_entry($entry));
    112 
    113         $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку')));
    114         $this->assertEquals('msgid "baba"
     131msgstr ""', $po->export_entry( $entry )
     132        );
     133        $entry = new Translation_Entry(
     134            array(
     135                'singular'     => 'baba',
     136                'translations' => array(),
     137            )
     138        );
     139        $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"", $po->export_entry( $entry ) );
     140
     141        $entry = new Translation_Entry(
     142            array(
     143                'singular'     => 'baba',
     144                'translations' => array( 'куку', 'буку' ),
     145            )
     146        );
     147        $this->assertEquals( "msgid \"baba\"\nmsgstr \"куку\"", $po->export_entry( $entry ) );
     148
     149        $entry = new Translation_Entry(
     150            array(
     151                'singular'     => 'baba',
     152                'plural'       => 'babas',
     153                'translations' => array( 'кукубуку' ),
     154            )
     155        );
     156        $this->assertEquals(
     157            'msgid "baba"
    115158msgid_plural "babas"
    116 msgstr[0] "кукубуку"', $po->export_entry($entry));
    117 
    118         $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку', 'кукуруку', 'бабаяга')));
    119         $this->assertEquals('msgid "baba"
     159msgstr[0] "кукубуку"', $po->export_entry( $entry )
     160        );
     161
     162        $entry = new Translation_Entry(
     163            array(
     164                'singular'     => 'baba',
     165                'plural'       => 'babas',
     166                'translations' => array( 'кукубуку', 'кукуруку', 'бабаяга' ),
     167            )
     168        );
     169        $this->assertEquals(
     170            'msgid "baba"
    120171msgid_plural "babas"
    121172msgstr[0] "кукубуку"
    122173msgstr[1] "кукуруку"
    123 msgstr[2] "бабаяга"', $po->export_entry($entry));
     174msgstr[2] "бабаяга"', $po->export_entry( $entry )
     175        );
    124176        // context
    125         $entry = new Translation_Entry(array('context' => 'ctxt', 'singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку', 'кукуруку', 'бабаяга'), 'flags' => array('fuzzy', 'php-format')));
    126         $this->assertEquals('#, fuzzy, php-format
     177        $entry = new Translation_Entry(
     178            array(
     179                'context'      => 'ctxt',
     180                'singular'     => 'baba',
     181                'plural'       => 'babas',
     182                'translations' => array( 'кукубуку', 'кукуруку', 'бабаяга' ),
     183                'flags'        => array( 'fuzzy', 'php-format' ),
     184            )
     185        );
     186        $this->assertEquals(
     187            '#, fuzzy, php-format
    127188msgctxt "ctxt"
    128189msgid "baba"
     
    130191msgstr[0] "кукубуку"
    131192msgstr[1] "кукуруку"
    132 msgstr[2] "бабаяга"', $po->export_entry($entry));
    133     }
     193msgstr[2] "бабаяга"', $po->export_entry( $entry )
     194        );
     195    }
    134196
    135197    function test_export_entries() {
    136         $entry = new Translation_Entry(array('singular' => 'baba',));
    137         $entry2 = new Translation_Entry(array('singular' => 'dyado',));
    138         $po = new PO();
    139         $po->add_entry($entry);
    140         $po->add_entry($entry2);
    141         $this->assertEquals("msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export_entries());
     198        $entry  = new Translation_Entry( array( 'singular' => 'baba' ) );
     199        $entry2 = new Translation_Entry( array( 'singular' => 'dyado' ) );
     200        $po     = new PO();
     201        $po->add_entry( $entry );
     202        $po->add_entry( $entry2 );
     203        $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export_entries() );
    142204    }
    143205
    144206    function test_export_headers() {
    145207        $po = new PO();
    146         $po->set_header('Project-Id-Version', 'WordPress 2.6-bleeding');
    147         $po->set_header('POT-Creation-Date', '2008-04-08 18:00+0000');
    148         $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());
     208        $po->set_header( 'Project-Id-Version', 'WordPress 2.6-bleeding' );
     209        $po->set_header( 'POT-Creation-Date', '2008-04-08 18:00+0000' );
     210        $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() );
    149211    }
    150212
    151213    function test_export() {
    152         $po = new PO();
    153         $entry = new Translation_Entry(array('singular' => 'baba',));
    154         $entry2 = new Translation_Entry(array('singular' => 'dyado',));
    155         $po->set_header('Project-Id-Version', 'WordPress 2.6-bleeding');
    156         $po->set_header('POT-Creation-Date', '2008-04-08 18:00+0000');
    157         $po->add_entry($entry);
    158         $po->add_entry($entry2);
    159         $this->assertEquals("msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export(false));
    160         $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());
     214        $po     = new PO();
     215        $entry  = new Translation_Entry( array( 'singular' => 'baba' ) );
     216        $entry2 = new Translation_Entry( array( 'singular' => 'dyado' ) );
     217        $po->set_header( 'Project-Id-Version', 'WordPress 2.6-bleeding' );
     218        $po->set_header( 'POT-Creation-Date', '2008-04-08 18:00+0000' );
     219        $po->add_entry( $entry );
     220        $po->add_entry( $entry2 );
     221        $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export( false ) );
     222        $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() );
    161223    }
    162224
    163225
    164226    function test_export_to_file() {
    165         $po = new PO();
    166         $entry = new Translation_Entry(array('singular' => 'baba',));
    167         $entry2 = new Translation_Entry(array('singular' => 'dyado',));
    168         $po->set_header('Project-Id-Version', 'WordPress 2.6-bleeding');
    169         $po->set_header('POT-Creation-Date', '2008-04-08 18:00+0000');
    170         $po->add_entry($entry);
    171         $po->add_entry($entry2);
     227        $po     = new PO();
     228        $entry  = new Translation_Entry( array( 'singular' => 'baba' ) );
     229        $entry2 = new Translation_Entry( array( 'singular' => 'dyado' ) );
     230        $po->set_header( 'Project-Id-Version', 'WordPress 2.6-bleeding' );
     231        $po->set_header( 'POT-Creation-Date', '2008-04-08 18:00+0000' );
     232        $po->add_entry( $entry );
     233        $po->add_entry( $entry2 );
    172234
    173235        $temp_fn = $this->temp_filename();
    174         $po->export_to_file($temp_fn, false);
    175         $this->assertEquals($po->export(false), file_get_contents($temp_fn));
     236        $po->export_to_file( $temp_fn, false );
     237        $this->assertEquals( $po->export( false ), file_get_contents( $temp_fn ) );
    176238
    177239        $temp_fn2 = $this->temp_filename();
    178         $po->export_to_file($temp_fn2);
    179         $this->assertEquals($po->export(), file_get_contents($temp_fn2));
     240        $po->export_to_file( $temp_fn2 );
     241        $this->assertEquals( $po->export(), file_get_contents( $temp_fn2 ) );
    180242    }
    181243
    182244    function test_import_from_file() {
    183         $po = new PO();
    184         $res = $po->import_from_file(DIR_TESTDATA . '/pomo/simple.po');
    185         $this->assertEquals(true, $res);
    186 
    187         $this->assertEquals(array('Project-Id-Version' => 'WordPress 2.6-bleeding', 'Plural-Forms' => 'nplurals=2; plural=n != 1;'), $po->headers);
    188 
    189         $simple_entry = new Translation_Entry(array('singular' => 'moon',));
    190         $this->assertEquals($simple_entry, $po->entries[$simple_entry->key()]);
    191 
    192         $all_types_entry = new Translation_Entry(array('singular' => 'strut', 'plural' => 'struts', 'context' => 'brum',
    193             'translations' => array('ztrut0', 'ztrut1', 'ztrut2')));
    194         $this->assertEquals($all_types_entry, $po->entries[$all_types_entry->key()]);
    195 
    196         $multiple_line_entry = new Translation_Entry(array('singular' => 'The first thing you need to do is tell Blogger to let WordPress access your account. You will be sent back here after providing authorization.', 'translations' => array("baba\ndyadogugu")));
    197         $this->assertEquals($multiple_line_entry, $po->entries[$multiple_line_entry->key()]);
    198 
    199         $multiple_line_all_types_entry = new Translation_Entry(array('context' => 'context', 'singular' => 'singular',
    200             'plural' => 'plural', 'translations' => array('translation0', 'translation1', 'translation2')));
    201         $this->assertEquals($multiple_line_all_types_entry, $po->entries[$multiple_line_all_types_entry->key()]);
    202 
    203         $comments_entry = new Translation_Entry(array('singular' => 'a', 'translator_comments' => "baba\nbrubru",
    204             'references' => array('wp-admin/x.php:111', 'baba:333', 'baba'), 'extracted_comments' => "translators: buuu",
    205             'flags' => array('fuzzy')));
    206         $this->assertEquals($comments_entry, $po->entries[$comments_entry->key()]);
    207 
    208         $end_quote_entry = new Translation_Entry(array('singular' => 'a"'));
    209         $this->assertEquals($end_quote_entry, $po->entries[$end_quote_entry->key()]);
     245        $po  = new PO();
     246        $res = $po->import_from_file( DIR_TESTDATA . '/pomo/simple.po' );
     247        $this->assertEquals( true, $res );
     248
     249        $this->assertEquals(
     250            array(
     251                'Project-Id-Version' => 'WordPress 2.6-bleeding',
     252                'Plural-Forms'       => 'nplurals=2; plural=n != 1;',
     253            ), $po->headers
     254        );
     255
     256        $simple_entry = new Translation_Entry( array( 'singular' => 'moon' ) );
     257        $this->assertEquals( $simple_entry, $po->entries[ $simple_entry->key() ] );
     258
     259        $all_types_entry = new Translation_Entry(
     260            array(
     261                'singular'     => 'strut',
     262                'plural'       => 'struts',
     263                'context'      => 'brum',
     264                'translations' => array( 'ztrut0', 'ztrut1', 'ztrut2' ),
     265            )
     266        );
     267        $this->assertEquals( $all_types_entry, $po->entries[ $all_types_entry->key() ] );
     268
     269        $multiple_line_entry = new Translation_Entry(
     270            array(
     271                'singular'     => 'The first thing you need to do is tell Blogger to let WordPress access your account. You will be sent back here after providing authorization.',
     272                'translations' => array( "baba\ndyadogugu" ),
     273            )
     274        );
     275        $this->assertEquals( $multiple_line_entry, $po->entries[ $multiple_line_entry->key() ] );
     276
     277        $multiple_line_all_types_entry = new Translation_Entry(
     278            array(
     279                'context'      => 'context',
     280                'singular'     => 'singular',
     281                'plural'       => 'plural',
     282                'translations' => array( 'translation0', 'translation1', 'translation2' ),
     283            )
     284        );
     285        $this->assertEquals( $multiple_line_all_types_entry, $po->entries[ $multiple_line_all_types_entry->key() ] );
     286
     287        $comments_entry = new Translation_Entry(
     288            array(
     289                'singular'            => 'a',
     290                'translator_comments' => "baba\nbrubru",
     291                'references'          => array( 'wp-admin/x.php:111', 'baba:333', 'baba' ),
     292                'extracted_comments'  => 'translators: buuu',
     293                'flags'               => array( 'fuzzy' ),
     294            )
     295        );
     296        $this->assertEquals( $comments_entry, $po->entries[ $comments_entry->key() ] );
     297
     298        $end_quote_entry = new Translation_Entry( array( 'singular' => 'a"' ) );
     299        $this->assertEquals( $end_quote_entry, $po->entries[ $end_quote_entry->key() ] );
    210300    }
    211301
     
    223313    //TODO: add tests for bad files
    224314}
    225 ?>
     315
Note: See TracChangeset for help on using the changeset viewer.