Removed Toki Pona localization files
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageTest.php
1 <?php
2
3 class LanguageTest extends LanguageClassesTestCase {
4 /**
5 * @covers Language::convertDoubleWidth
6 * @covers Language::normalizeForSearch
7 */
8 public function testLanguageConvertDoubleWidthToSingleWidth() {
9 $this->assertEquals(
10 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
11 $this->getLang()->normalizeForSearch(
12 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
13 ),
14 'convertDoubleWidth() with the full alphabet and digits'
15 );
16 }
17
18 /**
19 * @dataProvider provideFormattableTimes
20 * @covers Language::formatTimePeriod
21 */
22 public function testFormatTimePeriod( $seconds, $format, $expected, $desc ) {
23 $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc );
24 }
25
26 public static function provideFormattableTimes() {
27 return [
28 [
29 9.45,
30 [],
31 '9.5 s',
32 'formatTimePeriod() rounding (<10s)'
33 ],
34 [
35 9.45,
36 [ 'noabbrevs' => true ],
37 '9.5 seconds',
38 'formatTimePeriod() rounding (<10s)'
39 ],
40 [
41 9.95,
42 [],
43 '10 s',
44 'formatTimePeriod() rounding (<10s)'
45 ],
46 [
47 9.95,
48 [ 'noabbrevs' => true ],
49 '10 seconds',
50 'formatTimePeriod() rounding (<10s)'
51 ],
52 [
53 59.55,
54 [],
55 '1 min 0 s',
56 'formatTimePeriod() rounding (<60s)'
57 ],
58 [
59 59.55,
60 [ 'noabbrevs' => true ],
61 '1 minute 0 seconds',
62 'formatTimePeriod() rounding (<60s)'
63 ],
64 [
65 119.55,
66 [],
67 '2 min 0 s',
68 'formatTimePeriod() rounding (<1h)'
69 ],
70 [
71 119.55,
72 [ 'noabbrevs' => true ],
73 '2 minutes 0 seconds',
74 'formatTimePeriod() rounding (<1h)'
75 ],
76 [
77 3599.55,
78 [],
79 '1 h 0 min 0 s',
80 'formatTimePeriod() rounding (<1h)'
81 ],
82 [
83 3599.55,
84 [ 'noabbrevs' => true ],
85 '1 hour 0 minutes 0 seconds',
86 'formatTimePeriod() rounding (<1h)'
87 ],
88 [
89 7199.55,
90 [],
91 '2 h 0 min 0 s',
92 'formatTimePeriod() rounding (>=1h)'
93 ],
94 [
95 7199.55,
96 [ 'noabbrevs' => true ],
97 '2 hours 0 minutes 0 seconds',
98 'formatTimePeriod() rounding (>=1h)'
99 ],
100 [
101 7199.55,
102 'avoidseconds',
103 '2 h 0 min',
104 'formatTimePeriod() rounding (>=1h), avoidseconds'
105 ],
106 [
107 7199.55,
108 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
109 '2 hours 0 minutes',
110 'formatTimePeriod() rounding (>=1h), avoidseconds'
111 ],
112 [
113 7199.55,
114 'avoidminutes',
115 '2 h 0 min',
116 'formatTimePeriod() rounding (>=1h), avoidminutes'
117 ],
118 [
119 7199.55,
120 [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ],
121 '2 hours 0 minutes',
122 'formatTimePeriod() rounding (>=1h), avoidminutes'
123 ],
124 [
125 172799.55,
126 'avoidseconds',
127 '48 h 0 min',
128 'formatTimePeriod() rounding (=48h), avoidseconds'
129 ],
130 [
131 172799.55,
132 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
133 '48 hours 0 minutes',
134 'formatTimePeriod() rounding (=48h), avoidseconds'
135 ],
136 [
137 259199.55,
138 'avoidminutes',
139 '3 d 0 h',
140 'formatTimePeriod() rounding (>48h), avoidminutes'
141 ],
142 [
143 259199.55,
144 [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ],
145 '3 days 0 hours',
146 'formatTimePeriod() rounding (>48h), avoidminutes'
147 ],
148 [
149 176399.55,
150 'avoidseconds',
151 '2 d 1 h 0 min',
152 'formatTimePeriod() rounding (>48h), avoidseconds'
153 ],
154 [
155 176399.55,
156 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
157 '2 days 1 hour 0 minutes',
158 'formatTimePeriod() rounding (>48h), avoidseconds'
159 ],
160 [
161 176399.55,
162 'avoidminutes',
163 '2 d 1 h',
164 'formatTimePeriod() rounding (>48h), avoidminutes'
165 ],
166 [
167 176399.55,
168 [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ],
169 '2 days 1 hour',
170 'formatTimePeriod() rounding (>48h), avoidminutes'
171 ],
172 [
173 259199.55,
174 'avoidseconds',
175 '3 d 0 h 0 min',
176 'formatTimePeriod() rounding (>48h), avoidseconds'
177 ],
178 [
179 259199.55,
180 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
181 '3 days 0 hours 0 minutes',
182 'formatTimePeriod() rounding (>48h), avoidseconds'
183 ],
184 [
185 172801.55,
186 'avoidseconds',
187 '2 d 0 h 0 min',
188 'formatTimePeriod() rounding, (>48h), avoidseconds'
189 ],
190 [
191 172801.55,
192 [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ],
193 '2 days 0 hours 0 minutes',
194 'formatTimePeriod() rounding, (>48h), avoidseconds'
195 ],
196 [
197 176460.55,
198 [],
199 '2 d 1 h 1 min 1 s',
200 'formatTimePeriod() rounding, recursion, (>48h)'
201 ],
202 [
203 176460.55,
204 [ 'noabbrevs' => true ],
205 '2 days 1 hour 1 minute 1 second',
206 'formatTimePeriod() rounding, recursion, (>48h)'
207 ],
208 ];
209 }
210
211 /**
212 * @covers Language::truncate
213 */
214 public function testTruncate() {
215 $this->assertEquals(
216 "XXX",
217 $this->getLang()->truncate( "1234567890", 0, 'XXX' ),
218 'truncate prefix, len 0, small ellipsis'
219 );
220
221 $this->assertEquals(
222 "12345XXX",
223 $this->getLang()->truncate( "1234567890", 8, 'XXX' ),
224 'truncate prefix, small ellipsis'
225 );
226
227 $this->assertEquals(
228 "123456789",
229 $this->getLang()->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ),
230 'truncate prefix, large ellipsis'
231 );
232
233 $this->assertEquals(
234 "XXX67890",
235 $this->getLang()->truncate( "1234567890", -8, 'XXX' ),
236 'truncate suffix, small ellipsis'
237 );
238
239 $this->assertEquals(
240 "123456789",
241 $this->getLang()->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ),
242 'truncate suffix, large ellipsis'
243 );
244 $this->assertEquals(
245 "123XXX",
246 $this->getLang()->truncate( "123 ", 9, 'XXX' ),
247 'truncate prefix, with spaces'
248 );
249 $this->assertEquals(
250 "12345XXX",
251 $this->getLang()->truncate( "12345 8", 11, 'XXX' ),
252 'truncate prefix, with spaces and non-space ending'
253 );
254 $this->assertEquals(
255 "XXX234",
256 $this->getLang()->truncate( "1 234", -8, 'XXX' ),
257 'truncate suffix, with spaces'
258 );
259 $this->assertEquals(
260 "12345XXX",
261 $this->getLang()->truncate( "1234567890", 5, 'XXX', false ),
262 'truncate without adjustment'
263 );
264 $this->assertEquals(
265 "泰乐菌...",
266 $this->getLang()->truncate( "泰乐菌素123456789", 11, '...', false ),
267 'truncate does not chop Unicode characters in half'
268 );
269 $this->assertEquals(
270 "\n泰乐菌...",
271 $this->getLang()->truncate( "\n泰乐菌素123456789", 12, '...', false ),
272 'truncate does not chop Unicode characters in half if there is a preceding newline'
273 );
274 }
275
276 /**
277 * @dataProvider provideHTMLTruncateData
278 * @covers Language::truncateHTML
279 */
280 public function testTruncateHtml( $len, $ellipsis, $input, $expected ) {
281 // Actual HTML...
282 $this->assertEquals(
283 $expected,
284 $this->getLang()->truncateHtml( $input, $len, $ellipsis )
285 );
286 }
287
288 /**
289 * @return array Format is ($len, $ellipsis, $input, $expected)
290 */
291 public static function provideHTMLTruncateData() {
292 return [
293 [ 0, 'XXX', "1234567890", "XXX" ],
294 [ 8, 'XXX', "1234567890", "12345XXX" ],
295 [ 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ],
296 [ 2, '***',
297 '<p><span style="font-weight:bold;"></span></p>',
298 '<p><span style="font-weight:bold;"></span></p>',
299 ],
300 [ 2, '***',
301 '<p><span style="font-weight:bold;">123456789</span></p>',
302 '<p><span style="font-weight:bold;">***</span></p>',
303 ],
304 [ 2, '***',
305 '<p><span style="font-weight:bold;">&nbsp;23456789</span></p>',
306 '<p><span style="font-weight:bold;">***</span></p>',
307 ],
308 [ 3, '***',
309 '<p><span style="font-weight:bold;">123456789</span></p>',
310 '<p><span style="font-weight:bold;">***</span></p>',
311 ],
312 [ 4, '***',
313 '<p><span style="font-weight:bold;">123456789</span></p>',
314 '<p><span style="font-weight:bold;">1***</span></p>',
315 ],
316 [ 5, '***',
317 '<tt><span style="font-weight:bold;">123456789</span></tt>',
318 '<tt><span style="font-weight:bold;">12***</span></tt>',
319 ],
320 [ 6, '***',
321 '<p><a href="www.mediawiki.org">123456789</a></p>',
322 '<p><a href="www.mediawiki.org">123***</a></p>',
323 ],
324 [ 6, '***',
325 '<p><a href="www.mediawiki.org">12&nbsp;456789</a></p>',
326 '<p><a href="www.mediawiki.org">12&nbsp;***</a></p>',
327 ],
328 [ 7, '***',
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>',
331 ],
332 [ 8, '***',
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>',
335 ],
336 [ 9, '***',
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>',
339 ],
340 [ 10, '***',
341 '<p><font style="font-weight:bold;">123456789</font></p>',
342 '<p><font style="font-weight:bold;">123456789</font></p>',
343 ],
344 ];
345 }
346
347 /**
348 * Test Language::isWellFormedLanguageTag()
349 * @dataProvider provideWellFormedLanguageTags
350 * @covers Language::isWellFormedLanguageTag
351 */
352 public function testWellFormedLanguageTag( $code, $message = '' ) {
353 $this->assertTrue(
354 Language::isWellFormedLanguageTag( $code ),
355 "validating code $code $message"
356 );
357 }
358
359 /**
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
364 */
365 public static function provideWellFormedLanguageTags() {
366 return [
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' ],
396 ];
397 }
398
399 /**
400 * Negative test for Language::isWellFormedLanguageTag()
401 * @dataProvider provideMalformedLanguageTags
402 * @covers Language::isWellFormedLanguageTag
403 */
404 public function testMalformedLanguageTag( $code, $message = '' ) {
405 $this->assertFalse(
406 Language::isWellFormedLanguageTag( $code ),
407 "validating that code $code is a malformed language tag - $message"
408 );
409 }
410
411 /**
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
416 */
417 public static function provideMalformedLanguageTags() {
418 return [
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' ],
425 [
426 'i-notexist',
427 'grandfathered but not registered: invalid, even if we only test well-formedness'
428 ],
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' ],
451 ];
452 }
453
454 /**
455 * Negative test for Language::isWellFormedLanguageTag()
456 * @covers Language::isWellFormedLanguageTag
457 */
458 public function testLenientLanguageTag() {
459 $this->assertTrue(
460 Language::isWellFormedLanguageTag( 'pa_guru', true ),
461 'pa_guru is a well-formed language tag in lenient mode'
462 );
463 }
464
465 /**
466 * Test Language::isValidBuiltInCode()
467 * @dataProvider provideLanguageCodes
468 * @covers Language::isValidBuiltInCode
469 */
470 public function testBuiltInCodeValidation( $code, $expected, $message = '' ) {
471 $this->assertEquals( $expected,
472 (bool)Language::isValidBuiltInCode( $code ),
473 "validating code $code $message"
474 );
475 }
476
477 public static function provideLanguageCodes() {
478 return [
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' ],
485 ];
486 }
487
488 /**
489 * Test Language::isKnownLanguageTag()
490 * @dataProvider provideKnownLanguageTags
491 * @covers Language::isKnownLanguageTag
492 */
493 public function testKnownLanguageTag( $code, $message = '' ) {
494 $this->assertTrue(
495 (bool)Language::isKnownLanguageTag( $code ),
496 "validating code $code - $message"
497 );
498 }
499
500 public static function provideKnownLanguageTags() {
501 return [
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' ],
505 ];
506 }
507
508 /**
509 * @covers Language::isKnownLanguageTag
510 */
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.' );
515 }
516
517 $this->assertTrue(
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'
521 );
522 }
523
524 /**
525 * Negative tests for Language::isKnownLanguageTag()
526 * @dataProvider provideUnKnownLanguageTags
527 * @covers Language::isKnownLanguageTag
528 */
529 public function testUnknownLanguageTag( $code, $message = '' ) {
530 $this->assertFalse(
531 (bool)Language::isKnownLanguageTag( $code ),
532 "checking that code $code is invalid - $message"
533 );
534 }
535
536 public static function provideUnknownLanguageTags() {
537 return [
538 [ 'mw', 'non-existent two-letter code' ],
539 [ 'foo"<bar', 'very invalid language code' ],
540 ];
541 }
542
543 /**
544 * Test too short timestamp
545 * @expectedException MWException
546 * @covers Language::sprintfDate
547 */
548 public function testSprintfDateTooShortTimestamp() {
549 $this->getLang()->sprintfDate( 'xiY', '1234567890123' );
550 }
551
552 /**
553 * Test too long timestamp
554 * @expectedException MWException
555 * @covers Language::sprintfDate
556 */
557 public function testSprintfDateTooLongTimestamp() {
558 $this->getLang()->sprintfDate( 'xiY', '123456789012345' );
559 }
560
561 /**
562 * Test too short timestamp
563 * @expectedException MWException
564 * @covers Language::sprintfDate
565 */
566 public function testSprintfDateNotAllDigitTimestamp() {
567 $this->getLang()->sprintfDate( 'xiY', '-1234567890123' );
568 }
569
570 /**
571 * @dataProvider provideSprintfDateSamples
572 * @covers Language::sprintfDate
573 */
574 public function testSprintfDate( $format, $ts, $expected, $msg ) {
575 $ttl = null;
576 $this->assertEquals(
577 $expected,
578 $this->getLang()->sprintfDate( $format, $ts, null, $ttl ),
579 "sprintfDate('$format', '$ts'): $msg"
580 );
581 if ( $ttl ) {
582 $dt = new DateTime( $ts );
583 $lastValidTS = $dt->add( new DateInterval( 'PT' . ( $ttl - 1 ) . 'S' ) )->format( 'YmdHis' );
584 $this->assertEquals(
585 $expected,
586 $this->getLang()->sprintfDate( $format, $lastValidTS, null ),
587 "sprintfDate('$format', '$ts'): TTL $ttl too high (output was different at $lastValidTS)"
588 );
589 } else {
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' );
593 $this->assertEquals(
594 $expected,
595 $this->getLang()->sprintfDate( $format, $newTS, null ),
596 "sprintfDate('$format', '$ts'): Missing TTL (output was different at $newTS)"
597 );
598 }
599 }
600
601 /**
602 * sprintfDate should always use UTC when no zone is given.
603 * @dataProvider provideSprintfDateSamples
604 * @covers Language::sprintfDate
605 */
606 public function testSprintfDateNoZone( $format, $ts, $expected, $ignore, $msg ) {
607 $oldTZ = date_default_timezone_get();
608 $res = date_default_timezone_set( 'Asia/Seoul' );
609 if ( !$res ) {
610 $this->markTestSkipped( "Error setting Timezone" );
611 }
612
613 $this->assertEquals(
614 $expected,
615 $this->getLang()->sprintfDate( $format, $ts ),
616 "sprintfDate('$format', '$ts'): $msg"
617 );
618
619 date_default_timezone_set( $oldTZ );
620 }
621
622 /**
623 * sprintfDate should use passed timezone
624 * @dataProvider provideSprintfDateSamples
625 * @covers Language::sprintfDate
626 */
627 public function testSprintfDateTZ( $format, $ts, $ignore, $expected, $msg ) {
628 $tz = new DateTimeZone( 'Asia/Seoul' );
629 if ( !$tz ) {
630 $this->markTestSkipped( "Error getting Timezone" );
631 }
632
633 $this->assertEquals(
634 $expected,
635 $this->getLang()->sprintfDate( $format, $ts, $tz ),
636 "sprintfDate('$format', '$ts', 'Asia/Seoul'): $msg"
637 );
638 }
639
640 /**
641 * sprintfDate should only calculate a TTL if the caller is going to use it.
642 * @covers Language::sprintfDate
643 */
644 public function testSprintfDateNoTtlIfNotNeeded() {
645 $noTtl = 'unused'; // Value used to represent that the caller didn't pass a variable in.
646 $ttl = null;
647 $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $noTtl );
648 $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $ttl );
649
650 $this->assertSame(
651 'unused',
652 $noTtl,
653 'If the caller does not set the $ttl variable, do not compute it.'
654 );
655 $this->assertInternalType( 'int', $ttl, 'TTL should have been computed.' );
656 }
657
658 public static function provideSprintfDateSamples() {
659 return [
660 [
661 'xiY',
662 '20111212000000',
663 '1390', // note because we're testing English locale we get Latin-standard digits
664 '1390',
665 'Iranian calendar full year'
666 ],
667 [
668 'xiy',
669 '20111212000000',
670 '90',
671 '90',
672 'Iranian calendar short year'
673 ],
674 [
675 'o',
676 '20120101235000',
677 '2011',
678 '2011',
679 'ISO 8601 (week) year'
680 ],
681 [
682 'W',
683 '20120101235000',
684 '52',
685 '52',
686 'Week number'
687 ],
688 [
689 'W',
690 '20120102235000',
691 '1',
692 '1',
693 'Week number'
694 ],
695 [
696 'o-\\WW-N',
697 '20091231235000',
698 '2009-W53-4',
699 '2009-W53-4',
700 'leap week'
701 ],
702 // What follows is mostly copied from
703 // https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time
704 [
705 'Y',
706 '20120102090705',
707 '2012',
708 '2012',
709 'Full year'
710 ],
711 [
712 'y',
713 '20120102090705',
714 '12',
715 '12',
716 '2 digit year'
717 ],
718 [
719 'L',
720 '20120102090705',
721 '1',
722 '1',
723 'Leap year'
724 ],
725 [
726 'n',
727 '20120102090705',
728 '1',
729 '1',
730 'Month index, not zero pad'
731 ],
732 [
733 'N',
734 '20120102090705',
735 '01',
736 '01',
737 'Month index. Zero pad'
738 ],
739 [
740 'M',
741 '20120102090705',
742 'Jan',
743 'Jan',
744 'Month abbrev'
745 ],
746 [
747 'F',
748 '20120102090705',
749 'January',
750 'January',
751 'Full month'
752 ],
753 [
754 'xg',
755 '20120102090705',
756 'January',
757 'January',
758 'Genitive month name (same in EN)'
759 ],
760 [
761 'j',
762 '20120102090705',
763 '2',
764 '2',
765 'Day of month (not zero pad)'
766 ],
767 [
768 'd',
769 '20120102090705',
770 '02',
771 '02',
772 'Day of month (zero-pad)'
773 ],
774 [
775 'z',
776 '20120102090705',
777 '1',
778 '1',
779 'Day of year (zero-indexed)'
780 ],
781 [
782 'D',
783 '20120102090705',
784 'Mon',
785 'Mon',
786 'Day of week (abbrev)'
787 ],
788 [
789 'l',
790 '20120102090705',
791 'Monday',
792 'Monday',
793 'Full day of week'
794 ],
795 [
796 'N',
797 '20120101090705',
798 '7',
799 '7',
800 'Day of week (Mon=1, Sun=7)'
801 ],
802 [
803 'w',
804 '20120101090705',
805 '0',
806 '0',
807 'Day of week (Sun=0, Sat=6)'
808 ],
809 [
810 'N',
811 '20120102090705',
812 '1',
813 '1',
814 'Day of week'
815 ],
816 [
817 'a',
818 '20120102090705',
819 'am',
820 'am',
821 'am vs pm'
822 ],
823 [
824 'A',
825 '20120102120000',
826 'PM',
827 'PM',
828 'AM vs PM'
829 ],
830 [
831 'a',
832 '20120102000000',
833 'am',
834 'am',
835 'AM vs PM'
836 ],
837 [
838 'g',
839 '20120102090705',
840 '9',
841 '9',
842 '12 hour, not Zero'
843 ],
844 [
845 'h',
846 '20120102090705',
847 '09',
848 '09',
849 '12 hour, zero padded'
850 ],
851 [
852 'G',
853 '20120102090705',
854 '9',
855 '9',
856 '24 hour, not zero'
857 ],
858 [
859 'H',
860 '20120102090705',
861 '09',
862 '09',
863 '24 hour, zero'
864 ],
865 [
866 'H',
867 '20120102110705',
868 '11',
869 '11',
870 '24 hour, zero'
871 ],
872 [
873 'i',
874 '20120102090705',
875 '07',
876 '07',
877 'Minutes'
878 ],
879 [
880 's',
881 '20120102090705',
882 '05',
883 '05',
884 'seconds'
885 ],
886 [
887 'U',
888 '20120102090705',
889 '1325495225',
890 '1325462825',
891 'unix time'
892 ],
893 [
894 't',
895 '20120102090705',
896 '31',
897 '31',
898 'Days in current month'
899 ],
900 [
901 'c',
902 '20120102090705',
903 '2012-01-02T09:07:05+00:00',
904 '2012-01-02T09:07:05+09:00',
905 'ISO 8601 timestamp'
906 ],
907 [
908 'r',
909 '20120102090705',
910 'Mon, 02 Jan 2012 09:07:05 +0000',
911 'Mon, 02 Jan 2012 09:07:05 +0900',
912 'RFC 5322'
913 ],
914 [
915 'e',
916 '20120102090705',
917 'UTC',
918 'Asia/Seoul',
919 'Timezone identifier'
920 ],
921 [
922 'I',
923 '19880602090705',
924 '0',
925 '1',
926 'DST indicator'
927 ],
928 [
929 'O',
930 '20120102090705',
931 '+0000',
932 '+0900',
933 'Timezone offset'
934 ],
935 [
936 'P',
937 '20120102090705',
938 '+00:00',
939 '+09:00',
940 'Timezone offset with colon'
941 ],
942 [
943 'T',
944 '20120102090705',
945 'UTC',
946 'KST',
947 'Timezone abbreviation'
948 ],
949 [
950 'Z',
951 '20120102090705',
952 '0',
953 '32400',
954 'Timezone offset in seconds'
955 ],
956 [
957 'xmj xmF xmn xmY',
958 '20120102090705',
959 '7 Safar 2 1433',
960 '7 Safar 2 1433',
961 'Islamic'
962 ],
963 [
964 'xij xiF xin xiY',
965 '20120102090705',
966 '12 Dey 10 1390',
967 '12 Dey 10 1390',
968 'Iranian'
969 ],
970 [
971 'xjj xjF xjn xjY',
972 '20120102090705',
973 '7 Tevet 4 5772',
974 '7 Tevet 4 5772',
975 'Hebrew'
976 ],
977 [
978 'xjt',
979 '20120102090705',
980 '29',
981 '29',
982 'Hebrew number of days in month'
983 ],
984 [
985 'xjx',
986 '20120102090705',
987 'Tevet',
988 'Tevet',
989 'Hebrew genitive month name (No difference in EN)'
990 ],
991 [
992 'xkY',
993 '20120102090705',
994 '2555',
995 '2555',
996 'Thai year'
997 ],
998 [
999 'xoY',
1000 '20120102090705',
1001 '101',
1002 '101',
1003 'Minguo'
1004 ],
1005 [
1006 'xtY',
1007 '20120102090705',
1008 '平成24',
1009 '平成24',
1010 'nengo'
1011 ],
1012 [
1013 'xrxkYY',
1014 '20120102090705',
1015 'MMDLV2012',
1016 'MMDLV2012',
1017 'Roman numerals'
1018 ],
1019 [
1020 'xhxjYY',
1021 '20120102090705',
1022 \'תשע"ב2012',
1023 \'תשע"ב2012',
1024 'Hebrew numberals'
1025 ],
1026 [
1027 'xnY',
1028 '20120102090705',
1029 '2012',
1030 '2012',
1031 'Raw numerals (doesn\'t mean much in EN)'
1032 ],
1033 [
1034 '[[Y "(yea"\\r)]] \\"xx\\"',
1035 '20120102090705',
1036 '[[2012 (year)]] "x"',
1037 '[[2012 (year)]] "x"',
1038 'Various escaping'
1039 ],
1040
1041 ];
1042 }
1043
1044 /**
1045 * @dataProvider provideFormatSizes
1046 * @covers Language::formatSize
1047 */
1048 public function testFormatSize( $size, $expected, $msg ) {
1049 $this->assertEquals(
1050 $expected,
1051 $this->getLang()->formatSize( $size ),
1052 "formatSize('$size'): $msg"
1053 );
1054 }
1055
1056 public static function provideFormatSizes() {
1057 return [
1058 [
1059 0,
1060 "0 bytes",
1061 "Zero bytes"
1062 ],
1063 [
1064 1024,
1065 "1 KB",
1066 "1 kilobyte"
1067 ],
1068 [
1069 1024 * 1024,
1070 "1 MB",
1071 "1,024 megabytes"
1072 ],
1073 [
1074 1024 * 1024 * 1024,
1075 "1 GB",
1076 "1 gigabyte"
1077 ],
1078 [
1079 pow( 1024, 4 ),
1080 "1 TB",
1081 "1 terabyte"
1082 ],
1083 [
1084 pow( 1024, 5 ),
1085 "1 PB",
1086 "1 petabyte"
1087 ],
1088 [
1089 pow( 1024, 6 ),
1090 "1 EB",
1091 "1,024 exabyte"
1092 ],
1093 [
1094 pow( 1024, 7 ),
1095 "1 ZB",
1096 "1 zetabyte"
1097 ],
1098 [
1099 pow( 1024, 8 ),
1100 "1 YB",
1101 "1 yottabyte"
1102 ],
1103 // How big!? THIS BIG!
1104 ];
1105 }
1106
1107 /**
1108 * @dataProvider provideFormatBitrate
1109 * @covers Language::formatBitrate
1110 */
1111 public function testFormatBitrate( $bps, $expected, $msg ) {
1112 $this->assertEquals(
1113 $expected,
1114 $this->getLang()->formatBitrate( $bps ),
1115 "formatBitrate('$bps'): $msg"
1116 );
1117 }
1118
1119 public static function provideFormatBitrate() {
1120 return [
1121 [
1122 0,
1123 "0 bps",
1124 "0 bits per second"
1125 ],
1126 [
1127 999,
1128 "999 bps",
1129 "999 bits per second"
1130 ],
1131 [
1132 1000,
1133 "1 kbps",
1134 "1 kilobit per second"
1135 ],
1136 [
1137 1000 * 1000,
1138 "1 Mbps",
1139 "1 megabit per second"
1140 ],
1141 [
1142 pow( 10, 9 ),
1143 "1 Gbps",
1144 "1 gigabit per second"
1145 ],
1146 [
1147 pow( 10, 12 ),
1148 "1 Tbps",
1149 "1 terabit per second"
1150 ],
1151 [
1152 pow( 10, 15 ),
1153 "1 Pbps",
1154 "1 petabit per second"
1155 ],
1156 [
1157 pow( 10, 18 ),
1158 "1 Ebps",
1159 "1 exabit per second"
1160 ],
1161 [
1162 pow( 10, 21 ),
1163 "1 Zbps",
1164 "1 zetabit per second"
1165 ],
1166 [
1167 pow( 10, 24 ),
1168 "1 Ybps",
1169 "1 yottabit per second"
1170 ],
1171 [
1172 pow( 10, 27 ),
1173 "1,000 Ybps",
1174 "1,000 yottabits per second"
1175 ],
1176 ];
1177 }
1178
1179 /**
1180 * @dataProvider provideFormatDuration
1181 * @covers Language::formatDuration
1182 */
1183 public function testFormatDuration( $duration, $expected, $intervals = [] ) {
1184 $this->assertEquals(
1185 $expected,
1186 $this->getLang()->formatDuration( $duration, $intervals ),
1187 "formatDuration('$duration'): $expected"
1188 );
1189 }
1190
1191 public static function provideFormatDuration() {
1192 return [
1193 [
1194 0,
1195 '0 seconds',
1196 ],
1197 [
1198 1,
1199 '1 second',
1200 ],
1201 [
1202 2,
1203 '2 seconds',
1204 ],
1205 [
1206 60,
1207 '1 minute',
1208 ],
1209 [
1210 2 * 60,
1211 '2 minutes',
1212 ],
1213 [
1214 3600,
1215 '1 hour',
1216 ],
1217 [
1218 2 * 3600,
1219 '2 hours',
1220 ],
1221 [
1222 24 * 3600,
1223 '1 day',
1224 ],
1225 [
1226 2 * 86400,
1227 '2 days',
1228 ],
1229 [
1230 // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952
1231 ( 365 + ( 24 * 3 + 25 ) / 400.0 ) * 86400,
1232 '1 year',
1233 ],
1234 [
1235 2 * 31556952,
1236 '2 years',
1237 ],
1238 [
1239 10 * 31556952,
1240 '1 decade',
1241 ],
1242 [
1243 20 * 31556952,
1244 '2 decades',
1245 ],
1246 [
1247 100 * 31556952,
1248 '1 century',
1249 ],
1250 [
1251 200 * 31556952,
1252 '2 centuries',
1253 ],
1254 [
1255 1000 * 31556952,
1256 '1 millennium',
1257 ],
1258 [
1259 2000 * 31556952,
1260 '2 millennia',
1261 ],
1262 [
1263 9001,
1264 '2 hours, 30 minutes and 1 second'
1265 ],
1266 [
1267 3601,
1268 '1 hour and 1 second'
1269 ],
1270 [
1271 31556952 + 2 * 86400 + 9000,
1272 '1 year, 2 days, 2 hours and 30 minutes'
1273 ],
1274 [
1275 42 * 1000 * 31556952 + 42,
1276 '42 millennia and 42 seconds'
1277 ],
1278 [
1279 60,
1280 '60 seconds',
1281 [ 'seconds' ],
1282 ],
1283 [
1284 61,
1285 '61 seconds',
1286 [ 'seconds' ],
1287 ],
1288 [
1289 1,
1290 '1 second',
1291 [ 'seconds' ],
1292 ],
1293 [
1294 31556952 + 2 * 86400 + 9000,
1295 '1 year, 2 days and 150 minutes',
1296 [ 'years', 'days', 'minutes' ],
1297 ],
1298 [
1299 42,
1300 '0 days',
1301 [ 'years', 'days' ],
1302 ],
1303 [
1304 31556952 + 2 * 86400 + 9000,
1305 '1 year, 2 days and 150 minutes',
1306 [ 'minutes', 'days', 'years' ],
1307 ],
1308 [
1309 42,
1310 '0 days',
1311 [ 'days', 'years' ],
1312 ],
1313 ];
1314 }
1315
1316 /**
1317 * @dataProvider provideCheckTitleEncodingData
1318 * @covers Language::checkTitleEncoding
1319 */
1320 public function testCheckTitleEncoding( $s ) {
1321 $this->assertEquals(
1322 $s,
1323 $this->getLang()->checkTitleEncoding( $s ),
1324 "checkTitleEncoding('$s')"
1325 );
1326 }
1327
1328 public static function provideCheckTitleEncodingData() {
1329 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
1330 return [
1331 [ "" ],
1332 [ "United States of America" ], // 7bit ASCII
1333 [ rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ],
1334 [
1335 rawurldecode(
1336 "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn"
1337 )
1338 ],
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.
1342 [
1343 rawurldecode(
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"
1358 ),
1359 ],
1360 [
1361 rawurldecode(
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"
1377 )
1378 ]
1379 ];
1380 // @codingStandardsIgnoreEnd
1381 }
1382
1383 /**
1384 * @dataProvider provideRomanNumeralsData
1385 * @covers Language::romanNumeral
1386 */
1387 public function testRomanNumerals( $num, $numerals ) {
1388 $this->assertEquals(
1389 $numerals,
1390 Language::romanNumeral( $num ),
1391 "romanNumeral('$num')"
1392 );
1393 }
1394
1395 public static function provideRomanNumeralsData() {
1396 return [
1397 [ 1, 'I' ],
1398 [ 2, 'II' ],
1399 [ 3, 'III' ],
1400 [ 4, 'IV' ],
1401 [ 5, 'V' ],
1402 [ 6, 'VI' ],
1403 [ 7, 'VII' ],
1404 [ 8, 'VIII' ],
1405 [ 9, 'IX' ],
1406 [ 10, 'X' ],
1407 [ 20, 'XX' ],
1408 [ 30, 'XXX' ],
1409 [ 40, 'XL' ],
1410 [ 49, 'XLIX' ],
1411 [ 50, 'L' ],
1412 [ 60, 'LX' ],
1413 [ 70, 'LXX' ],
1414 [ 80, 'LXXX' ],
1415 [ 90, 'XC' ],
1416 [ 99, 'XCIX' ],
1417 [ 100, 'C' ],
1418 [ 200, 'CC' ],
1419 [ 300, 'CCC' ],
1420 [ 400, 'CD' ],
1421 [ 500, 'D' ],
1422 [ 600, 'DC' ],
1423 [ 700, 'DCC' ],
1424 [ 800, 'DCCC' ],
1425 [ 900, 'CM' ],
1426 [ 999, 'CMXCIX' ],
1427 [ 1000, 'M' ],
1428 [ 1989, 'MCMLXXXIX' ],
1429 [ 2000, 'MM' ],
1430 [ 3000, 'MMM' ],
1431 [ 4000, 'MMMM' ],
1432 [ 5000, 'MMMMM' ],
1433 [ 6000, 'MMMMMM' ],
1434 [ 7000, 'MMMMMMM' ],
1435 [ 8000, 'MMMMMMMM' ],
1436 [ 9000, 'MMMMMMMMM' ],
1437 [ 9999, 'MMMMMMMMMCMXCIX' ],
1438 [ 10000, 'MMMMMMMMMM' ],
1439 ];
1440 }
1441
1442 /**
1443 * @dataProvider provideHebrewNumeralsData
1444 * @covers Language::hebrewNumeral
1445 */
1446 public function testHebrewNumeral( $num, $numerals ) {
1447 $this->assertEquals(
1448 $numerals,
1449 Language::hebrewNumeral( $num ),
1450 "hebrewNumeral('$num')"
1451 );
1452 }
1453
1454 public static function provideHebrewNumeralsData() {
1455 return [
1456 [ -1, -1 ],
1457 [ 0, 0 ],
1458 [ 1, "א'" ],
1459 [ 2, "ב'" ],
1460 [ 3, "ג'" ],
1461 [ 4, "ד'" ],
1462 [ 5, "ה'" ],
1463 [ 6, "ו'" ],
1464 [ 7, "ז'" ],
1465 [ 8, "ח'" ],
1466 [ 9, "ט'" ],
1467 [ 10, "י'" ],
1468 [ 11, 'י"א' ],
1469 [ 14, 'י"ד' ],
1470 [ 15, 'ט"ו' ],
1471 [ 16, 'ט"ז' ],
1472 [ 17, 'י"ז' ],
1473 [ 20, "כ'" ],
1474 [ 21, 'כ"א' ],
1475 [ 30, "ל'" ],
1476 [ 40, "מ'" ],
1477 [ 50, "נ'" ],
1478 [ 60, "ס'" ],
1479 [ 70, "ע'" ],
1480 [ 80, "פ'" ],
1481 [ 90, "צ'" ],
1482 [ 99, 'צ"ט' ],
1483 [ 100, "ק'" ],
1484 [ 101, 'ק"א' ],
1485 [ 110, 'ק"י' ],
1486 [ 200, "ר'" ],
1487 [ 300, "ש'" ],
1488 [ 400, "ת'" ],
1489 [ 500, 'ת"ק' ],
1490 [ 800, 'ת"ת' ],
1491 [ 1000, "א' אלף" ],
1492 [ 1001, "א'א'" ],
1493 [ 1012, "א'י\"ב" ],
1494 [ 1020, "א'ך'" ],
1495 [ 1030, "א'ל'" ],
1496 [ 1081, "א'פ\"א" ],
1497 [ 2000, "ב' אלפים" ],
1498 [ 2016, "ב'ט\"ז" ],
1499 [ 3000, "ג' אלפים" ],
1500 [ 4000, "ד' אלפים" ],
1501 [ 4904, "ד'תתק\"ד" ],
1502 [ 5000, "ה' אלפים" ],
1503 [ 5680, "ה'תר\"ף" ],
1504 [ 5690, "ה'תר\"ץ" ],
1505 [ 5708, "ה'תש\"ח" ],
1506 [ 5720, "ה'תש\"ך" ],
1507 [ 5740, "ה'תש\"ם" ],
1508 [ 5750, "ה'תש\"ן" ],
1509 [ 5775, "ה'תשע\"ה" ],
1510 ];
1511 }
1512
1513 /**
1514 * @dataProvider providePluralData
1515 * @covers Language::convertPlural
1516 */
1517 public function testConvertPlural( $expected, $number, $forms ) {
1518 $chosen = $this->getLang()->convertPlural( $number, $forms );
1519 $this->assertEquals( $expected, $chosen );
1520 }
1521
1522 public static function providePluralData() {
1523 // Params are: [expected text, number given, [the plural forms]]
1524 return [
1525 [ 'plural', 0, [
1526 'singular', 'plural'
1527 ] ],
1528 [ 'explicit zero', 0, [
1529 '0=explicit zero', 'singular', 'plural'
1530 ] ],
1531 [ 'explicit one', 1, [
1532 'singular', 'plural', '1=explicit one',
1533 ] ],
1534 [ 'singular', 1, [
1535 'singular', 'plural', '0=explicit zero',
1536 ] ],
1537 [ 'plural', 3, [
1538 '0=explicit zero', '1=explicit one', 'singular', 'plural'
1539 ] ],
1540 [ 'explicit eleven', 11, [
1541 'singular', 'plural', '11=explicit eleven',
1542 ] ],
1543 [ 'plural', 12, [
1544 'singular', 'plural', '11=explicit twelve',
1545 ] ],
1546 [ 'plural', 12, [
1547 'singular', 'plural', '=explicit form',
1548 ] ],
1549 [ 'other', 2, [
1550 'kissa=kala', '1=2=3', 'other',
1551 ] ],
1552 [ '', 2, [
1553 '0=explicit zero', '1=explicit one',
1554 ] ],
1555 ];
1556 }
1557
1558 /**
1559 * @covers Language::embedBidi()
1560 */
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(
1567 '123',
1568 $lang->embedBidi( '123' ),
1569 'embedBidi with neutral argument'
1570 );
1571 $this->assertEquals(
1572 $lre . 'Ben_(WMF)' . $pdf,
1573 $lang->embedBidi( 'Ben_(WMF)' ),
1574 'embedBidi with LTR argument'
1575 );
1576 $this->assertEquals(
1577 $rle . 'יהודי (מנוחין)' . $pdf,
1578 $lang->embedBidi( 'יהודי (מנוחין)' ),
1579 'embedBidi with RTL argument'
1580 );
1581 }
1582
1583 /**
1584 * @covers Language::translateBlockExpiry()
1585 * @dataProvider provideTranslateBlockExpiry
1586 */
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 );
1592 } else {
1593 $expected = $expectedData;
1594 }
1595 $this->assertEquals( $expected, $lang->translateBlockExpiry( $str, null, $now ), $desc );
1596 }
1597
1598 public static function provideTranslateBlockExpiry() {
1599 return [
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' ],
1606 [
1607 [ 'formatDuration', 1023 * 60 * 60 ],
1608 '1023 hours',
1609 wfTimestamp( TS_UNIX, '19910203040506' ),
1610 'relative with initial timestamp'
1611 ],
1612 [ [ 'formatDuration', 0 ], 'now', 0, 'now' ],
1613 [
1614 [ 'timeanddate', '20120102070000' ],
1615 '2012-1-1 7:00 +1 day',
1616 0,
1617 'mixed, handled as absolute'
1618 ],
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' ],
1622 [
1623 [ 'timeanddate', '19910910000000' ],
1624 '10 september',
1625 wfTimestamp( TS_UNIX, '19910203040506' ),
1626 'partial'
1627 ],
1628 [ 'dummy', 'dummy', 0, 'return garbage as is' ],
1629 ];
1630 }
1631
1632 /**
1633 * @dataProvider parseFormattedNumberProvider
1634 */
1635 public function testParseFormattedNumber( $langCode, $number ) {
1636 $lang = Language::factory( $langCode );
1637
1638 $localisedNum = $lang->formatNum( $number );
1639 $normalisedNum = $lang->parseFormattedNumber( $localisedNum );
1640
1641 $this->assertEquals( $number, $normalisedNum );
1642 }
1643
1644 public function parseFormattedNumberProvider() {
1645 return [
1646 [ 'de', 377.01 ],
1647 [ 'fa', 334 ],
1648 [ 'fa', 382.772 ],
1649 [ 'ar', 1844 ],
1650 [ 'lzh', 3731 ],
1651 [ 'zh-classical', 7432 ]
1652 ];
1653 }
1654
1655 /**
1656 * @covers Language::commafy()
1657 * @dataProvider provideCommafyData
1658 */
1659 public function testCommafy( $number, $numbersWithCommas ) {
1660 $this->assertEquals(
1661 $numbersWithCommas,
1662 $this->getLang()->commafy( $number ),
1663 "commafy('$number')"
1664 );
1665 }
1666
1667 public static function provideCommafyData() {
1668 return [
1669 [ -1, '-1' ],
1670 [ 10, '10' ],
1671 [ 100, '100' ],
1672 [ 1000, '1,000' ],
1673 [ 10000, '10,000' ],
1674 [ 100000, '100,000' ],
1675 [ 1000000, '1,000,000' ],
1676 [ -1.0001, '-1.0001' ],
1677 [ 1.0001, '1.0001' ],
1678 [ 10.0001, '10.0001' ],
1679 [ 100.0001, '100.0001' ],
1680 [ 1000.0001, '1,000.0001' ],
1681 [ 10000.0001, '10,000.0001' ],
1682 [ 100000.0001, '100,000.0001' ],
1683 [ 1000000.0001, '1,000,000.0001' ],
1684 [ '200000000000000000000', '200,000,000,000,000,000,000' ],
1685 [ '-200000000000000000000', '-200,000,000,000,000,000,000' ],
1686 ];
1687 }
1688
1689 /**
1690 * @covers Language::listToText
1691 */
1692 public function testListToText() {
1693 $lang = $this->getLang();
1694 $and = $lang->getMessageFromDB( 'and' );
1695 $s = $lang->getMessageFromDB( 'word-separator' );
1696 $c = $lang->getMessageFromDB( 'comma-separator' );
1697
1698 $this->assertEquals( '', $lang->listToText( [] ) );
1699 $this->assertEquals( 'a', $lang->listToText( [ 'a' ] ) );
1700 $this->assertEquals( "a{$and}{$s}b", $lang->listToText( [ 'a', 'b' ] ) );
1701 $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( [ 'a', 'b', 'c' ] ) );
1702 $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( [ 'a', 'b', 'c', 'd' ] ) );
1703 }
1704
1705 /**
1706 * @dataProvider provideIsSupportedLanguage
1707 * @covers Language::isSupportedLanguage
1708 */
1709 public function testIsSupportedLanguage( $code, $expected, $comment ) {
1710 $this->assertEquals( $expected, Language::isSupportedLanguage( $code ), $comment );
1711 }
1712
1713 public static function provideIsSupportedLanguage() {
1714 return [
1715 [ 'en', true, 'is supported language' ],
1716 [ 'fi', true, 'is supported language' ],
1717 [ 'bunny', false, 'is not supported language' ],
1718 [ 'FI', false, 'is not supported language, input should be in lower case' ],
1719 ];
1720 }
1721
1722 /**
1723 * @dataProvider provideGetParentLanguage
1724 * @covers Language::getParentLanguage
1725 */
1726 public function testGetParentLanguage( $code, $expected, $comment ) {
1727 $lang = Language::factory( $code );
1728 if ( is_null( $expected ) ) {
1729 $this->assertNull( $lang->getParentLanguage(), $comment );
1730 } else {
1731 $this->assertEquals( $expected, $lang->getParentLanguage()->getCode(), $comment );
1732 }
1733 }
1734
1735 public static function provideGetParentLanguage() {
1736 return [
1737 [ 'zh-cn', 'zh', 'zh is the parent language of zh-cn' ],
1738 [ 'zh', 'zh', 'zh is defined as the parent language of zh, '
1739 . 'because zh converter can convert zh-cn to zh' ],
1740 [ 'zh-invalid', null, 'do not be fooled by arbitrarily composed language codes' ],
1741 [ 'de-formal', null, 'de does not have converter' ],
1742 [ 'de', null, 'de does not have converter' ],
1743 ];
1744 }
1745
1746 /**
1747 * @dataProvider provideGetNamespaceAliases
1748 * @covers Language::getNamespaceAliases
1749 */
1750 public function testGetNamespaceAliases( $languageCode, $subset ) {
1751 $language = Language::factory( $languageCode );
1752 $aliases = $language->getNamespaceAliases();
1753 foreach ( $subset as $alias => $nsId ) {
1754 $this->assertEquals( $nsId, $aliases[$alias] );
1755 }
1756 }
1757
1758 public static function provideGetNamespaceAliases() {
1759 // TODO: Add tests for NS_PROJECT_TALK and GenderNamespaces
1760 return [
1761 [
1762 'zh',
1763 [
1764 '文件' => NS_FILE,
1765 '檔案' => NS_FILE,
1766 ],
1767 ],
1768 ];
1769 }
1770
1771 public function testEquals() {
1772 $en1 = new Language();
1773 $en1->setCode( 'en' );
1774
1775 $en2 = Language::factory( 'en' );
1776 $en2->setCode( 'en' );
1777
1778 $this->assertTrue( $en1->equals( $en2 ), 'en equals en' );
1779
1780 $fr = Language::factory( 'fr' );
1781 $this->assertFalse( $en1->equals( $fr ), 'en not equals fr' );
1782 }
1783 }