Merge "add basic print styles to CologneBlue"
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageSrTest.php
1 <?php
2 /**
3 * PHPUnit tests for the Serbian language.
4 * The language can be represented using two scripts:
5 * - Latin (SR_el)
6 * - Cyrillic (SR_ec)
7 * Both representations seems to be bijective, hence MediaWiki can convert
8 * from one script to the other.
9 *
10 * @author Antoine Musso <hashar at free dot fr>
11 * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
12 * @file
13 */
14
15 /** Tests for MediaWiki languages/LanguageSr.php */
16 class LanguageSrTest extends LanguageClassesTestCase {
17 function testEasyConversions() {
18 $this->assertCyrillic(
19 'шђчћжШЂЧЋЖ',
20 'Cyrillic guessing characters'
21 );
22 $this->assertLatin(
23 'šđč枊ĐČĆŽ',
24 'Latin guessing characters'
25 );
26 }
27
28 function testMixedConversions() {
29 $this->assertCyrillic(
30 'шђчћжШЂЧЋЖ - šđčćž',
31 'Mostly cyrillic characters'
32 );
33 $this->assertLatin(
34 'šđč枊ĐČĆŽ - шђчћж',
35 'Mostly latin characters'
36 );
37 }
38
39 function testSameAmountOfLatinAndCyrillicGetConverted() {
40 $this->assertConverted(
41 '4 latin: šđčć | 4 cyrillic: шђчћ',
42 'sr-ec'
43 );
44 $this->assertConverted(
45 '4 latin: šđčć | 4 cyrillic: шђчћ',
46 'sr-el'
47 );
48 }
49
50 /**
51 * @author Nikola Smolenski
52 */
53 function testConversionToCyrillic() {
54 //A simple convertion of Latin to Cyrillic
55 $this->assertEquals( 'абвг',
56 $this->convertToCyrillic( 'abvg' )
57 );
58 //Same as above, but assert that -{}-s must be removed and not converted
59 $this->assertEquals( 'ljабnjвгdž',
60 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
61 );
62 //A simple convertion of Cyrillic to Cyrillic
63 $this->assertEquals( 'абвг',
64 $this->convertToCyrillic( 'абвг' )
65 );
66 //Same as above, but assert that -{}-s must be removed and not converted
67 $this->assertEquals( 'ljабnjвгdž',
68 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
69 );
70 //This text has some Latin, but is recognized as Cyrillic, so it should not be converted
71 $this->assertEquals( 'abvgшђжчћ',
72 $this->convertToCyrillic( 'abvgшђжчћ' )
73 );
74 //Same as above, but assert that -{}-s must be removed
75 $this->assertEquals( 'љabvgњшђжчћџ',
76 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
77 );
78 //This text has some Cyrillic, but is recognized as Latin, so it should be converted
79 $this->assertEquals( 'абвгшђжчћ',
80 $this->convertToCyrillic( 'абвгšđžčć' )
81 );
82 //Same as above, but assert that -{}-s must be removed and not converted
83 $this->assertEquals( 'ljабвгnjшђжчћdž',
84 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
85 );
86 // Roman numerals are not converted
87 $this->assertEquals( 'а I б II в III г IV шђжчћ',
88 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
89 );
90 }
91
92 function testConversionToLatin() {
93 //A simple convertion of Latin to Latin
94 $this->assertEquals( 'abcd',
95 $this->convertToLatin( 'abcd' )
96 );
97 //A simple convertion of Cyrillic to Latin
98 $this->assertEquals( 'abcd',
99 $this->convertToLatin( 'абцд' )
100 );
101 //This text has some Latin, but is recognized as Cyrillic, so it should be converted
102 $this->assertEquals( 'abcdšđžčć',
103 $this->convertToLatin( 'abcdшђжчћ' )
104 );
105 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted
106 $this->assertEquals( 'абцдšđžčć',
107 $this->convertToLatin( 'абцдšđžčć' )
108 );
109 }
110
111 /** @dataProvider providePlural */
112 function testPlural( $result, $value ) {
113 $forms = array( 'one', 'few', 'many', 'other' );
114 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
115 }
116
117 /** @dataProvider providePlural */
118 function testGetPluralRuleType( $result, $value ) {
119 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
120 }
121
122 public static function providePlural() {
123 return array(
124 array( 'one', 1 ),
125 array( 'many', 11 ),
126 array( 'one', 91 ),
127 array( 'one', 121 ),
128 array( 'few', 2 ),
129 array( 'few', 3 ),
130 array( 'few', 4 ),
131 array( 'few', 334 ),
132 array( 'many', 5 ),
133 array( 'many', 15 ),
134 array( 'many', 120 ),
135 );
136 }
137
138 /** @dataProvider providePluralTwoForms */
139 function testPluralTwoForms( $result, $value ) {
140 $forms = array( 'one', 'other' );
141 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
142 }
143
144 public static function providePluralTwoForms() {
145 return array(
146 array( 'one', 1 ),
147 array( 'other', 11 ),
148 array( 'other', 91 ),
149 array( 'other', 121 ),
150 );
151 }
152
153 ##### HELPERS #####################################################
154 /**
155 *Wrapper to verify text stay the same after applying conversion
156 * @param $text string Text to convert
157 * @param $variant string Language variant 'sr-ec' or 'sr-el'
158 * @param $msg string Optional message
159 */
160 function assertUnConverted( $text, $variant, $msg = '' ) {
161 $this->assertEquals(
162 $text,
163 $this->convertTo( $text, $variant ),
164 $msg
165 );
166 }
167
168 /**
169 * Wrapper to verify a text is different once converted to a variant.
170 * @param $text string Text to convert
171 * @param $variant string Language variant 'sr-ec' or 'sr-el'
172 * @param $msg string Optional message
173 */
174 function assertConverted( $text, $variant, $msg = '' ) {
175 $this->assertNotEquals(
176 $text,
177 $this->convertTo( $text, $variant ),
178 $msg
179 );
180 }
181
182 /**
183 * Verifiy the given Cyrillic text is not converted when using
184 * using the cyrillic variant and converted to Latin when using
185 * the Latin variant.
186 */
187 function assertCyrillic( $text, $msg = '' ) {
188 $this->assertUnConverted( $text, 'sr-ec', $msg );
189 $this->assertConverted( $text, 'sr-el', $msg );
190 }
191
192 /**
193 * Verifiy the given Latin text is not converted when using
194 * using the Latin variant and converted to Cyrillic when using
195 * the Cyrillic variant.
196 */
197 function assertLatin( $text, $msg = '' ) {
198 $this->assertUnConverted( $text, 'sr-el', $msg );
199 $this->assertConverted( $text, 'sr-ec', $msg );
200 }
201
202
203 /** Wrapper for converter::convertTo() method*/
204 function convertTo( $text, $variant ) {
205 return $this->getLang()
206 ->mConverter
207 ->convertTo(
208 $text, $variant
209 );
210 }
211
212 function convertToCyrillic( $text ) {
213 return $this->convertTo( $text, 'sr-ec' );
214 }
215
216 function convertToLatin( $text ) {
217 return $this->convertTo( $text, 'sr-el' );
218 }
219 }