3 class LanguageTest
extends LanguageClassesTestCase
{
5 * @covers Language::convertDoubleWidth
6 * @covers Language::normalizeForSearch
8 public function testLanguageConvertDoubleWidthToSingleWidth() {
10 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
11 $this->getLang()->normalizeForSearch(
12 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
14 'convertDoubleWidth() with the full alphabet and digits'
19 * @dataProvider provideFormattableTimes
20 * @covers Language::formatTimePeriod
22 public function testFormatTimePeriod( $seconds, $format, $expected, $desc ) {
23 $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc );
26 public static function provideFormattableTimes() {
32 'formatTimePeriod() rounding (<10s)'
36 [ 'noabbrevs' => true ],
38 'formatTimePeriod() rounding (<10s)'
44 'formatTimePeriod() rounding (<10s)'
48 [ 'noabbrevs' => true ],
50 'formatTimePeriod() rounding (<10s)'
56 'formatTimePeriod() rounding (<60s)'
60 [ 'noabbrevs' => true ],
62 'formatTimePeriod() rounding (<60s)'
68 'formatTimePeriod() rounding (<1h)'
72 [ 'noabbrevs' => true ],
73 '2 minutes 0 seconds',
74 'formatTimePeriod() rounding (<1h)'
80 'formatTimePeriod() rounding (<1h)'
84 [ 'noabbrevs' => true ],
85 '1 hour 0 minutes 0 seconds',
86 'formatTimePeriod() rounding (<1h)'
92 'formatTimePeriod() rounding (>=1h)'
96 [ 'noabbrevs' => true ],
97 '2 hours 0 minutes 0 seconds',
98 'formatTimePeriod() rounding (>=1h)'
104 'formatTimePeriod() rounding (>=1h), avoidseconds'
108 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
110 'formatTimePeriod() rounding (>=1h), avoidseconds'
116 'formatTimePeriod() rounding (>=1h), avoidminutes'
120 [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ],
122 'formatTimePeriod() rounding (>=1h), avoidminutes'
128 'formatTimePeriod() rounding (=48h), avoidseconds'
132 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
133 '48 hours 0 minutes',
134 'formatTimePeriod() rounding (=48h), avoidseconds'
140 'formatTimePeriod() rounding (>48h), avoidminutes'
144 [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ],
146 'formatTimePeriod() rounding (>48h), avoidminutes'
152 'formatTimePeriod() rounding (>48h), avoidseconds'
156 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
157 '2 days 1 hour 0 minutes',
158 'formatTimePeriod() rounding (>48h), avoidseconds'
164 'formatTimePeriod() rounding (>48h), avoidminutes'
168 [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ],
170 'formatTimePeriod() rounding (>48h), avoidminutes'
176 'formatTimePeriod() rounding (>48h), avoidseconds'
180 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
181 '3 days 0 hours 0 minutes',
182 'formatTimePeriod() rounding (>48h), avoidseconds'
188 'formatTimePeriod() rounding, (>48h), avoidseconds'
192 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
193 '2 days 0 hours 0 minutes',
194 'formatTimePeriod() rounding, (>48h), avoidseconds'
200 'formatTimePeriod() rounding, recursion, (>48h)'
204 [ 'noabbrevs' => true ],
205 '2 days 1 hour 1 minute 1 second',
206 'formatTimePeriod() rounding, recursion, (>48h)'
212 * @covers Language::truncate
214 public function testTruncate() {
217 $this->getLang()->truncate( "1234567890", 0, 'XXX' ),
218 'truncate prefix, len 0, small ellipsis'
223 $this->getLang()->truncate( "1234567890", 8, 'XXX' ),
224 'truncate prefix, small ellipsis'
229 $this->getLang()->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ),
230 'truncate prefix, large ellipsis'
235 $this->getLang()->truncate( "1234567890", -8, 'XXX' ),
236 'truncate suffix, small ellipsis'
241 $this->getLang()->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ),
242 'truncate suffix, large ellipsis'
246 $this->getLang()->truncate( "123 ", 9, 'XXX' ),
247 'truncate prefix, with spaces'
251 $this->getLang()->truncate( "12345 8", 11, 'XXX' ),
252 'truncate prefix, with spaces and non-space ending'
256 $this->getLang()->truncate( "1 234", -8, 'XXX' ),
257 'truncate suffix, with spaces'
261 $this->getLang()->truncate( "1234567890", 5, 'XXX', false ),
262 'truncate without adjustment'
266 $this->getLang()->truncate( "泰乐菌素123456789", 11, '...', false ),
267 'truncate does not chop Unicode characters in half'
271 $this->getLang()->truncate( "\n泰乐菌素123456789", 12, '...', false ),
272 'truncate does not chop Unicode characters in half if there is a preceding newline'
277 * @dataProvider provideHTMLTruncateData
278 * @covers Language::truncateHTML
280 public function testTruncateHtml( $len, $ellipsis, $input, $expected ) {
284 $this->getLang()->truncateHtml( $input, $len, $ellipsis )
289 * @return array Format is ($len, $ellipsis, $input, $expected)
291 public static function provideHTMLTruncateData() {
293 [ 0, 'XXX', "1234567890", "XXX" ],
294 [ 8, 'XXX', "1234567890", "12345XXX" ],
295 [ 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ],
297 '<p><span style="font-weight:bold;"></span></p>',
298 '<p><span style="font-weight:bold;"></span></p>',
301 '<p><span style="font-weight:bold;">123456789</span></p>',
302 '<p><span style="font-weight:bold;">***</span></p>',
305 '<p><span style="font-weight:bold;"> 23456789</span></p>',
306 '<p><span style="font-weight:bold;">***</span></p>',
309 '<p><span style="font-weight:bold;">123456789</span></p>',
310 '<p><span style="font-weight:bold;">***</span></p>',
313 '<p><span style="font-weight:bold;">123456789</span></p>',
314 '<p><span style="font-weight:bold;">1***</span></p>',
317 '<tt><span style="font-weight:bold;">123456789</span></tt>',
318 '<tt><span style="font-weight:bold;">12***</span></tt>',
321 '<p><a href="www.mediawiki.org">123456789</a></p>',
322 '<p><a href="www.mediawiki.org">123***</a></p>',
325 '<p><a href="www.mediawiki.org">12 456789</a></p>',
326 '<p><a href="www.mediawiki.org">12 ***</a></p>',
329 '<small><span style="font-weight:bold;">123<p id="#moo">456</p>789</span></small>',
330 '<small><span style="font-weight:bold;">123<p id="#moo">4***</p></span></small>',
333 '<div><span style="font-weight:bold;">123<span>4</span>56789</span></div>',
334 '<div><span style="font-weight:bold;">123<span>4</span>5***</span></div>',
337 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
338 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
341 '<p><font style="font-weight:bold;">123456789</font></p>',
342 '<p><font style="font-weight:bold;">123456789</font></p>',
348 * Test Language::isWellFormedLanguageTag()
349 * @dataProvider provideWellFormedLanguageTags
350 * @covers Language::isWellFormedLanguageTag
352 public function testWellFormedLanguageTag( $code, $message = '' ) {
354 Language
::isWellFormedLanguageTag( $code ),
355 "validating code $code $message"
360 * The test cases are based on the tests in the GaBuZoMeu parser
361 * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr>
362 * and distributed as free software, under the GNU General Public Licence.
363 * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html
365 public static function provideWellFormedLanguageTags() {
367 [ 'fr', 'two-letter code' ],
368 [ 'fr-latn', 'two-letter code with lower case script code' ],
369 [ 'fr-Latn-FR', 'two-letter code with title case script code and uppercase country code' ],
370 [ 'fr-Latn-419', 'two-letter code with title case script code and region number' ],
371 [ 'fr-FR', 'two-letter code with uppercase' ],
372 [ 'ax-TZ', 'Not in the registry, but well-formed' ],
373 [ 'fr-shadok', 'two-letter code with variant' ],
374 [ 'fr-y-myext-myext2', 'non-x singleton' ],
375 [ 'fra-Latn', 'ISO 639 can be 3-letters' ],
376 [ 'fra', 'three-letter language code' ],
377 [ 'fra-FX', 'three-letter language code with country code' ],
378 [ 'i-klingon', 'grandfathered with singleton' ],
379 [ 'I-kLINgon', 'tags are case-insensitive...' ],
380 [ 'no-bok', 'grandfathered without singleton' ],
381 [ 'i-enochian', 'Grandfathered' ],
382 [ 'x-fr-CH', 'private use' ],
383 [ 'es-419', 'two-letter code with region number' ],
384 [ 'en-Latn-GB-boont-r-extended-sequence-x-private', 'weird, but well-formed' ],
385 [ 'ab-x-abc-x-abc', 'anything goes after x' ],
386 [ 'ab-x-abc-a-a', 'anything goes after x, including several non-x singletons' ],
387 [ 'i-default', 'grandfathered' ],
388 [ 'abcd-Latn', 'Language of 4 chars reserved for future use' ],
389 [ 'AaBbCcDd-x-y-any-x', 'Language of 5-8 chars, registered' ],
390 [ 'de-CH-1901', 'with country and year' ],
391 [ 'en-US-x-twain', 'with country and singleton' ],
392 [ 'zh-cmn', 'three-letter variant' ],
393 [ 'zh-cmn-Hant', 'three-letter variant and script' ],
394 [ 'zh-cmn-Hant-HK', 'three-letter variant, script and country' ],
395 [ 'xr-p-lze', 'Extension' ],
400 * Negative test for Language::isWellFormedLanguageTag()
401 * @dataProvider provideMalformedLanguageTags
402 * @covers Language::isWellFormedLanguageTag
404 public function testMalformedLanguageTag( $code, $message = '' ) {
406 Language
::isWellFormedLanguageTag( $code ),
407 "validating that code $code is a malformed language tag - $message"
412 * The test cases are based on the tests in the GaBuZoMeu parser
413 * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr>
414 * and distributed as free software, under the GNU General Public Licence.
415 * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html
417 public static function provideMalformedLanguageTags() {
419 [ 'f', 'language too short' ],
420 [ 'f-Latn', 'language too short with script' ],
421 [ 'xr-lxs-qut', 'variants too short' ], # extlangS
422 [ 'fr-Latn-F', 'region too short' ],
423 [ 'a-value', 'language too short with region' ],
424 [ 'tlh-a-b-foo', 'valid three-letter with wrong variant' ],
427 'grandfathered but not registered: invalid, even if we only test well-formedness'
429 [ 'abcdefghi-012345678', 'numbers too long' ],
430 [ 'ab-abc-abc-abc-abc', 'invalid extensions' ],
431 [ 'ab-abcd-abc', 'invalid extensions' ],
432 [ 'ab-ab-abc', 'invalid extensions' ],
433 [ 'ab-123-abc', 'invalid extensions' ],
434 [ 'a-Hant-ZH', 'short language with valid extensions' ],
435 [ 'a1-Hant-ZH', 'invalid character in language' ],
436 [ 'ab-abcde-abc', 'invalid extensions' ],
437 [ 'ab-1abc-abc', 'invalid characters in extensions' ],
438 [ 'ab-ab-abcd', 'invalid order of extensions' ],
439 [ 'ab-123-abcd', 'invalid order of extensions' ],
440 [ 'ab-abcde-abcd', 'invalid extensions' ],
441 [ 'ab-1abc-abcd', 'invalid characters in extensions' ],
442 [ 'ab-a-b', 'extensions too short' ],
443 [ 'ab-a-x', 'extensions too short, even with singleton' ],
444 [ 'ab--ab', 'two separators' ],
445 [ 'ab-abc-', 'separator in the end' ],
446 [ '-ab-abc', 'separator in the beginning' ],
447 [ 'abcd-efg', 'language too long' ],
448 [ 'aabbccddE', 'tag too long' ],
449 [ 'pa_guru', 'A tag with underscore is invalid in strict mode' ],
450 [ 'de-f', 'subtag too short' ],
455 * Negative test for Language::isWellFormedLanguageTag()
456 * @covers Language::isWellFormedLanguageTag
458 public function testLenientLanguageTag() {
460 Language
::isWellFormedLanguageTag( 'pa_guru', true ),
461 'pa_guru is a well-formed language tag in lenient mode'
466 * Test Language::isValidBuiltInCode()
467 * @dataProvider provideLanguageCodes
468 * @covers Language::isValidBuiltInCode
470 public function testBuiltInCodeValidation( $code, $expected, $message = '' ) {
471 $this->assertEquals( $expected,
472 (bool)Language
::isValidBuiltInCode( $code ),
473 "validating code $code $message"
477 public static function provideLanguageCodes() {
479 [ 'fr', true, 'Two letters, minor case' ],
480 [ 'EN', false, 'Two letters, upper case' ],
481 [ 'tyv', true, 'Three letters' ],
482 [ 'be-tarask', true, 'With dash' ],
483 [ 'be-x-old', true, 'With extension (two dashes)' ],
484 [ 'be_tarask', false, 'Reject underscores' ],
489 * Test Language::isKnownLanguageTag()
490 * @dataProvider provideKnownLanguageTags
491 * @covers Language::isKnownLanguageTag
493 public function testKnownLanguageTag( $code, $message = '' ) {
495 (bool)Language
::isKnownLanguageTag( $code ),
496 "validating code $code - $message"
500 public static function provideKnownLanguageTags() {
502 [ 'fr', 'simple code' ],
503 [ 'bat-smg', 'an MW legacy tag' ],
504 [ 'sgs', 'an internal standard MW name, for which a legacy tag is used externally' ],
509 * @covers Language::isKnownLanguageTag
511 public function testKnownCldrLanguageTag() {
512 if ( !class_exists( 'LanguageNames' ) ) {
513 $this->markTestSkipped( 'The LanguageNames class is not available. '
514 . 'The CLDR extension is probably not installed.' );
518 (bool)Language
::isKnownLanguageTag( 'pal' ),
519 'validating code "pal" an ancient language, which probably will '
520 . 'not appear in Names.php, but appears in CLDR in English'
525 * Negative tests for Language::isKnownLanguageTag()
526 * @dataProvider provideUnKnownLanguageTags
527 * @covers Language::isKnownLanguageTag
529 public function testUnknownLanguageTag( $code, $message = '' ) {
531 (bool)Language
::isKnownLanguageTag( $code ),
532 "checking that code $code is invalid - $message"
536 public static function provideUnknownLanguageTags() {
538 [ 'mw', 'non-existent two-letter code' ],
539 [ 'foo"<bar', 'very invalid language code' ],
544 * Test too short timestamp
545 * @expectedException MWException
546 * @covers Language::sprintfDate
548 public function testSprintfDateTooShortTimestamp() {
549 $this->getLang()->sprintfDate( 'xiY', '1234567890123' );
553 * Test too long timestamp
554 * @expectedException MWException
555 * @covers Language::sprintfDate
557 public function testSprintfDateTooLongTimestamp() {
558 $this->getLang()->sprintfDate( 'xiY', '123456789012345' );
562 * Test too short timestamp
563 * @expectedException MWException
564 * @covers Language::sprintfDate
566 public function testSprintfDateNotAllDigitTimestamp() {
567 $this->getLang()->sprintfDate( 'xiY', '-1234567890123' );
571 * @dataProvider provideSprintfDateSamples
572 * @covers Language::sprintfDate
574 public function testSprintfDate( $format, $ts, $expected, $msg ) {
578 $this->getLang()->sprintfDate( $format, $ts, null, $ttl ),
579 "sprintfDate('$format', '$ts'): $msg"
582 $dt = new DateTime( $ts );
583 $lastValidTS = $dt->add( new DateInterval( 'PT' . ( $ttl - 1 ) . 'S' ) )->format( 'YmdHis' );
586 $this->getLang()->sprintfDate( $format, $lastValidTS, null ),
587 "sprintfDate('$format', '$ts'): TTL $ttl too high (output was different at $lastValidTS)"
590 // advance the time enough to make all of the possible outputs different (except possibly L)
591 $dt = new DateTime( $ts );
592 $newTS = $dt->add( new DateInterval( 'P1Y1M8DT13H1M1S' ) )->format( 'YmdHis' );
595 $this->getLang()->sprintfDate( $format, $newTS, null ),
596 "sprintfDate('$format', '$ts'): Missing TTL (output was different at $newTS)"
602 * sprintfDate should always use UTC when no zone is given.
603 * @dataProvider provideSprintfDateSamples
604 * @covers Language::sprintfDate
606 public function testSprintfDateNoZone( $format, $ts, $expected, $ignore, $msg ) {
607 $oldTZ = date_default_timezone_get();
608 $res = date_default_timezone_set( 'Asia/Seoul' );
610 $this->markTestSkipped( "Error setting Timezone" );
615 $this->getLang()->sprintfDate( $format, $ts ),
616 "sprintfDate('$format', '$ts'): $msg"
619 date_default_timezone_set( $oldTZ );
623 * sprintfDate should use passed timezone
624 * @dataProvider provideSprintfDateSamples
625 * @covers Language::sprintfDate
627 public function testSprintfDateTZ( $format, $ts, $ignore, $expected, $msg ) {
628 $tz = new DateTimeZone( 'Asia/Seoul' );
630 $this->markTestSkipped( "Error getting Timezone" );
635 $this->getLang()->sprintfDate( $format, $ts, $tz ),
636 "sprintfDate('$format', '$ts', 'Asia/Seoul'): $msg"
641 * sprintfDate should only calculate a TTL if the caller is going to use it.
642 * @covers Language::sprintfDate
644 public function testSprintfDateNoTtlIfNotNeeded() {
645 $noTtl = 'unused'; // Value used to represent that the caller didn't pass a variable in.
647 $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $noTtl );
648 $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $ttl );
653 'If the caller does not set the $ttl variable, do not compute it.'
655 $this->assertInternalType( 'int', $ttl, 'TTL should have been computed.' );
658 public static function provideSprintfDateSamples() {
663 '1390', // note because we're testing English locale we get Latin-standard digits
665 'Iranian calendar full year'
672 'Iranian calendar short year'
679 'ISO 8601 (week) year'
702 // What follows is mostly copied from
703 // https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time
730 'Month index, not zero pad'
737 'Month index. Zero pad'
758 'Genitive month name (same in EN)'
765 'Day of month (not zero pad)'
772 'Day of month (zero-pad)'
779 'Day of year (zero-indexed)'
786 'Day of week (abbrev)'
800 'Day of week (Mon=1, Sun=7)'
807 'Day of week (Sun=0, Sat=6)'
849 '12 hour, zero padded'
898 'Days in current month'
903 '2012-01-02T09:07:05+00:00',
904 '2012-01-02T09:07:05+09:00',
910 'Mon, 02 Jan 2012 09:07:05 +0000',
911 'Mon, 02 Jan 2012 09:07:05 +0900',
919 'Timezone identifier'
940 'Timezone offset with colon'
947 'Timezone abbreviation'
954 'Timezone offset in seconds'
982 'Hebrew number of days in month'
989 'Hebrew genitive month name (No difference in EN)'
1031 'Raw numerals (doesn\'t mean much in EN)'
1034 '[[Y "(yea"\\r)]] \\"xx\\"',
1036 '[[2012 (year)]] "x"',
1037 '[[2012 (year)]] "x"',
1045 * @dataProvider provideFormatSizes
1046 * @covers Language::formatSize
1048 public function testFormatSize( $size, $expected, $msg ) {
1049 $this->assertEquals(
1051 $this->getLang()->formatSize( $size ),
1052 "formatSize('$size'): $msg"
1056 public static function provideFormatSizes() {
1103 // How big!? THIS BIG!
1108 * @dataProvider provideFormatBitrate
1109 * @covers Language::formatBitrate
1111 public function testFormatBitrate( $bps, $expected, $msg ) {
1112 $this->assertEquals(
1114 $this->getLang()->formatBitrate( $bps ),
1115 "formatBitrate('$bps'): $msg"
1119 public static function provideFormatBitrate() {
1129 "999 bits per second"
1134 "1 kilobit per second"
1139 "1 megabit per second"
1144 "1 gigabit per second"
1149 "1 terabit per second"
1154 "1 petabit per second"
1159 "1 exabit per second"
1164 "1 zetabit per second"
1169 "1 yottabit per second"
1174 "1,000 yottabits per second"
1180 * @dataProvider provideFormatDuration
1181 * @covers Language::formatDuration
1183 public function testFormatDuration( $duration, $expected, $intervals = [] ) {
1184 $this->assertEquals(
1186 $this->getLang()->formatDuration( $duration, $intervals ),
1187 "formatDuration('$duration'): $expected"
1191 public static function provideFormatDuration() {
1230 // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952
1231 ( 365 +
( 24 * 3 +
25 ) / 400.0 ) * 86400,
1264 '2 hours, 30 minutes and 1 second'
1268 '1 hour and 1 second'
1271 31556952 +
2 * 86400 +
9000,
1272 '1 year, 2 days, 2 hours and 30 minutes'
1275 42 * 1000 * 31556952 +
42,
1276 '42 millennia and 42 seconds'
1294 31556952 +
2 * 86400 +
9000,
1295 '1 year, 2 days and 150 minutes',
1296 [ 'years', 'days', 'minutes' ],
1301 [ 'years', 'days' ],
1304 31556952 +
2 * 86400 +
9000,
1305 '1 year, 2 days and 150 minutes',
1306 [ 'minutes', 'days', 'years' ],
1311 [ 'days', 'years' ],
1317 * @dataProvider provideCheckTitleEncodingData
1318 * @covers Language::checkTitleEncoding
1320 public function testCheckTitleEncoding( $s ) {
1321 $this->assertEquals(
1323 $this->getLang()->checkTitleEncoding( $s ),
1324 "checkTitleEncoding('$s')"
1328 public static function provideCheckTitleEncodingData() {
1329 // phpcs:disable Generic.Files.LineLength
1332 [ "United States of America" ], // 7bit ASCII
1333 [ rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ],
1336 "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn"
1339 // The following two data sets come from T38839. They fail if checkTitleEncoding uses a regexp to test for
1340 // valid UTF-8 encoding and the pcre.recursion_limit is low (like, say, 1024). They succeed if checkTitleEncoding
1341 // uses mb_check_encoding for its test.
1344 "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn%7C"
1345 . "Catherine%20Willows%7CDavid%20Hodges%7CDavid%20Phillips%7CGil%20Grissom%7CGreg%20Sanders%7CHodges%7C"
1346 . "Internet%20Movie%20Database%7CJim%20Brass%7CLady%20Heather%7C"
1347 . "Les%20Experts%20(s%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e)%7CLes%20Experts%20:%20Manhattan%7C"
1348 . "Les%20Experts%20:%20Miami%7CListe%20des%20personnages%20des%20Experts%7C"
1349 . "Liste%20des%20%C3%A9pisodes%20des%20Experts%7CMod%C3%A8le%20discussion:Palette%20Les%20Experts%7C"
1350 . "Nick%20Stokes%7CPersonnage%20de%20fiction%7CPersonnage%20fictif%7CPersonnage%20de%20fiction%7C"
1351 . "Personnages%20r%C3%A9currents%20dans%20Les%20Experts%7CRaymond%20Langston%7CRiley%20Adams%7C"
1352 . "Saison%201%20des%20Experts%7CSaison%2010%20des%20Experts%7CSaison%2011%20des%20Experts%7C"
1353 . "Saison%2012%20des%20Experts%7CSaison%202%20des%20Experts%7CSaison%203%20des%20Experts%7C"
1354 . "Saison%204%20des%20Experts%7CSaison%205%20des%20Experts%7CSaison%206%20des%20Experts%7C"
1355 . "Saison%207%20des%20Experts%7CSaison%208%20des%20Experts%7CSaison%209%20des%20Experts%7C"
1356 . "Sara%20Sidle%7CSofia%20Curtis%7CS%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e%7CWallace%20Langham%7C"
1357 . "Warrick%20Brown%7CWendy%20Simms%7C%C3%89tats-Unis"
1362 "Mod%C3%A8le%3AArrondissements%20homonymes%7CMod%C3%A8le%3ABandeau%20standard%20pour%20page%20d'homonymie%7C"
1363 . "Mod%C3%A8le%3ABatailles%20homonymes%7CMod%C3%A8le%3ACantons%20homonymes%7C"
1364 . "Mod%C3%A8le%3ACommunes%20fran%C3%A7aises%20homonymes%7CMod%C3%A8le%3AFilms%20homonymes%7C"
1365 . "Mod%C3%A8le%3AGouvernements%20homonymes%7CMod%C3%A8le%3AGuerres%20homonymes%7CMod%C3%A8le%3AHomonymie%7C"
1366 . "Mod%C3%A8le%3AHomonymie%20bateau%7CMod%C3%A8le%3AHomonymie%20d'%C3%A9tablissements%20scolaires%20ou"
1367 . "%20universitaires%7CMod%C3%A8le%3AHomonymie%20d'%C3%AEles%7CMod%C3%A8le%3AHomonymie%20de%20clubs%20sportifs%7C"
1368 . "Mod%C3%A8le%3AHomonymie%20de%20comt%C3%A9s%7CMod%C3%A8le%3AHomonymie%20de%20monument%7C"
1369 . "Mod%C3%A8le%3AHomonymie%20de%20nom%20romain%7CMod%C3%A8le%3AHomonymie%20de%20parti%20politique%7C"
1370 . "Mod%C3%A8le%3AHomonymie%20de%20route%7CMod%C3%A8le%3AHomonymie%20dynastique%7C"
1371 . "Mod%C3%A8le%3AHomonymie%20vid%C3%A9oludique%7CMod%C3%A8le%3AHomonymie%20%C3%A9difice%20religieux%7C"
1372 . "Mod%C3%A8le%3AInternationalisation%7CMod%C3%A8le%3AIsom%C3%A9rie%7CMod%C3%A8le%3AParonymie%7C"
1373 . "Mod%C3%A8le%3APatronyme%7CMod%C3%A8le%3APatronyme%20basque%7CMod%C3%A8le%3APatronyme%20italien%7C"
1374 . "Mod%C3%A8le%3APatronymie%7CMod%C3%A8le%3APersonnes%20homonymes%7CMod%C3%A8le%3ASaints%20homonymes%7C"
1375 . "Mod%C3%A8le%3ATitres%20homonymes%7CMod%C3%A8le%3AToponymie%7CMod%C3%A8le%3AUnit%C3%A9s%20homonymes%7C"
1376 . "Mod%C3%A8le%3AVilles%20homonymes%7CMod%C3%A8le%3A%C3%89difices%20religieux%20homonymes"
1384 * @dataProvider provideRomanNumeralsData
1385 * @covers Language::romanNumeral
1387 public function testRomanNumerals( $num, $numerals ) {
1388 $this->assertEquals(
1390 Language
::romanNumeral( $num ),
1391 "romanNumeral('$num')"
1395 public static function provideRomanNumeralsData() {
1428 [ 1989, 'MCMLXXXIX' ],
1434 [ 7000, 'MMMMMMM' ],
1435 [ 8000, 'MMMMMMMM' ],
1436 [ 9000, 'MMMMMMMMM' ],
1437 [ 9999, 'MMMMMMMMMCMXCIX' ],
1438 [ 10000, 'MMMMMMMMMM' ],
1443 * @dataProvider provideHebrewNumeralsData
1444 * @covers Language::hebrewNumeral
1446 public function testHebrewNumeral( $num, $numerals ) {
1447 $this->assertEquals(
1449 Language
::hebrewNumeral( $num ),
1450 "hebrewNumeral('$num')"
1454 public static function provideHebrewNumeralsData() {
1497 [ 2000, "ב' אלפים" ],
1499 [ 3000, "ג' אלפים" ],
1500 [ 4000, "ד' אלפים" ],
1501 [ 4904, "ד'תתק\"ד" ],
1502 [ 5000, "ה' אלפים" ],
1503 [ 5680, "ה'תר\"ף" ],
1504 [ 5690, "ה'תר\"ץ" ],
1505 [ 5708, "ה'תש\"ח" ],
1506 [ 5720, "ה'תש\"ך" ],
1507 [ 5740, "ה'תש\"ם" ],
1508 [ 5750, "ה'תש\"ן" ],
1509 [ 5775, "ה'תשע\"ה" ],
1514 * @dataProvider providePluralData
1515 * @covers Language::convertPlural
1517 public function testConvertPlural( $expected, $number, $forms ) {
1518 $chosen = $this->getLang()->convertPlural( $number, $forms );
1519 $this->assertEquals( $expected, $chosen );
1522 public static function providePluralData() {
1523 // Params are: [expected text, number given, [the plural forms]]
1526 'singular', 'plural'
1528 [ 'explicit zero', 0, [
1529 '0=explicit zero', 'singular', 'plural'
1531 [ 'explicit one', 1, [
1532 'singular', 'plural', '1=explicit one',
1535 'singular', 'plural', '0=explicit zero',
1538 '0=explicit zero', '1=explicit one', 'singular', 'plural'
1540 [ 'explicit eleven', 11, [
1541 'singular', 'plural', '11=explicit eleven',
1544 'singular', 'plural', '11=explicit twelve',
1547 'singular', 'plural', '=explicit form',
1550 'kissa=kala', '1=2=3', 'other',
1553 '0=explicit zero', '1=explicit one',
1559 * @covers Language::embedBidi()
1561 public function testEmbedBidi() {
1562 $lre = "\xE2\x80\xAA"; // U+202A LEFT-TO-RIGHT EMBEDDING
1563 $rle = "\xE2\x80\xAB"; // U+202B RIGHT-TO-LEFT EMBEDDING
1564 $pdf = "\xE2\x80\xAC"; // U+202C POP DIRECTIONAL FORMATTING
1565 $lang = $this->getLang();
1566 $this->assertEquals(
1568 $lang->embedBidi( '123' ),
1569 'embedBidi with neutral argument'
1571 $this->assertEquals(
1572 $lre . 'Ben_(WMF)' . $pdf,
1573 $lang->embedBidi( 'Ben_(WMF)' ),
1574 'embedBidi with LTR argument'
1576 $this->assertEquals(
1577 $rle . 'יהודי (מנוחין)' . $pdf,
1578 $lang->embedBidi( 'יהודי (מנוחין)' ),
1579 'embedBidi with RTL argument'
1584 * @covers Language::translateBlockExpiry()
1585 * @dataProvider provideTranslateBlockExpiry
1587 public function testTranslateBlockExpiry( $expectedData, $str, $now, $desc ) {
1588 $lang = $this->getLang();
1589 if ( is_array( $expectedData ) ) {
1590 list( $func, $arg ) = $expectedData;
1591 $expected = $lang->$func( $arg );
1593 $expected = $expectedData;
1595 $this->assertEquals( $expected, $lang->translateBlockExpiry( $str, null, $now ), $desc );
1598 public static function provideTranslateBlockExpiry() {
1600 [ '2 hours', '2 hours', 0, 'simple data from ipboptions' ],
1601 [ 'indefinite', 'infinite', 0, 'infinite from ipboptions' ],
1602 [ 'indefinite', 'infinity', 0, 'alternative infinite from ipboptions' ],
1603 [ 'indefinite', 'indefinite', 0, 'another alternative infinite from ipboptions' ],
1604 [ [ 'formatDuration', 1023 * 60 * 60 ], '1023 hours', 0, 'relative' ],
1605 [ [ 'formatDuration', -1023 ], '-1023 seconds', 0, 'negative relative' ],
1607 [ 'formatDuration', 1023 * 60 * 60 ],
1609 wfTimestamp( TS_UNIX
, '19910203040506' ),
1610 'relative with initial timestamp'
1612 [ [ 'formatDuration', 0 ], 'now', 0, 'now' ],
1614 [ 'timeanddate', '20120102070000' ],
1615 '2012-1-1 7:00 +1 day',
1617 'mixed, handled as absolute'
1619 [ [ 'timeanddate', '19910203040506' ], '1991-2-3 4:05:06', 0, 'absolute' ],
1620 [ [ 'timeanddate', '19700101000000' ], '1970-1-1 0:00:00', 0, 'absolute at epoch' ],
1621 [ [ 'timeanddate', '19691231235959' ], '1969-12-31 23:59:59', 0, 'time before epoch' ],
1623 [ 'timeanddate', '19910910000000' ],
1625 wfTimestamp( TS_UNIX
, '19910203040506' ),
1628 [ 'dummy', 'dummy', 0, 'return garbage as is' ],
1633 * @dataProvider provideFormatNum
1634 * @covers Language::formatNum
1636 public function testFormatNum(
1637 $translateNumerals, $langCode, $number, $nocommafy, $expected
1639 $this->setMwGlobals( [ 'wgTranslateNumerals' => $translateNumerals ] );
1640 $lang = Language
::factory( $langCode );
1641 $formattedNum = $lang->formatNum( $number, $nocommafy );
1642 $this->assertType( 'string', $formattedNum );
1643 $this->assertEquals( $expected, $formattedNum );
1646 public function provideFormatNum() {
1648 [ true, 'en', 100, false, '100' ],
1649 [ true, 'en', 101, true, '101' ],
1650 [ false, 'en', 103, false, '103' ],
1651 [ false, 'en', 104, true, '104' ],
1652 [ true, 'en', '105', false, '105' ],
1653 [ true, 'en', '106', true, '106' ],
1654 [ false, 'en', '107', false, '107' ],
1655 [ false, 'en', '108', true, '108' ],
1660 * @covers Language::parseFormattedNumber
1661 * @dataProvider parseFormattedNumberProvider
1663 public function testParseFormattedNumber( $langCode, $number ) {
1664 $lang = Language
::factory( $langCode );
1666 $localisedNum = $lang->formatNum( $number );
1667 $normalisedNum = $lang->parseFormattedNumber( $localisedNum );
1669 $this->assertEquals( $number, $normalisedNum );
1672 public function parseFormattedNumberProvider() {
1679 [ 'zh-classical', 7432 ]
1684 * @covers Language::commafy()
1685 * @dataProvider provideCommafyData
1687 public function testCommafy( $number, $numbersWithCommas ) {
1688 $this->assertEquals(
1690 $this->getLang()->commafy( $number ),
1691 "commafy('$number')"
1695 public static function provideCommafyData() {
1701 [ 10000, '10,000' ],
1702 [ 100000, '100,000' ],
1703 [ 1000000, '1,000,000' ],
1704 [ -1.0001, '-1.0001' ],
1705 [ 1.0001, '1.0001' ],
1706 [ 10.0001, '10.0001' ],
1707 [ 100.0001, '100.0001' ],
1708 [ 1000.0001, '1,000.0001' ],
1709 [ 10000.0001, '10,000.0001' ],
1710 [ 100000.0001, '100,000.0001' ],
1711 [ 1000000.0001, '1,000,000.0001' ],
1712 [ '200000000000000000000', '200,000,000,000,000,000,000' ],
1713 [ '-200000000000000000000', '-200,000,000,000,000,000,000' ],
1718 * @covers Language::listToText
1720 public function testListToText() {
1721 $lang = $this->getLang();
1722 $and = $lang->getMessageFromDB( 'and' );
1723 $s = $lang->getMessageFromDB( 'word-separator' );
1724 $c = $lang->getMessageFromDB( 'comma-separator' );
1726 $this->assertEquals( '', $lang->listToText( [] ) );
1727 $this->assertEquals( 'a', $lang->listToText( [ 'a' ] ) );
1728 $this->assertEquals( "a{$and}{$s}b", $lang->listToText( [ 'a', 'b' ] ) );
1729 $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( [ 'a', 'b', 'c' ] ) );
1730 $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( [ 'a', 'b', 'c', 'd' ] ) );
1734 * @dataProvider provideIsSupportedLanguage
1735 * @covers Language::isSupportedLanguage
1737 public function testIsSupportedLanguage( $code, $expected, $comment ) {
1738 $this->assertEquals( $expected, Language
::isSupportedLanguage( $code ), $comment );
1741 public static function provideIsSupportedLanguage() {
1743 [ 'en', true, 'is supported language' ],
1744 [ 'fi', true, 'is supported language' ],
1745 [ 'bunny', false, 'is not supported language' ],
1746 [ 'FI', false, 'is not supported language, input should be in lower case' ],
1751 * @dataProvider provideGetParentLanguage
1752 * @covers Language::getParentLanguage
1754 public function testGetParentLanguage( $code, $expected, $comment ) {
1755 $lang = Language
::factory( $code );
1756 if ( is_null( $expected ) ) {
1757 $this->assertNull( $lang->getParentLanguage(), $comment );
1759 $this->assertEquals( $expected, $lang->getParentLanguage()->getCode(), $comment );
1763 public static function provideGetParentLanguage() {
1765 [ 'zh-cn', 'zh', 'zh is the parent language of zh-cn' ],
1766 [ 'zh', 'zh', 'zh is defined as the parent language of zh, '
1767 . 'because zh converter can convert zh-cn to zh' ],
1768 [ 'zh-invalid', null, 'do not be fooled by arbitrarily composed language codes' ],
1769 [ 'de-formal', null, 'de does not have converter' ],
1770 [ 'de', null, 'de does not have converter' ],
1775 * @dataProvider provideGetNamespaceAliases
1776 * @covers Language::getNamespaceAliases
1778 public function testGetNamespaceAliases( $languageCode, $subset ) {
1779 $language = Language
::factory( $languageCode );
1780 $aliases = $language->getNamespaceAliases();
1781 foreach ( $subset as $alias => $nsId ) {
1782 $this->assertEquals( $nsId, $aliases[$alias] );
1786 public static function provideGetNamespaceAliases() {
1787 // TODO: Add tests for NS_PROJECT_TALK and GenderNamespaces
1800 * @covers Language::equals
1802 public function testEquals() {
1803 $en1 = new Language();
1804 $en1->setCode( 'en' );
1806 $en2 = Language
::factory( 'en' );
1807 $en2->setCode( 'en' );
1809 $this->assertTrue( $en1->equals( $en2 ), 'en equals en' );
1811 $fr = Language
::factory( 'fr' );
1812 $this->assertFalse( $en1->equals( $fr ), 'en not equals fr' );