Merge "Fix bad join on ChangeTag subquery"
[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->hideDeprecated( '$wgFixArabicUnicode = false' );
38 $this->assertSame( $input, $this->getLang()->normalize( $input ), 'regular normalised form' );
39 }
40
41 public static function provideNormalize() {
42 return [
43 [
44 'ﷅ',
45 'صمم',
46 ],
47 ];
48 }
49
50 /**
51 * Mostly to test the raw ascii feature.
52 * @dataProvider provideSprintfDate
53 * @covers Language::sprintfDate
54 */
55 public function testSprintfDate( $format, $date, $expected ) {
56 $this->assertEquals( $expected, $this->getLang()->sprintfDate( $format, $date ) );
57 }
58
59 public static function provideSprintfDate() {
60 return [
61 [
62 'xg "vs" g',
63 '20120102030410',
64 'يناير vs ٣'
65 ],
66 [
67 'xmY',
68 '20120102030410',
69 '١٤٣٣'
70 ],
71 [
72 'xnxmY',
73 '20120102030410',
74 '1433'
75 ],
76 [
77 'xN xmj xmn xN xmY',
78 '20120102030410',
79 ' 7 2 ١٤٣٣'
80 ],
81 ];
82 }
83
84 /**
85 * @dataProvider providePlural
86 * @covers Language::convertPlural
87 */
88 public function testPlural( $result, $value ) {
89 $forms = [ 'zero', 'one', 'two', 'few', 'many', 'other' ];
90 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
91 }
92
93 /**
94 * @dataProvider providePlural
95 * @covers Language::getPluralRuleType
96 */
97 public function testGetPluralRuleType( $result, $value ) {
98 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
99 }
100
101 public static function providePlural() {
102 return [
103 [ 'zero', 0 ],
104 [ 'one', 1 ],
105 [ 'two', 2 ],
106 [ 'few', 3 ],
107 [ 'few', 9 ],
108 [ 'few', 110 ],
109 [ 'many', 11 ],
110 [ 'many', 15 ],
111 [ 'many', 99 ],
112 [ 'many', 9999 ],
113 [ 'other', 100 ],
114 [ 'other', 102 ],
115 [ 'other', 1000 ],
116 [ 'other', 1.7 ],
117 ];
118 }
119 }