languages: Add coverage for 'ar' and 'ml' normalize()
[lhc/web/wiklou.git] / tests / phpunit / languages / classes / LanguageArTest.php
1 <?php
2
3 /**
4 * @covers LanguageAr
5 */
6 class LanguageArTest extends LanguageClassesTestCase {
7
8 /**
9 * @covers Language::formatNum
10 * @dataProvider provideFormatNum
11 */
12 public function testFormatNum( $num, $formatted ) {
13 $this->assertEquals( $formatted, $this->getLang()->formatNum( $num ) );
14 }
15
16 public static function provideFormatNum() {
17 return [
18 [ '1234567', '١٬٢٣٤٬٥٦٧' ],
19 [ -12.89, '-١٢٫٨٩' ],
20 ];
21 }
22
23 /**
24 * @covers LanguageAr::normalize
25 * @covers Language::normalize
26 * @dataProvider provideNormalize
27 */
28 public function testNormalize( $input, $expected ) {
29 if ( $input === $expected ) {
30 throw new Exception( 'Expected output must differ.' );
31 }
32
33 $this->setMwGlobals( 'wgFixArabicUnicode', true );
34 $this->assertSame( $expected, $this->getLang()->normalize( $input ), 'ar-normalised form' );
35
36 $this->setMwGlobals( 'wgFixArabicUnicode', false );
37 $this->assertSame( $input, $this->getLang()->normalize( $input ), 'regular normalised form' );
38 }
39
40 public static function provideNormalize() {
41 return [
42 [
43 'ﷅ',
44 'صمم',
45 ],
46 ];
47 }
48
49 /**
50 * Mostly to test the raw ascii feature.
51 * @dataProvider provideSprintfDate
52 * @covers Language::sprintfDate
53 */
54 public function testSprintfDate( $format, $date, $expected ) {
55 $this->assertEquals( $expected, $this->getLang()->sprintfDate( $format, $date ) );
56 }
57
58 public static function provideSprintfDate() {
59 return [
60 [
61 'xg "vs" g',
62 '20120102030410',
63 'يناير vs ٣'
64 ],
65 [
66 'xmY',
67 '20120102030410',
68 '١٤٣٣'
69 ],
70 [
71 'xnxmY',
72 '20120102030410',
73 '1433'
74 ],
75 [
76 'xN xmj xmn xN xmY',
77 '20120102030410',
78 ' 7 2 ١٤٣٣'
79 ],
80 ];
81 }
82
83 /**
84 * @dataProvider providePlural
85 * @covers Language::convertPlural
86 */
87 public function testPlural( $result, $value ) {
88 $forms = [ 'zero', 'one', 'two', 'few', 'many', 'other' ];
89 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
90 }
91
92 /**
93 * @dataProvider providePlural
94 * @covers Language::getPluralRuleType
95 */
96 public function testGetPluralRuleType( $result, $value ) {
97 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
98 }
99
100 public static function providePlural() {
101 return [
102 [ 'zero', 0 ],
103 [ 'one', 1 ],
104 [ 'two', 2 ],
105 [ 'few', 3 ],
106 [ 'few', 9 ],
107 [ 'few', 110 ],
108 [ 'many', 11 ],
109 [ 'many', 15 ],
110 [ 'many', 99 ],
111 [ 'many', 9999 ],
112 [ 'other', 100 ],
113 [ 'other', 102 ],
114 [ 'other', 1000 ],
115 [ 'other', 1.7 ],
116 ];
117 }
118 }