3 class LanguageTest
extends LanguageClassesTestCase
{
5 function testLanguageConvertDoubleWidthToSingleWidth() {
7 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
8 $this->getLang()->normalizeForSearch(
9 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
11 'convertDoubleWidth() with the full alphabet and digits'
16 * @dataProvider provideFormattableTimes
18 function testFormatTimePeriod( $seconds, $format, $expected, $desc ) {
19 $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc );
22 public static function provideFormattableTimes() {
28 'formatTimePeriod() rounding (<10s)'
32 array( 'noabbrevs' => true ),
34 'formatTimePeriod() rounding (<10s)'
40 'formatTimePeriod() rounding (<10s)'
44 array( 'noabbrevs' => true ),
46 'formatTimePeriod() rounding (<10s)'
52 'formatTimePeriod() rounding (<60s)'
56 array( 'noabbrevs' => true ),
58 'formatTimePeriod() rounding (<60s)'
64 'formatTimePeriod() rounding (<1h)'
68 array( 'noabbrevs' => true ),
69 '2 minutes 0 seconds',
70 'formatTimePeriod() rounding (<1h)'
76 'formatTimePeriod() rounding (<1h)'
80 array( 'noabbrevs' => true ),
81 '1 hour 0 minutes 0 seconds',
82 'formatTimePeriod() rounding (<1h)'
88 'formatTimePeriod() rounding (>=1h)'
92 array( 'noabbrevs' => true ),
93 '2 hours 0 minutes 0 seconds',
94 'formatTimePeriod() rounding (>=1h)'
100 'formatTimePeriod() rounding (>=1h), avoidseconds'
104 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
106 'formatTimePeriod() rounding (>=1h), avoidseconds'
112 'formatTimePeriod() rounding (>=1h), avoidminutes'
116 array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ),
118 'formatTimePeriod() rounding (>=1h), avoidminutes'
124 'formatTimePeriod() rounding (=48h), avoidseconds'
128 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
129 '48 hours 0 minutes',
130 'formatTimePeriod() rounding (=48h), avoidseconds'
136 'formatTimePeriod() rounding (>48h), avoidminutes'
140 array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ),
142 'formatTimePeriod() rounding (>48h), avoidminutes'
148 'formatTimePeriod() rounding (>48h), avoidseconds'
152 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
153 '2 days 1 hour 0 minutes',
154 'formatTimePeriod() rounding (>48h), avoidseconds'
160 'formatTimePeriod() rounding (>48h), avoidminutes'
164 array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ),
166 'formatTimePeriod() rounding (>48h), avoidminutes'
172 'formatTimePeriod() rounding (>48h), avoidseconds'
176 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
177 '3 days 0 hours 0 minutes',
178 'formatTimePeriod() rounding (>48h), avoidseconds'
184 'formatTimePeriod() rounding, (>48h), avoidseconds'
188 array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
189 '2 days 0 hours 0 minutes',
190 'formatTimePeriod() rounding, (>48h), avoidseconds'
196 'formatTimePeriod() rounding, recursion, (>48h)'
200 array( 'noabbrevs' => true ),
201 '2 days 1 hour 1 minute 1 second',
202 'formatTimePeriod() rounding, recursion, (>48h)'
207 function testTruncate() {
210 $this->getLang()->truncate( "1234567890", 0, 'XXX' ),
211 'truncate prefix, len 0, small ellipsis'
216 $this->getLang()->truncate( "1234567890", 8, 'XXX' ),
217 'truncate prefix, small ellipsis'
222 $this->getLang()->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ),
223 'truncate prefix, large ellipsis'
228 $this->getLang()->truncate( "1234567890", -8, 'XXX' ),
229 'truncate suffix, small ellipsis'
234 $this->getLang()->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ),
235 'truncate suffix, large ellipsis'
240 * @dataProvider provideHTMLTruncateData()
242 function testTruncateHtml( $len, $ellipsis, $input, $expected ) {
246 $this->getLang()->truncateHTML( $input, $len, $ellipsis )
251 * Array format is ($len, $ellipsis, $input, $expected)
253 public static function provideHTMLTruncateData() {
255 array( 0, 'XXX', "1234567890", "XXX" ),
256 array( 8, 'XXX', "1234567890", "12345XXX" ),
257 array( 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ),
259 '<p><span style="font-weight:bold;"></span></p>',
260 '<p><span style="font-weight:bold;"></span></p>',
263 '<p><span style="font-weight:bold;">123456789</span></p>',
264 '<p><span style="font-weight:bold;">***</span></p>',
267 '<p><span style="font-weight:bold;"> 23456789</span></p>',
268 '<p><span style="font-weight:bold;">***</span></p>',
271 '<p><span style="font-weight:bold;">123456789</span></p>',
272 '<p><span style="font-weight:bold;">***</span></p>',
275 '<p><span style="font-weight:bold;">123456789</span></p>',
276 '<p><span style="font-weight:bold;">1***</span></p>',
279 '<tt><span style="font-weight:bold;">123456789</span></tt>',
280 '<tt><span style="font-weight:bold;">12***</span></tt>',
283 '<p><a href="www.mediawiki.org">123456789</a></p>',
284 '<p><a href="www.mediawiki.org">123***</a></p>',
287 '<p><a href="www.mediawiki.org">12 456789</a></p>',
288 '<p><a href="www.mediawiki.org">12 ***</a></p>',
291 '<small><span style="font-weight:bold;">123<p id="#moo">456</p>789</span></small>',
292 '<small><span style="font-weight:bold;">123<p id="#moo">4***</p></span></small>',
295 '<div><span style="font-weight:bold;">123<span>4</span>56789</span></div>',
296 '<div><span style="font-weight:bold;">123<span>4</span>5***</span></div>',
299 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
300 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
303 '<p><font style="font-weight:bold;">123456789</font></p>',
304 '<p><font style="font-weight:bold;">123456789</font></p>',
310 * Test Language::isWellFormedLanguageTag()
311 * @dataProvider provideWellFormedLanguageTags
313 function testWellFormedLanguageTag( $code, $message = '' ) {
315 Language
::isWellFormedLanguageTag( $code ),
316 "validating code $code $message"
321 * The test cases are based on the tests in the GaBuZoMeu parser
322 * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr>
323 * and distributed as free software, under the GNU General Public Licence.
324 * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html
326 public static function provideWellFormedLanguageTags() {
328 array( 'fr', 'two-letter code' ),
329 array( 'fr-latn', 'two-letter code with lower case script code' ),
330 array( 'fr-Latn-FR', 'two-letter code with title case script code and uppercase country code' ),
331 array( 'fr-Latn-419', 'two-letter code with title case script code and region number' ),
332 array( 'fr-FR', 'two-letter code with uppercase' ),
333 array( 'ax-TZ', 'Not in the registry, but well-formed' ),
334 array( 'fr-shadok', 'two-letter code with variant' ),
335 array( 'fr-y-myext-myext2', 'non-x singleton' ),
336 array( 'fra-Latn', 'ISO 639 can be 3-letters' ),
337 array( 'fra', 'three-letter language code' ),
338 array( 'fra-FX', 'three-letter language code with country code' ),
339 array( 'i-klingon', 'grandfathered with singleton' ),
340 array( 'I-kLINgon', 'tags are case-insensitive...' ),
341 array( 'no-bok', 'grandfathered without singleton' ),
342 array( 'i-enochian', 'Grandfathered' ),
343 array( 'x-fr-CH', 'private use' ),
344 array( 'es-419', 'two-letter code with region number' ),
345 array( 'en-Latn-GB-boont-r-extended-sequence-x-private', 'weird, but well-formed' ),
346 array( 'ab-x-abc-x-abc', 'anything goes after x' ),
347 array( 'ab-x-abc-a-a', 'anything goes after x, including several non-x singletons' ),
348 array( 'i-default', 'grandfathered' ),
349 array( 'abcd-Latn', 'Language of 4 chars reserved for future use' ),
350 array( 'AaBbCcDd-x-y-any-x', 'Language of 5-8 chars, registered' ),
351 array( 'de-CH-1901', 'with country and year' ),
352 array( 'en-US-x-twain', 'with country and singleton' ),
353 array( 'zh-cmn', 'three-letter variant' ),
354 array( 'zh-cmn-Hant', 'three-letter variant and script' ),
355 array( 'zh-cmn-Hant-HK', 'three-letter variant, script and country' ),
356 array( 'xr-p-lze', 'Extension' ),
361 * Negative test for Language::isWellFormedLanguageTag()
362 * @dataProvider provideMalformedLanguageTags
364 function testMalformedLanguageTag( $code, $message = '' ) {
366 Language
::isWellFormedLanguageTag( $code ),
367 "validating that code $code is a malformed language tag - $message"
372 * The test cases are based on the tests in the GaBuZoMeu parser
373 * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr>
374 * and distributed as free software, under the GNU General Public Licence.
375 * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html
377 public static function provideMalformedLanguageTags() {
379 array( 'f', 'language too short' ),
380 array( 'f-Latn', 'language too short with script' ),
381 array( 'xr-lxs-qut', 'variants too short' ), # extlangS
382 array( 'fr-Latn-F', 'region too short' ),
383 array( 'a-value', 'language too short with region' ),
384 array( 'tlh-a-b-foo', 'valid three-letter with wrong variant' ),
385 array( 'i-notexist', 'grandfathered but not registered: invalid, even if we only test well-formedness' ),
386 array( 'abcdefghi-012345678', 'numbers too long' ),
387 array( 'ab-abc-abc-abc-abc', 'invalid extensions' ),
388 array( 'ab-abcd-abc', 'invalid extensions' ),
389 array( 'ab-ab-abc', 'invalid extensions' ),
390 array( 'ab-123-abc', 'invalid extensions' ),
391 array( 'a-Hant-ZH', 'short language with valid extensions' ),
392 array( 'a1-Hant-ZH', 'invalid character in language' ),
393 array( 'ab-abcde-abc', 'invalid extensions' ),
394 array( 'ab-1abc-abc', 'invalid characters in extensions' ),
395 array( 'ab-ab-abcd', 'invalid order of extensions' ),
396 array( 'ab-123-abcd', 'invalid order of extensions' ),
397 array( 'ab-abcde-abcd', 'invalid extensions' ),
398 array( 'ab-1abc-abcd', 'invalid characters in extensions' ),
399 array( 'ab-a-b', 'extensions too short' ),
400 array( 'ab-a-x', 'extensions too short, even with singleton' ),
401 array( 'ab--ab', 'two separators' ),
402 array( 'ab-abc-', 'separator in the end' ),
403 array( '-ab-abc', 'separator in the beginning' ),
404 array( 'abcd-efg', 'language too long' ),
405 array( 'aabbccddE', 'tag too long' ),
406 array( 'pa_guru', 'A tag with underscore is invalid in strict mode' ),
407 array( 'de-f', 'subtag too short' ),
412 * Negative test for Language::isWellFormedLanguageTag()
414 function testLenientLanguageTag() {
416 Language
::isWellFormedLanguageTag( 'pa_guru', true ),
417 'pa_guru is a well-formed language tag in lenient mode'
422 * Test Language::isValidBuiltInCode()
423 * @dataProvider provideLanguageCodes
425 function testBuiltInCodeValidation( $code, $message = '' ) {
427 (bool)Language
::isValidBuiltInCode( $code ),
428 "validating code $code $message"
432 function testBuiltInCodeValidationRejectUnderscore() {
434 (bool)Language
::isValidBuiltInCode( 'be_tarask' ),
435 "reject underscore in language code"
439 public static function provideLanguageCodes() {
441 array( 'fr', 'Two letters, minor case' ),
442 array( 'EN', 'Two letters, upper case' ),
443 array( 'tyv', 'Three letters' ),
444 array( 'tokipona', 'long language code' ),
445 array( 'be-tarask', 'With dash' ),
446 array( 'Zh-classical', 'Begin with upper case, dash' ),
447 array( 'Be-x-old', 'With extension (two dashes)' ),
452 * Test Language::isKnownLanguageTag()
453 * @dataProvider provideKnownLanguageTags
455 function testKnownLanguageTag( $code, $message = '' ) {
457 (bool)Language
::isKnownLanguageTag( $code ),
458 "validating code $code - $message"
462 public static function provideKnownLanguageTags() {
464 array( 'fr', 'simple code' ),
465 array( 'bat-smg', 'an MW legacy tag' ),
466 array( 'sgs', 'an internal standard MW name, for which a legacy tag is used externally' ),
471 * Test Language::isKnownLanguageTag()
473 function testKnownCldrLanguageTag() {
474 if ( !class_exists( 'LanguageNames' ) ) {
475 $this->markTestSkipped( 'The LanguageNames class is not available. The cldr extension is probably not installed.' );
479 (bool)Language
::isKnownLanguageTag( 'pal' ),
480 'validating code "pal" an ancient language, which probably will not appear in Names.php, but appears in CLDR in English'
485 * Negative tests for Language::isKnownLanguageTag()
486 * @dataProvider provideUnKnownLanguageTags
488 function testUnknownLanguageTag( $code, $message = '' ) {
490 (bool)Language
::isKnownLanguageTag( $code ),
491 "checking that code $code is invalid - $message"
495 public static function provideUnknownLanguageTags() {
497 array( 'mw', 'non-existent two-letter code' ),
502 * @dataProvider provideSprintfDateSamples
504 function testSprintfDate( $format, $ts, $expected, $msg ) {
507 $this->getLang()->sprintfDate( $format, $ts ),
508 "sprintfDate('$format', '$ts'): $msg"
513 * sprintfDate should always use UTC when no zone is given.
514 * @dataProvider provideSprintfDateSamples
516 function testSprintfDateNoZone( $format, $ts, $expected, $ignore, $msg ) {
517 $oldTZ = date_default_timezone_get();
518 $res = date_default_timezone_set( 'Asia/Seoul' );
520 $this->markTestSkipped( "Error setting Timezone" );
525 $this->getLang()->sprintfDate( $format, $ts ),
526 "sprintfDate('$format', '$ts'): $msg"
529 date_default_timezone_set( $oldTZ );
533 * sprintfDate should use passed timezone
534 * @dataProvider provideSprintfDateSamples
536 function testSprintfDateTZ( $format, $ts, $ignore, $expected, $msg ) {
537 $tz = new DateTimeZone( 'Asia/Seoul' );
539 $this->markTestSkipped( "Error getting Timezone" );
544 $this->getLang()->sprintfDate( $format, $ts, $tz ),
545 "sprintfDate('$format', '$ts', 'Asia/Seoul'): $msg"
549 public static function provideSprintfDateSamples() {
554 '1390', // note because we're testing English locale we get Latin-standard digits
556 'Iranian calendar full year'
563 'Iranian calendar short year'
570 'ISO 8601 (week) year'
593 // What follows is mostly copied from http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time
620 'Month index, not zero pad'
627 'Month index. Zero pad'
648 'Genitive month name (same in EN)'
655 'Day of month (not zero pad)'
662 'Day of month (zero-pad)'
669 'Day of year (zero-indexed)'
676 'Day of week (abbrev)'
690 'Day of week (Mon=1, Sun=7)'
697 'Day of week (Sun=0, Sat=6)'
739 '12 hour, zero padded'
788 'Days in current month'
793 '2012-01-02T09:07:05+00:00',
794 '2012-01-02T09:07:05+09:00',
800 'Mon, 02 Jan 2012 09:07:05 +0000',
801 'Mon, 02 Jan 2012 09:07:05 +0900',
809 'Timezone identifier'
830 'Timezone offset with colon'
837 'Timezone abbreviation'
844 'Timezone offset in seconds'
872 'Hebrew number of days in month'
879 'Hebrew genitive month name (No difference in EN)'
921 'Raw numerals (doesn\'t mean much in EN)'
924 '[[Y "(yea"\\r)]] \\"xx\\"',
926 '[[2012 (year)]] "x"',
927 '[[2012 (year)]] "x"',
935 * @dataProvider provideFormatSizes
937 function testFormatSize( $size, $expected, $msg ) {
940 $this->getLang()->formatSize( $size ),
941 "formatSize('$size'): $msg"
945 public static function provideFormatSizes() {
992 // How big!? THIS BIG!
997 * @dataProvider provideFormatBitrate
999 function testFormatBitrate( $bps, $expected, $msg ) {
1000 $this->assertEquals(
1002 $this->getLang()->formatBitrate( $bps ),
1003 "formatBitrate('$bps'): $msg"
1007 public static function provideFormatBitrate() {
1017 "999 bits per second"
1022 "1 kilobit per second"
1027 "1 megabit per second"
1032 "1 gigabit per second"
1037 "1 terabit per second"
1042 "1 petabit per second"
1047 "1 exabit per second"
1052 "1 zetabit per second"
1057 "1 yottabit per second"
1062 "1,000 yottabits per second"
1069 * @dataProvider provideFormatDuration
1071 function testFormatDuration( $duration, $expected, $intervals = array() ) {
1072 $this->assertEquals(
1074 $this->getLang()->formatDuration( $duration, $intervals ),
1075 "formatDuration('$duration'): $expected"
1079 public static function provideFormatDuration() {
1118 // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952
1119 ( 365 +
( 24 * 3 +
25 ) / 400.0 ) * 86400,
1152 '2 hours, 30 minutes and 1 second'
1156 '1 hour and 1 second'
1159 31556952 +
2 * 86400 +
9000,
1160 '1 year, 2 days, 2 hours and 30 minutes'
1163 42 * 1000 * 31556952 +
42,
1164 '42 millennia and 42 seconds'
1182 31556952 +
2 * 86400 +
9000,
1183 '1 year, 2 days and 150 minutes',
1184 array( 'years', 'days', 'minutes' ),
1189 array( 'years', 'days' ),
1192 31556952 +
2 * 86400 +
9000,
1193 '1 year, 2 days and 150 minutes',
1194 array( 'minutes', 'days', 'years' ),
1199 array( 'days', 'years' ),
1205 * @dataProvider provideCheckTitleEncodingData
1207 function testCheckTitleEncoding( $s ) {
1208 $this->assertEquals(
1210 $this->getLang()->checkTitleEncoding( $s ),
1211 "checkTitleEncoding('$s')"
1215 public static function provideCheckTitleEncodingData() {
1218 array( "United States of America" ), // 7bit ASCII
1219 array( rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ),
1222 "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn"
1225 // The following two data sets come from bug 36839. They fail if checkTitleEncoding uses a regexp to test for
1226 // valid UTF-8 encoding and the pcre.recursion_limit is low (like, say, 1024). They succeed if checkTitleEncoding
1227 // uses mb_check_encoding for its test.
1230 "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn%7C"
1231 . "Catherine%20Willows%7CDavid%20Hodges%7CDavid%20Phillips%7CGil%20Grissom%7CGreg%20Sanders%7CHodges%7C"
1232 . "Internet%20Movie%20Database%7CJim%20Brass%7CLady%20Heather%7C"
1233 . "Les%20Experts%20(s%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e)%7CLes%20Experts%20:%20Manhattan%7C"
1234 . "Les%20Experts%20:%20Miami%7CListe%20des%20personnages%20des%20Experts%7C"
1235 . "Liste%20des%20%C3%A9pisodes%20des%20Experts%7CMod%C3%A8le%20discussion:Palette%20Les%20Experts%7C"
1236 . "Nick%20Stokes%7CPersonnage%20de%20fiction%7CPersonnage%20fictif%7CPersonnage%20de%20fiction%7C"
1237 . "Personnages%20r%C3%A9currents%20dans%20Les%20Experts%7CRaymond%20Langston%7CRiley%20Adams%7C"
1238 . "Saison%201%20des%20Experts%7CSaison%2010%20des%20Experts%7CSaison%2011%20des%20Experts%7C"
1239 . "Saison%2012%20des%20Experts%7CSaison%202%20des%20Experts%7CSaison%203%20des%20Experts%7C"
1240 . "Saison%204%20des%20Experts%7CSaison%205%20des%20Experts%7CSaison%206%20des%20Experts%7C"
1241 . "Saison%207%20des%20Experts%7CSaison%208%20des%20Experts%7CSaison%209%20des%20Experts%7C"
1242 . "Sara%20Sidle%7CSofia%20Curtis%7CS%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e%7CWallace%20Langham%7C"
1243 . "Warrick%20Brown%7CWendy%20Simms%7C%C3%89tats-Unis"
1248 "Mod%C3%A8le%3AArrondissements%20homonymes%7CMod%C3%A8le%3ABandeau%20standard%20pour%20page%20d'homonymie%7C"
1249 . "Mod%C3%A8le%3ABatailles%20homonymes%7CMod%C3%A8le%3ACantons%20homonymes%7C"
1250 . "Mod%C3%A8le%3ACommunes%20fran%C3%A7aises%20homonymes%7CMod%C3%A8le%3AFilms%20homonymes%7C"
1251 . "Mod%C3%A8le%3AGouvernements%20homonymes%7CMod%C3%A8le%3AGuerres%20homonymes%7CMod%C3%A8le%3AHomonymie%7C"
1252 . "Mod%C3%A8le%3AHomonymie%20bateau%7CMod%C3%A8le%3AHomonymie%20d'%C3%A9tablissements%20scolaires%20ou"
1253 . "%20universitaires%7CMod%C3%A8le%3AHomonymie%20d'%C3%AEles%7CMod%C3%A8le%3AHomonymie%20de%20clubs%20sportifs%7C"
1254 . "Mod%C3%A8le%3AHomonymie%20de%20comt%C3%A9s%7CMod%C3%A8le%3AHomonymie%20de%20monument%7C"
1255 . "Mod%C3%A8le%3AHomonymie%20de%20nom%20romain%7CMod%C3%A8le%3AHomonymie%20de%20parti%20politique%7C"
1256 . "Mod%C3%A8le%3AHomonymie%20de%20route%7CMod%C3%A8le%3AHomonymie%20dynastique%7C"
1257 . "Mod%C3%A8le%3AHomonymie%20vid%C3%A9oludique%7CMod%C3%A8le%3AHomonymie%20%C3%A9difice%20religieux%7C"
1258 . "Mod%C3%A8le%3AInternationalisation%7CMod%C3%A8le%3AIsom%C3%A9rie%7CMod%C3%A8le%3AParonymie%7C"
1259 . "Mod%C3%A8le%3APatronyme%7CMod%C3%A8le%3APatronyme%20basque%7CMod%C3%A8le%3APatronyme%20italien%7C"
1260 . "Mod%C3%A8le%3APatronymie%7CMod%C3%A8le%3APersonnes%20homonymes%7CMod%C3%A8le%3ASaints%20homonymes%7C"
1261 . "Mod%C3%A8le%3ATitres%20homonymes%7CMod%C3%A8le%3AToponymie%7CMod%C3%A8le%3AUnit%C3%A9s%20homonymes%7C"
1262 . "Mod%C3%A8le%3AVilles%20homonymes%7CMod%C3%A8le%3A%C3%89difices%20religieux%20homonymes"
1269 * @dataProvider provideRomanNumeralsData
1271 function testRomanNumerals( $num, $numerals ) {
1272 $this->assertEquals(
1274 Language
::romanNumeral( $num ),
1275 "romanNumeral('$num')"
1279 public static function provideRomanNumeralsData() {
1294 array( 49, 'XLIX' ),
1298 array( 80, 'LXXX' ),
1300 array( 99, 'XCIX' ),
1303 array( 300, 'CCC' ),
1307 array( 700, 'DCC' ),
1308 array( 800, 'DCCC' ),
1310 array( 999, 'CMXCIX' ),
1312 array( 1989, 'MCMLXXXIX' ),
1313 array( 2000, 'MM' ),
1314 array( 3000, 'MMM' ),
1315 array( 4000, 'MMMM' ),
1316 array( 5000, 'MMMMM' ),
1317 array( 6000, 'MMMMMM' ),
1318 array( 7000, 'MMMMMMM' ),
1319 array( 8000, 'MMMMMMMM' ),
1320 array( 9000, 'MMMMMMMMM' ),
1321 array( 9999, 'MMMMMMMMMCMXCIX' ),
1322 array( 10000, 'MMMMMMMMMM' ),
1327 * @dataProvider providePluralData
1329 function testConvertPlural( $expected, $number, $forms ) {
1330 $chosen = $this->getLang()->convertPlural( $number, $forms );
1331 $this->assertEquals( $expected, $chosen );
1334 public static function providePluralData() {
1335 // Params are: [expected text, number given, [the plural forms]]
1337 array( 'plural', 0, array(
1338 'singular', 'plural'
1340 array( 'explicit zero', 0, array(
1341 '0=explicit zero', 'singular', 'plural'
1343 array( 'explicit one', 1, array(
1344 'singular', 'plural', '1=explicit one',
1346 array( 'singular', 1, array(
1347 'singular', 'plural', '0=explicit zero',
1349 array( 'plural', 3, array(
1350 '0=explicit zero', '1=explicit one', 'singular', 'plural'
1352 array( 'explicit eleven', 11, array(
1353 'singular', 'plural', '11=explicit eleven',
1355 array( 'plural', 12, array(
1356 'singular', 'plural', '11=explicit twelve',
1358 array( 'plural', 12, array(
1359 'singular', 'plural', '=explicit form',
1361 array( 'other', 2, array(
1362 'kissa=kala', '1=2=3', 'other',
1368 * @covers Language::translateBlockExpiry()
1369 * @dataProvider provideTranslateBlockExpiry
1371 function testTranslateBlockExpiry( $expectedData, $str, $desc ) {
1372 $lang = $this->getLang();
1373 if ( is_array( $expectedData ) ) {
1374 list( $func, $arg ) = $expectedData;
1375 $expected = $lang->$func( $arg );
1377 $expected = $expectedData;
1379 $this->assertEquals( $expected, $lang->translateBlockExpiry( $str ), $desc );
1382 public static function provideTranslateBlockExpiry() {
1384 array( '2 hours', '2 hours', 'simple data from ipboptions' ),
1385 array( 'indefinite', 'infinite', 'infinite from ipboptions' ),
1386 array( 'indefinite', 'infinity', 'alternative infinite from ipboptions' ),
1387 array( 'indefinite', 'indefinite', 'another alternative infinite from ipboptions' ),
1388 array( array( 'formatDuration', 1023 * 60 * 60 ), '1023 hours', 'relative' ),
1389 array( array( 'formatDuration', -1023 ), '-1023 seconds', 'negative relative' ),
1390 array( array( 'formatDuration', 0 ), 'now', 'now' ),
1391 array( array( 'timeanddate', '20120102070000' ), '2012-1-1 7:00 +1 day', 'mixed, handled as absolute' ),
1392 array( array( 'timeanddate', '19910203040506' ), '1991-2-3 4:05:06', 'absolute' ),
1393 array( array( 'timeanddate', '19700101000000' ), '1970-1-1 0:00:00', 'absolute at epoch' ),
1394 array( array( 'timeanddate', '19691231235959' ), '1969-12-31 23:59:59', 'time before epoch' ),
1395 array( 'dummy', 'dummy', 'return garbage as is' ),
1400 * @covers Language::commafy()
1401 * @dataProvider provideCommafyData
1403 function testCommafy( $number, $numbersWithCommas ) {
1404 $this->assertEquals(
1406 $this->getLang()->commafy( $number ),
1407 "commafy('$number')"
1411 public static function provideCommafyData() {
1415 array( 100, '100' ),
1416 array( 1000, '1,000' ),
1417 array( 10000, '10,000' ),
1418 array( 100000, '100,000' ),
1419 array( 1000000, '1,000,000' ),
1420 array( 1.0001, '1.0001' ),
1421 array( 10.0001, '10.0001' ),
1422 array( 100.0001, '100.0001' ),
1423 array( 1000.0001, '1,000.0001' ),
1424 array( 10000.0001, '10,000.0001' ),
1425 array( 100000.0001, '100,000.0001' ),
1426 array( 1000000.0001, '1,000,000.0001' ),
1430 function testListToText() {
1431 $lang = $this->getLang();
1432 $and = $lang->getMessageFromDB( 'and' );
1433 $s = $lang->getMessageFromDB( 'word-separator' );
1434 $c = $lang->getMessageFromDB( 'comma-separator' );
1436 $this->assertEquals( '', $lang->listToText( array() ) );
1437 $this->assertEquals( 'a', $lang->listToText( array( 'a' ) ) );
1438 $this->assertEquals( "a{$and}{$s}b", $lang->listToText( array( 'a', 'b' ) ) );
1439 $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( array( 'a', 'b', 'c' ) ) );
1440 $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( array( 'a', 'b', 'c', 'd' ) ) );
1444 * @dataProvider provideIsSupportedLanguage
1446 function testIsSupportedLanguage( $code, $expected, $comment ) {
1447 $this->assertEquals( $expected, Language
::isSupportedLanguage( $code ), $comment );
1450 public static function provideIsSupportedLanguage() {
1452 array( 'en', true, 'is supported language' ),
1453 array( 'fi', true, 'is supported language' ),
1454 array( 'bunny', false, 'is not supported language' ),
1455 array( 'FI', false, 'is not supported language, input should be in lower case' ),