Changeset 42343 for trunk/tests/phpunit/tests/pomo/po.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/pomo/po.php
r41722 r42343 8 8 require_once ABSPATH . '/wp-includes/pomo/po.php'; 9 9 // not so random wordpress.pot string -- multiple lines 10 $this->mail = "Your new WordPress blog has been successfully set up at:11 12 %1 \$s10 $this->mail = 'Your new WordPress blog has been successfully set up at: 11 12 %1$s 13 13 14 14 You can log in to the administrator account with the following information: 15 15 16 Username: %2 \$s17 Password: %3 \$s16 Username: %2$s 17 Password: %3$s 18 18 19 19 We hope you enjoy your new blog. Thanks! … … 21 21 --The WordPress Team 22 22 http://wordpress.org/ 23 ";24 $this->po_mail = '""23 '; 24 $this->po_mail = '"" 25 25 "Your new WordPress blog has been successfully set up at:\n" 26 26 "\n" … … 36 36 "--The WordPress Team\n" 37 37 "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 } 41 41 42 42 function test_prepend_each_line() { 43 43 $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", '# ' ) ); 47 47 } 48 48 … … 50 50 $po = new PO(); 51 51 //simple 52 $this->assertEquals( '"baba"', $po->poify('baba'));52 $this->assertEquals( '"baba"', $po->poify( 'baba' ) ); 53 53 //long word 54 $this->assertEquals( $this->po_a90, $po->poify($this->a90));54 $this->assertEquals( $this->po_a90, $po->poify( $this->a90 ) ); 55 55 // tab 56 $this->assertEquals( '"ba\tba"', $po->poify("ba\tba"));56 $this->assertEquals( '"ba\tba"', $po->poify( "ba\tba" ) ); 57 57 // 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" ) ); 59 59 // backslash 60 $this->assertEquals( '"ba\\\\ba"', $po->poify('ba\\ba'));60 $this->assertEquals( '"ba\\\\ba"', $po->poify( 'ba\\ba' ) ); 61 61 // random wordpress.pot string 62 62 $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 ) ); 66 66 } 67 67 68 68 function test_unpoify() { 69 69 $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"' ) ); 74 74 // 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 ) ); 77 77 } 78 78 79 79 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 ) ); 83 83 // 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" 86 92 msgid_plural "babas" 87 93 msgstr[0] "" 88 msgstr[1] ""', $po->export_entry($entry)); 89 $entry = new Translation_Entry(array('singular' => 'baba', 'translator_comments' => "baba\ndyado")); 90 $this->assertEquals('# baba 94 msgstr[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 91 104 # dyado 92 105 msgid "baba" 93 msgstr ""', $po->export_entry($entry)); 94 $entry = new Translation_Entry(array('singular' => 'baba', 'extracted_comments' => "baba")); 95 $this->assertEquals('#. baba 106 msgstr ""', $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 96 116 msgid "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 117 msgstr ""', $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 103 128 #: 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 104 129 #: 29 105 130 msgid "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" 131 msgstr ""', $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" 115 158 msgid_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" 159 msgstr[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" 120 171 msgid_plural "babas" 121 172 msgstr[0] "кукубуку" 122 173 msgstr[1] "кукуруку" 123 msgstr[2] "бабаяга"', $po->export_entry($entry)); 174 msgstr[2] "бабаяга"', $po->export_entry( $entry ) 175 ); 124 176 // 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 127 188 msgctxt "ctxt" 128 189 msgid "baba" … … 130 191 msgstr[0] "кукубуку" 131 192 msgstr[1] "кукуруку" 132 msgstr[2] "бабаяга"', $po->export_entry($entry)); 133 } 193 msgstr[2] "бабаяга"', $po->export_entry( $entry ) 194 ); 195 } 134 196 135 197 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() ); 142 204 } 143 205 144 206 function test_export_headers() { 145 207 $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() ); 149 211 } 150 212 151 213 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() ); 161 223 } 162 224 163 225 164 226 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 ); 172 234 173 235 $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 ) ); 176 238 177 239 $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 ) ); 180 242 } 181 243 182 244 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() ] ); 210 300 } 211 301 … … 223 313 //TODO: add tests for bad files 224 314 } 225 ?> 315
Note: See TracChangeset
for help on using the changeset viewer.