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