MediaWiki
master
|
00001 <?php 00002 00003 class LanguageTest extends LanguageClassesTestCase { 00004 00005 function testLanguageConvertDoubleWidthToSingleWidth() { 00006 $this->assertEquals( 00007 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 00008 $this->getLang()->normalizeForSearch( 00009 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 00010 ), 00011 'convertDoubleWidth() with the full alphabet and digits' 00012 ); 00013 } 00014 00018 function testFormatTimePeriod( $seconds, $format, $expected, $desc ) { 00019 $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc ); 00020 } 00021 00022 function provideFormattableTimes() { 00023 return array( 00024 array( 00025 9.45, 00026 array(), 00027 '9.5 s', 00028 'formatTimePeriod() rounding (<10s)' 00029 ), 00030 array( 00031 9.45, 00032 array( 'noabbrevs' => true ), 00033 '9.5 seconds', 00034 'formatTimePeriod() rounding (<10s)' 00035 ), 00036 array( 00037 9.95, 00038 array(), 00039 '10 s', 00040 'formatTimePeriod() rounding (<10s)' 00041 ), 00042 array( 00043 9.95, 00044 array( 'noabbrevs' => true ), 00045 '10 seconds', 00046 'formatTimePeriod() rounding (<10s)' 00047 ), 00048 array( 00049 59.55, 00050 array(), 00051 '1 min 0 s', 00052 'formatTimePeriod() rounding (<60s)' 00053 ), 00054 array( 00055 59.55, 00056 array( 'noabbrevs' => true ), 00057 '1 minute 0 seconds', 00058 'formatTimePeriod() rounding (<60s)' 00059 ), 00060 array( 00061 119.55, 00062 array(), 00063 '2 min 0 s', 00064 'formatTimePeriod() rounding (<1h)' 00065 ), 00066 array( 00067 119.55, 00068 array( 'noabbrevs' => true ), 00069 '2 minutes 0 seconds', 00070 'formatTimePeriod() rounding (<1h)' 00071 ), 00072 array( 00073 3599.55, 00074 array(), 00075 '1 h 0 min 0 s', 00076 'formatTimePeriod() rounding (<1h)' 00077 ), 00078 array( 00079 3599.55, 00080 array( 'noabbrevs' => true ), 00081 '1 hour 0 minutes 0 seconds', 00082 'formatTimePeriod() rounding (<1h)' 00083 ), 00084 array( 00085 7199.55, 00086 array(), 00087 '2 h 0 min 0 s', 00088 'formatTimePeriod() rounding (>=1h)' 00089 ), 00090 array( 00091 7199.55, 00092 array( 'noabbrevs' => true ), 00093 '2 hours 0 minutes 0 seconds', 00094 'formatTimePeriod() rounding (>=1h)' 00095 ), 00096 array( 00097 7199.55, 00098 'avoidseconds', 00099 '2 h 0 min', 00100 'formatTimePeriod() rounding (>=1h), avoidseconds' 00101 ), 00102 array( 00103 7199.55, 00104 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), 00105 '2 hours 0 minutes', 00106 'formatTimePeriod() rounding (>=1h), avoidseconds' 00107 ), 00108 array( 00109 7199.55, 00110 'avoidminutes', 00111 '2 h 0 min', 00112 'formatTimePeriod() rounding (>=1h), avoidminutes' 00113 ), 00114 array( 00115 7199.55, 00116 array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ), 00117 '2 hours 0 minutes', 00118 'formatTimePeriod() rounding (>=1h), avoidminutes' 00119 ), 00120 array( 00121 172799.55, 00122 'avoidseconds', 00123 '48 h 0 min', 00124 'formatTimePeriod() rounding (=48h), avoidseconds' 00125 ), 00126 array( 00127 172799.55, 00128 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), 00129 '48 hours 0 minutes', 00130 'formatTimePeriod() rounding (=48h), avoidseconds' 00131 ), 00132 array( 00133 259199.55, 00134 'avoidminutes', 00135 '3 d 0 h', 00136 'formatTimePeriod() rounding (>48h), avoidminutes' 00137 ), 00138 array( 00139 259199.55, 00140 array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ), 00141 '3 days 0 hours', 00142 'formatTimePeriod() rounding (>48h), avoidminutes' 00143 ), 00144 array( 00145 176399.55, 00146 'avoidseconds', 00147 '2 d 1 h 0 min', 00148 'formatTimePeriod() rounding (>48h), avoidseconds' 00149 ), 00150 array( 00151 176399.55, 00152 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), 00153 '2 days 1 hour 0 minutes', 00154 'formatTimePeriod() rounding (>48h), avoidseconds' 00155 ), 00156 array( 00157 176399.55, 00158 'avoidminutes', 00159 '2 d 1 h', 00160 'formatTimePeriod() rounding (>48h), avoidminutes' 00161 ), 00162 array( 00163 176399.55, 00164 array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ), 00165 '2 days 1 hour', 00166 'formatTimePeriod() rounding (>48h), avoidminutes' 00167 ), 00168 array( 00169 259199.55, 00170 'avoidseconds', 00171 '3 d 0 h 0 min', 00172 'formatTimePeriod() rounding (>48h), avoidseconds' 00173 ), 00174 array( 00175 259199.55, 00176 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), 00177 '3 days 0 hours 0 minutes', 00178 'formatTimePeriod() rounding (>48h), avoidseconds' 00179 ), 00180 array( 00181 172801.55, 00182 'avoidseconds', 00183 '2 d 0 h 0 min', 00184 'formatTimePeriod() rounding, (>48h), avoidseconds' 00185 ), 00186 array( 00187 172801.55, 00188 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), 00189 '2 days 0 hours 0 minutes', 00190 'formatTimePeriod() rounding, (>48h), avoidseconds' 00191 ), 00192 array( 00193 176460.55, 00194 array(), 00195 '2 d 1 h 1 min 1 s', 00196 'formatTimePeriod() rounding, recursion, (>48h)' 00197 ), 00198 array( 00199 176460.55, 00200 array( 'noabbrevs' => true ), 00201 '2 days 1 hour 1 minute 1 second', 00202 'formatTimePeriod() rounding, recursion, (>48h)' 00203 ), 00204 ); 00205 00206 } 00207 00208 function testTruncate() { 00209 $this->assertEquals( 00210 "XXX", 00211 $this->getLang()->truncate( "1234567890", 0, 'XXX' ), 00212 'truncate prefix, len 0, small ellipsis' 00213 ); 00214 00215 $this->assertEquals( 00216 "12345XXX", 00217 $this->getLang()->truncate( "1234567890", 8, 'XXX' ), 00218 'truncate prefix, small ellipsis' 00219 ); 00220 00221 $this->assertEquals( 00222 "123456789", 00223 $this->getLang()->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ), 00224 'truncate prefix, large ellipsis' 00225 ); 00226 00227 $this->assertEquals( 00228 "XXX67890", 00229 $this->getLang()->truncate( "1234567890", -8, 'XXX' ), 00230 'truncate suffix, small ellipsis' 00231 ); 00232 00233 $this->assertEquals( 00234 "123456789", 00235 $this->getLang()->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ), 00236 'truncate suffix, large ellipsis' 00237 ); 00238 } 00239 00243 function testTruncateHtml( $len, $ellipsis, $input, $expected ) { 00244 // Actual HTML... 00245 $this->assertEquals( 00246 $expected, 00247 $this->getLang()->truncateHTML( $input, $len, $ellipsis ) 00248 ); 00249 } 00250 00254 function provideHTMLTruncateData() { 00255 return array( 00256 array( 0, 'XXX', "1234567890", "XXX" ), 00257 array( 8, 'XXX', "1234567890", "12345XXX" ), 00258 array( 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ), 00259 array( 2, '***', 00260 '<p><span style="font-weight:bold;"></span></p>', 00261 '<p><span style="font-weight:bold;"></span></p>', 00262 ), 00263 array( 2, '***', 00264 '<p><span style="font-weight:bold;">123456789</span></p>', 00265 '<p><span style="font-weight:bold;">***</span></p>', 00266 ), 00267 array( 2, '***', 00268 '<p><span style="font-weight:bold;"> 23456789</span></p>', 00269 '<p><span style="font-weight:bold;">***</span></p>', 00270 ), 00271 array( 3, '***', 00272 '<p><span style="font-weight:bold;">123456789</span></p>', 00273 '<p><span style="font-weight:bold;">***</span></p>', 00274 ), 00275 array( 4, '***', 00276 '<p><span style="font-weight:bold;">123456789</span></p>', 00277 '<p><span style="font-weight:bold;">1***</span></p>', 00278 ), 00279 array( 5, '***', 00280 '<tt><span style="font-weight:bold;">123456789</span></tt>', 00281 '<tt><span style="font-weight:bold;">12***</span></tt>', 00282 ), 00283 array( 6, '***', 00284 '<p><a href="www.mediawiki.org">123456789</a></p>', 00285 '<p><a href="www.mediawiki.org">123***</a></p>', 00286 ), 00287 array( 6, '***', 00288 '<p><a href="www.mediawiki.org">12 456789</a></p>', 00289 '<p><a href="www.mediawiki.org">12 ***</a></p>', 00290 ), 00291 array( 7, '***', 00292 '<small><span style="font-weight:bold;">123<p id="#moo">456</p>789</span></small>', 00293 '<small><span style="font-weight:bold;">123<p id="#moo">4***</p></span></small>', 00294 ), 00295 array( 8, '***', 00296 '<div><span style="font-weight:bold;">123<span>4</span>56789</span></div>', 00297 '<div><span style="font-weight:bold;">123<span>4</span>5***</span></div>', 00298 ), 00299 array( 9, '***', 00300 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>', 00301 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>', 00302 ), 00303 array( 10, '***', 00304 '<p><font style="font-weight:bold;">123456789</font></p>', 00305 '<p><font style="font-weight:bold;">123456789</font></p>', 00306 ), 00307 ); 00308 } 00309 00314 function testBuiltInCodeValidation( $code, $message = '' ) { 00315 $this->assertTrue( 00316 (bool) Language::isValidBuiltInCode( $code ), 00317 "validating code $code $message" 00318 ); 00319 } 00320 00321 function testBuiltInCodeValidationRejectUnderscore() { 00322 $this->assertFalse( 00323 (bool) Language::isValidBuiltInCode( 'be_tarask' ), 00324 "reject underscore in language code" 00325 ); 00326 } 00327 00328 function provideLanguageCodes() { 00329 return array( 00330 array( 'fr' , 'Two letters, minor case' ), 00331 array( 'EN' , 'Two letters, upper case' ), 00332 array( 'tyv' , 'Three letters' ), 00333 array( 'tokipona' , 'long language code' ), 00334 array( 'be-tarask', 'With dash' ), 00335 array( 'Zh-classical', 'Begin with upper case, dash' ), 00336 array( 'Be-x-old', 'With extension (two dashes)' ), 00337 ); 00338 } 00339 00343 function testSprintfDate( $format, $ts, $expected, $msg ) { 00344 $this->assertEquals( 00345 $expected, 00346 $this->getLang()->sprintfDate( $format, $ts ), 00347 "sprintfDate('$format', '$ts'): $msg" 00348 ); 00349 } 00354 function testSprintfDateTZ( $format, $ts, $expected, $msg ) { 00355 $oldTZ = date_default_timezone_get(); 00356 $res = date_default_timezone_set( 'Asia/Seoul' ); 00357 if ( !$res ) { 00358 $this->markTestSkipped( "Error setting Timezone" ); 00359 } 00360 00361 $this->assertEquals( 00362 $expected, 00363 $this->getLang()->sprintfDate( $format, $ts ), 00364 "sprintfDate('$format', '$ts'): $msg" 00365 ); 00366 00367 date_default_timezone_set( $oldTZ ); 00368 } 00369 00370 function provideSprintfDateSamples() { 00371 return array( 00372 array( 00373 'xiY', 00374 '20111212000000', 00375 '1390', // note because we're testing English locale we get Latin-standard digits 00376 'Iranian calendar full year' 00377 ), 00378 array( 00379 'xiy', 00380 '20111212000000', 00381 '90', 00382 'Iranian calendar short year' 00383 ), 00384 array( 00385 'o', 00386 '20120101235000', 00387 '2011', 00388 'ISO 8601 (week) year' 00389 ), 00390 array( 00391 'W', 00392 '20120101235000', 00393 '52', 00394 'Week number' 00395 ), 00396 array( 00397 'W', 00398 '20120102235000', 00399 '1', 00400 'Week number' 00401 ), 00402 array( 00403 'o-\\WW-N', 00404 '20091231235000', 00405 '2009-W53-4', 00406 'leap week' 00407 ), 00408 // What follows is mostly copied from http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time 00409 array( 00410 'Y', 00411 '20120102090705', 00412 '2012', 00413 'Full year' 00414 ), 00415 array( 00416 'y', 00417 '20120102090705', 00418 '12', 00419 '2 digit year' 00420 ), 00421 array( 00422 'L', 00423 '20120102090705', 00424 '1', 00425 'Leap year' 00426 ), 00427 array( 00428 'n', 00429 '20120102090705', 00430 '1', 00431 'Month index, not zero pad' 00432 ), 00433 array( 00434 'N', 00435 '20120102090705', 00436 '01', 00437 'Month index. Zero pad' 00438 ), 00439 array( 00440 'M', 00441 '20120102090705', 00442 'Jan', 00443 'Month abbrev' 00444 ), 00445 array( 00446 'F', 00447 '20120102090705', 00448 'January', 00449 'Full month' 00450 ), 00451 array( 00452 'xg', 00453 '20120102090705', 00454 'January', 00455 'Genitive month name (same in EN)' 00456 ), 00457 array( 00458 'j', 00459 '20120102090705', 00460 '2', 00461 'Day of month (not zero pad)' 00462 ), 00463 array( 00464 'd', 00465 '20120102090705', 00466 '02', 00467 'Day of month (zero-pad)' 00468 ), 00469 array( 00470 'z', 00471 '20120102090705', 00472 '1', 00473 'Day of year (zero-indexed)' 00474 ), 00475 array( 00476 'D', 00477 '20120102090705', 00478 'Mon', 00479 'Day of week (abbrev)' 00480 ), 00481 array( 00482 'l', 00483 '20120102090705', 00484 'Monday', 00485 'Full day of week' 00486 ), 00487 array( 00488 'N', 00489 '20120101090705', 00490 '7', 00491 'Day of week (Mon=1, Sun=7)' 00492 ), 00493 array( 00494 'w', 00495 '20120101090705', 00496 '0', 00497 'Day of week (Sun=0, Sat=6)' 00498 ), 00499 array( 00500 'N', 00501 '20120102090705', 00502 '1', 00503 'Day of week' 00504 ), 00505 array( 00506 'a', 00507 '20120102090705', 00508 'am', 00509 'am vs pm' 00510 ), 00511 array( 00512 'A', 00513 '20120102120000', 00514 'PM', 00515 'AM vs PM' 00516 ), 00517 array( 00518 'a', 00519 '20120102000000', 00520 'am', 00521 'AM vs PM' 00522 ), 00523 array( 00524 'g', 00525 '20120102090705', 00526 '9', 00527 '12 hour, not Zero' 00528 ), 00529 array( 00530 'h', 00531 '20120102090705', 00532 '09', 00533 '12 hour, zero padded' 00534 ), 00535 array( 00536 'G', 00537 '20120102090705', 00538 '9', 00539 '24 hour, not zero' 00540 ), 00541 array( 00542 'H', 00543 '20120102090705', 00544 '09', 00545 '24 hour, zero' 00546 ), 00547 array( 00548 'H', 00549 '20120102110705', 00550 '11', 00551 '24 hour, zero' 00552 ), 00553 array( 00554 'i', 00555 '20120102090705', 00556 '07', 00557 'Minutes' 00558 ), 00559 array( 00560 's', 00561 '20120102090705', 00562 '05', 00563 'seconds' 00564 ), 00565 array( 00566 'U', 00567 '20120102090705', 00568 '1325495225', 00569 'unix time' 00570 ), 00571 array( 00572 't', 00573 '20120102090705', 00574 '31', 00575 'Days in current month' 00576 ), 00577 array( 00578 'c', 00579 '20120102090705', 00580 '2012-01-02T09:07:05+00:00', 00581 'ISO 8601 timestamp' 00582 ), 00583 array( 00584 'r', 00585 '20120102090705', 00586 'Mon, 02 Jan 2012 09:07:05 +0000', 00587 'RFC 5322' 00588 ), 00589 array( 00590 'xmj xmF xmn xmY', 00591 '20120102090705', 00592 '7 Safar 2 1433', 00593 'Islamic' 00594 ), 00595 array( 00596 'xij xiF xin xiY', 00597 '20120102090705', 00598 '12 Dey 10 1390', 00599 'Iranian' 00600 ), 00601 array( 00602 'xjj xjF xjn xjY', 00603 '20120102090705', 00604 '7 Tevet 4 5772', 00605 'Hebrew' 00606 ), 00607 array( 00608 'xjt', 00609 '20120102090705', 00610 '29', 00611 'Hebrew number of days in month' 00612 ), 00613 array( 00614 'xjx', 00615 '20120102090705', 00616 'Tevet', 00617 'Hebrew genitive month name (No difference in EN)' 00618 ), 00619 array( 00620 'xkY', 00621 '20120102090705', 00622 '2555', 00623 'Thai year' 00624 ), 00625 array( 00626 'xoY', 00627 '20120102090705', 00628 '101', 00629 'Minguo' 00630 ), 00631 array( 00632 'xtY', 00633 '20120102090705', 00634 '平成24', 00635 'nengo' 00636 ), 00637 array( 00638 'xrxkYY', 00639 '20120102090705', 00640 'MMDLV2012', 00641 'Roman numerals' 00642 ), 00643 array( 00644 'xhxjYY', 00645 '20120102090705', 00646 'ה\'תשע"ב2012', 00647 'Hebrew numberals' 00648 ), 00649 array( 00650 'xnY', 00651 '20120102090705', 00652 '2012', 00653 'Raw numerals (doesn\'t mean much in EN)' 00654 ), 00655 array( 00656 '[[Y "(yea"\\r)]] \\"xx\\"', 00657 '20120102090705', 00658 '[[2012 (year)]] "x"', 00659 'Various escaping' 00660 ), 00661 00662 ); 00663 } 00664 00668 function testFormatSize( $size, $expected, $msg ) { 00669 $this->assertEquals( 00670 $expected, 00671 $this->getLang()->formatSize( $size ), 00672 "formatSize('$size'): $msg" 00673 ); 00674 } 00675 00676 function provideFormatSizes() { 00677 return array( 00678 array( 00679 0, 00680 "0 B", 00681 "Zero bytes" 00682 ), 00683 array( 00684 1024, 00685 "1 KB", 00686 "1 kilobyte" 00687 ), 00688 array( 00689 1024 * 1024, 00690 "1 MB", 00691 "1,024 megabytes" 00692 ), 00693 array( 00694 1024 * 1024 * 1024, 00695 "1 GB", 00696 "1 gigabytes" 00697 ), 00698 array( 00699 pow( 1024, 4 ), 00700 "1 TB", 00701 "1 terabyte" 00702 ), 00703 array( 00704 pow( 1024, 5 ), 00705 "1 PB", 00706 "1 petabyte" 00707 ), 00708 array( 00709 pow( 1024, 6 ), 00710 "1 EB", 00711 "1,024 exabyte" 00712 ), 00713 array( 00714 pow( 1024, 7 ), 00715 "1 ZB", 00716 "1 zetabyte" 00717 ), 00718 array( 00719 pow( 1024, 8 ), 00720 "1 YB", 00721 "1 yottabyte" 00722 ), 00723 // How big!? THIS BIG! 00724 ); 00725 } 00726 00730 function testFormatBitrate( $bps, $expected, $msg ) { 00731 $this->assertEquals( 00732 $expected, 00733 $this->getLang()->formatBitrate( $bps ), 00734 "formatBitrate('$bps'): $msg" 00735 ); 00736 } 00737 00738 function provideFormatBitrate() { 00739 return array( 00740 array( 00741 0, 00742 "0bps", 00743 "0 bits per second" 00744 ), 00745 array( 00746 999, 00747 "999bps", 00748 "999 bits per second" 00749 ), 00750 array( 00751 1000, 00752 "1kbps", 00753 "1 kilobit per second" 00754 ), 00755 array( 00756 1000 * 1000, 00757 "1Mbps", 00758 "1 megabit per second" 00759 ), 00760 array( 00761 pow( 10, 9 ), 00762 "1Gbps", 00763 "1 gigabit per second" 00764 ), 00765 array( 00766 pow( 10, 12 ), 00767 "1Tbps", 00768 "1 terabit per second" 00769 ), 00770 array( 00771 pow( 10, 15 ), 00772 "1Pbps", 00773 "1 petabit per second" 00774 ), 00775 array( 00776 pow( 10, 18 ), 00777 "1Ebps", 00778 "1 exabit per second" 00779 ), 00780 array( 00781 pow( 10, 21 ), 00782 "1Zbps", 00783 "1 zetabit per second" 00784 ), 00785 array( 00786 pow( 10, 24 ), 00787 "1Ybps", 00788 "1 yottabit per second" 00789 ), 00790 array( 00791 pow( 10, 27 ), 00792 "1,000Ybps", 00793 "1,000 yottabits per second" 00794 ), 00795 ); 00796 } 00797 00798 00799 00803 function testFormatDuration( $duration, $expected, $intervals = array() ) { 00804 $this->assertEquals( 00805 $expected, 00806 $this->getLang()->formatDuration( $duration, $intervals ), 00807 "formatDuration('$duration'): $expected" 00808 ); 00809 } 00810 00811 function provideFormatDuration() { 00812 return array( 00813 array( 00814 0, 00815 '0 seconds', 00816 ), 00817 array( 00818 1, 00819 '1 second', 00820 ), 00821 array( 00822 2, 00823 '2 seconds', 00824 ), 00825 array( 00826 60, 00827 '1 minute', 00828 ), 00829 array( 00830 2 * 60, 00831 '2 minutes', 00832 ), 00833 array( 00834 3600, 00835 '1 hour', 00836 ), 00837 array( 00838 2 * 3600, 00839 '2 hours', 00840 ), 00841 array( 00842 24 * 3600, 00843 '1 day', 00844 ), 00845 array( 00846 2 * 86400, 00847 '2 days', 00848 ), 00849 array( 00850 365.25 * 86400, // 365.25 * 86400 = 31557600 00851 '1 year', 00852 ), 00853 array( 00854 2 * 31557600, 00855 '2 years', 00856 ), 00857 array( 00858 10 * 31557600, 00859 '1 decade', 00860 ), 00861 array( 00862 20 * 31557600, 00863 '2 decades', 00864 ), 00865 array( 00866 100 * 31557600, 00867 '1 century', 00868 ), 00869 array( 00870 200 * 31557600, 00871 '2 centuries', 00872 ), 00873 array( 00874 1000 * 31557600, 00875 '1 millennium', 00876 ), 00877 array( 00878 2000 * 31557600, 00879 '2 millennia', 00880 ), 00881 array( 00882 9001, 00883 '2 hours, 30 minutes and 1 second' 00884 ), 00885 array( 00886 3601, 00887 '1 hour and 1 second' 00888 ), 00889 array( 00890 31557600 + 2 * 86400 + 9000, 00891 '1 year, 2 days, 2 hours and 30 minutes' 00892 ), 00893 array( 00894 42 * 1000 * 31557600 + 42, 00895 '42 millennia and 42 seconds' 00896 ), 00897 array( 00898 60, 00899 '60 seconds', 00900 array( 'seconds' ), 00901 ), 00902 array( 00903 61, 00904 '61 seconds', 00905 array( 'seconds' ), 00906 ), 00907 array( 00908 1, 00909 '1 second', 00910 array( 'seconds' ), 00911 ), 00912 array( 00913 31557600 + 2 * 86400 + 9000, 00914 '1 year, 2 days and 150 minutes', 00915 array( 'years', 'days', 'minutes' ), 00916 ), 00917 array( 00918 42, 00919 '0 days', 00920 array( 'years', 'days' ), 00921 ), 00922 array( 00923 31557600 + 2 * 86400 + 9000, 00924 '1 year, 2 days and 150 minutes', 00925 array( 'minutes', 'days', 'years' ), 00926 ), 00927 array( 00928 42, 00929 '0 days', 00930 array( 'days', 'years' ), 00931 ), 00932 ); 00933 } 00934 00938 function testCheckTitleEncoding( $s ) { 00939 $this->assertEquals( 00940 $s, 00941 $this->getLang()->checkTitleEncoding($s), 00942 "checkTitleEncoding('$s')" 00943 ); 00944 } 00945 00946 function provideCheckTitleEncodingData() { 00947 return array ( 00948 array( "" ), 00949 array( "United States of America" ), // 7bit ASCII 00950 array( rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ), 00951 array( 00952 rawurldecode( 00953 "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn" 00954 ) 00955 ), 00956 // The following two data sets come from bug 36839. They fail if checkTitleEncoding uses a regexp to test for 00957 // valid UTF-8 encoding and the pcre.recursion_limit is low (like, say, 1024). They succeed if checkTitleEncoding 00958 // uses mb_check_encoding for its test. 00959 array( 00960 rawurldecode( 00961 "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn%7C" 00962 . "Catherine%20Willows%7CDavid%20Hodges%7CDavid%20Phillips%7CGil%20Grissom%7CGreg%20Sanders%7CHodges%7C" 00963 . "Internet%20Movie%20Database%7CJim%20Brass%7CLady%20Heather%7C" 00964 . "Les%20Experts%20(s%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e)%7CLes%20Experts%20:%20Manhattan%7C" 00965 . "Les%20Experts%20:%20Miami%7CListe%20des%20personnages%20des%20Experts%7C" 00966 . "Liste%20des%20%C3%A9pisodes%20des%20Experts%7CMod%C3%A8le%20discussion:Palette%20Les%20Experts%7C" 00967 . "Nick%20Stokes%7CPersonnage%20de%20fiction%7CPersonnage%20fictif%7CPersonnage%20de%20fiction%7C" 00968 . "Personnages%20r%C3%A9currents%20dans%20Les%20Experts%7CRaymond%20Langston%7CRiley%20Adams%7C" 00969 . "Saison%201%20des%20Experts%7CSaison%2010%20des%20Experts%7CSaison%2011%20des%20Experts%7C" 00970 . "Saison%2012%20des%20Experts%7CSaison%202%20des%20Experts%7CSaison%203%20des%20Experts%7C" 00971 . "Saison%204%20des%20Experts%7CSaison%205%20des%20Experts%7CSaison%206%20des%20Experts%7C" 00972 . "Saison%207%20des%20Experts%7CSaison%208%20des%20Experts%7CSaison%209%20des%20Experts%7C" 00973 . "Sara%20Sidle%7CSofia%20Curtis%7CS%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e%7CWallace%20Langham%7C" 00974 . "Warrick%20Brown%7CWendy%20Simms%7C%C3%89tats-Unis" 00975 ), 00976 ), 00977 array( 00978 rawurldecode( 00979 "Mod%C3%A8le%3AArrondissements%20homonymes%7CMod%C3%A8le%3ABandeau%20standard%20pour%20page%20d'homonymie%7C" 00980 . "Mod%C3%A8le%3ABatailles%20homonymes%7CMod%C3%A8le%3ACantons%20homonymes%7C" 00981 . "Mod%C3%A8le%3ACommunes%20fran%C3%A7aises%20homonymes%7CMod%C3%A8le%3AFilms%20homonymes%7C" 00982 . "Mod%C3%A8le%3AGouvernements%20homonymes%7CMod%C3%A8le%3AGuerres%20homonymes%7CMod%C3%A8le%3AHomonymie%7C" 00983 . "Mod%C3%A8le%3AHomonymie%20bateau%7CMod%C3%A8le%3AHomonymie%20d'%C3%A9tablissements%20scolaires%20ou" 00984 . "%20universitaires%7CMod%C3%A8le%3AHomonymie%20d'%C3%AEles%7CMod%C3%A8le%3AHomonymie%20de%20clubs%20sportifs%7C" 00985 . "Mod%C3%A8le%3AHomonymie%20de%20comt%C3%A9s%7CMod%C3%A8le%3AHomonymie%20de%20monument%7C" 00986 . "Mod%C3%A8le%3AHomonymie%20de%20nom%20romain%7CMod%C3%A8le%3AHomonymie%20de%20parti%20politique%7C" 00987 . "Mod%C3%A8le%3AHomonymie%20de%20route%7CMod%C3%A8le%3AHomonymie%20dynastique%7C" 00988 . "Mod%C3%A8le%3AHomonymie%20vid%C3%A9oludique%7CMod%C3%A8le%3AHomonymie%20%C3%A9difice%20religieux%7C" 00989 . "Mod%C3%A8le%3AInternationalisation%7CMod%C3%A8le%3AIsom%C3%A9rie%7CMod%C3%A8le%3AParonymie%7C" 00990 . "Mod%C3%A8le%3APatronyme%7CMod%C3%A8le%3APatronyme%20basque%7CMod%C3%A8le%3APatronyme%20italien%7C" 00991 . "Mod%C3%A8le%3APatronymie%7CMod%C3%A8le%3APersonnes%20homonymes%7CMod%C3%A8le%3ASaints%20homonymes%7C" 00992 . "Mod%C3%A8le%3ATitres%20homonymes%7CMod%C3%A8le%3AToponymie%7CMod%C3%A8le%3AUnit%C3%A9s%20homonymes%7C" 00993 . "Mod%C3%A8le%3AVilles%20homonymes%7CMod%C3%A8le%3A%C3%89difices%20religieux%20homonymes" 00994 ) 00995 ) 00996 ); 00997 } 00998 01002 function testRomanNumerals( $num, $numerals ) { 01003 $this->assertEquals( 01004 $numerals, 01005 Language::romanNumeral( $num ), 01006 "romanNumeral('$num')" 01007 ); 01008 } 01009 01010 function provideRomanNumeralsData() { 01011 return array( 01012 array( 1, 'I' ), 01013 array( 2, 'II' ), 01014 array( 3, 'III' ), 01015 array( 4, 'IV' ), 01016 array( 5, 'V' ), 01017 array( 6, 'VI' ), 01018 array( 7, 'VII' ), 01019 array( 8, 'VIII' ), 01020 array( 9, 'IX' ), 01021 array( 10, 'X' ), 01022 array( 20, 'XX' ), 01023 array( 30, 'XXX' ), 01024 array( 40, 'XL' ), 01025 array( 49, 'XLIX' ), 01026 array( 50, 'L' ), 01027 array( 60, 'LX' ), 01028 array( 70, 'LXX' ), 01029 array( 80, 'LXXX' ), 01030 array( 90, 'XC' ), 01031 array( 99, 'XCIX' ), 01032 array( 100, 'C' ), 01033 array( 200, 'CC' ), 01034 array( 300, 'CCC' ), 01035 array( 400, 'CD' ), 01036 array( 500, 'D' ), 01037 array( 600, 'DC' ), 01038 array( 700, 'DCC' ), 01039 array( 800, 'DCCC' ), 01040 array( 900, 'CM' ), 01041 array( 999, 'CMXCIX' ), 01042 array( 1000, 'M' ), 01043 array( 1989, 'MCMLXXXIX' ), 01044 array( 2000, 'MM' ), 01045 array( 3000, 'MMM' ), 01046 array( 4000, 'MMMM' ), 01047 array( 5000, 'MMMMM' ), 01048 array( 6000, 'MMMMMM' ), 01049 array( 7000, 'MMMMMMM' ), 01050 array( 8000, 'MMMMMMMM' ), 01051 array( 9000, 'MMMMMMMMM' ), 01052 array( 9999, 'MMMMMMMMMCMXCIX'), 01053 array( 10000, 'MMMMMMMMMM' ), 01054 ); 01055 } 01056 01060 function testConvertPlural( $expected, $number, $forms ) { 01061 $chosen = $this->getLang()->convertPlural( $number, $forms ); 01062 $this->assertEquals( $expected, $chosen ); 01063 } 01064 01065 function providePluralData() { 01066 return array( 01067 array( 'explicit zero', 0, array( 01068 '0=explicit zero', 'singular', 'plural' 01069 ) ), 01070 array( 'explicit one', 1, array( 01071 'singular', 'plural', '1=explicit one', 01072 ) ), 01073 array( 'singular', 1, array( 01074 'singular', 'plural', '0=explicit zero', 01075 ) ), 01076 array( 'plural', 3, array( 01077 '0=explicit zero', '1=explicit one', 'singular', 'plural' 01078 ) ), 01079 ); 01080 } 01081 } 01082