MediaWiki REL1_32
LanguageSrTest.php
Go to the documentation of this file.
1<?php
27 public function testHasVariants() {
28 $this->assertTrue( $this->getLang()->hasVariants(), 'sr has variants' );
29 }
30
34 public function testHasVariant() {
35 $langs = [
36 'sr' => $this->getLang(),
37 'sr-ec' => Language::factory( 'sr-ec' ),
38 'sr-cyrl' => Language::factory( 'sr-cyrl' ),
39 ];
40 foreach ( $langs as $code => $l ) {
41 $p = $l->getParentLanguage();
42 $this->assertTrue( $p !== null, 'parent language exists' );
43 $this->assertEquals( 'sr', $p->getCode(), 'sr is parent language' );
44 $this->assertTrue( $p instanceof LanguageSr, 'parent is LanguageSr' );
45 // This is a valid variant of the base
46 $this->assertTrue( $p->hasVariant( $l->getCode() ) );
47 // This test should be tweaked if/when sr-ec is renamed (T117845)
48 // to swap the roles of sr-ec and sr-Cyrl
49 $this->assertTrue( $l->hasVariant( 'sr-ec' ), 'sr-ec exists' );
50 // note that sr-cyrl is an alias, not a (strict) variant name
51 foreach ( [ 'sr-EC', 'sr-Cyrl', 'sr-cyrl', 'sr-bogus' ] as $v ) {
52 $this->assertFalse( $l->hasVariant( $v ), "$v is not a variant of $code" );
53 }
54 }
55 }
56
60 public function testHasVariantBogus() {
61 $langs = [
62 // Note that case matters when calling Language::factory();
63 // these are all bogus language codes
64 'sr-EC' => Language::factory( 'sr-EC' ),
65 'sr-Cyrl' => Language::factory( 'sr-Cyrl' ),
66 'sr-bogus' => Language::factory( 'sr-bogus' ),
67 ];
68 foreach ( $langs as $code => $l ) {
69 $p = $l->getParentLanguage();
70 $this->assertTrue( $p === null, 'no parent for bogus language' );
71 $this->assertFalse( $l instanceof LanguageSr, "$code is not sr" );
72 $this->assertFalse( $this->getLang()->hasVariant( $code ), "$code is not a sr variant" );
73 foreach ( [ 'sr', 'sr-ec', 'sr-EC', 'sr-Cyrl', 'sr-cyrl', 'sr-bogus' ] as $v ) {
74 if ( $v !== $code ) {
75 $this->assertFalse( $l->hasVariant( $v ), "no variant $v" );
76 }
77 }
78 }
79 }
80
84 public function testEasyConversions() {
85 $this->assertCyrillic(
86 'шђчћжШЂЧЋЖ',
87 'Cyrillic guessing characters'
88 );
89 $this->assertLatin(
90 'šđč枊ĐČĆŽ',
91 'Latin guessing characters'
92 );
93 }
94
98 public function testMixedConversions() {
99 $this->assertCyrillic(
100 'шђчћжШЂЧЋЖ - šđčćž',
101 'Mostly Cyrillic characters'
102 );
103 $this->assertLatin(
104 'šđč枊ĐČĆŽ - шђчћж',
105 'Mostly Latin characters'
106 );
107 }
108
113 $this->assertConverted(
114 '4 Latin: šđčć | 4 Cyrillic: шђчћ',
115 'sr-ec'
116 );
117 $this->assertConverted(
118 '4 Latin: šđčć | 4 Cyrillic: шђчћ',
119 'sr-el'
120 );
121 }
122
127 public function testConversionToCyrillic() {
128 // A simple conversion of Latin to Cyrillic
129 $this->assertEquals( 'абвг',
130 $this->convertToCyrillic( 'abvg' )
131 );
132 // Same as above, but assert that -{}-s must be removed and not converted
133 $this->assertEquals( 'ljабnjвгdž',
134 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
135 );
136 // A simple conversion of Cyrillic to Cyrillic
137 $this->assertEquals( 'абвг',
138 $this->convertToCyrillic( 'абвг' )
139 );
140 // Same as above, but assert that -{}-s must be removed and not converted
141 $this->assertEquals( 'ljабnjвгdž',
142 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
143 );
144 // This text has some Latin, but is recognized as Cyrillic, so it should not be converted
145 $this->assertEquals( 'abvgшђжчћ',
146 $this->convertToCyrillic( 'abvgшђжчћ' )
147 );
148 // Same as above, but assert that -{}-s must be removed
149 $this->assertEquals( 'љabvgњшђжчћџ',
150 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
151 );
152 // This text has some Cyrillic, but is recognized as Latin, so it should be converted
153 $this->assertEquals( 'абвгшђжчћ',
154 $this->convertToCyrillic( 'абвгšđžčć' )
155 );
156 // Same as above, but assert that -{}-s must be removed and not converted
157 $this->assertEquals( 'ljабвгnjшђжчћdž',
158 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
159 );
160 // Roman numerals are not converted
161 $this->assertEquals( 'а I б II в III г IV шђжчћ',
162 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
163 );
164 }
165
169 public function testConversionToLatin() {
170 // A simple conversion of Latin to Latin
171 $this->assertEquals( 'abcd',
172 $this->convertToLatin( 'abcd' )
173 );
174 // A simple conversion of Cyrillic to Latin
175 $this->assertEquals( 'abcd',
176 $this->convertToLatin( 'абцд' )
177 );
178 // This text has some Latin, but is recognized as Cyrillic, so it should be converted
179 $this->assertEquals( 'abcdšđžčć',
180 $this->convertToLatin( 'abcdшђжчћ' )
181 );
182 // This text has some Cyrillic, but is recognized as Latin, so it should not be converted
183 $this->assertEquals( 'абцдšđžčć',
184 $this->convertToLatin( 'абцдšđžčć' )
185 );
186 }
187
192 public function testPlural( $result, $value ) {
193 $forms = [ 'one', 'few', 'other' ];
194 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
195 }
196
201 public function testGetPluralRuleType( $result, $value ) {
202 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
203 }
204
205 public static function providePlural() {
206 return [
207 [ 'one', 1 ],
208 [ 'other', 11 ],
209 [ 'one', 91 ],
210 [ 'one', 121 ],
211 [ 'few', 2 ],
212 [ 'few', 3 ],
213 [ 'few', 4 ],
214 [ 'few', 334 ],
215 [ 'other', 5 ],
216 [ 'other', 15 ],
217 [ 'other', 120 ],
218 ];
219 }
220
225 public function testPluralTwoForms( $result, $value ) {
226 $forms = [ 'one', 'other' ];
227 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
228 }
229
230 public static function providePluralTwoForms() {
231 return [
232 [ 'one', 1 ],
233 [ 'other', 11 ],
234 [ 'other', 4 ],
235 [ 'one', 91 ],
236 [ 'one', 121 ],
237 ];
238 }
239
240 # #### HELPERS #####################################################
247 protected function assertUnConverted( $text, $variant, $msg = '' ) {
248 $this->assertEquals(
249 $text,
250 $this->convertTo( $text, $variant ),
251 $msg
252 );
253 }
254
261 protected function assertConverted( $text, $variant, $msg = '' ) {
262 $this->assertNotEquals(
263 $text,
264 $this->convertTo( $text, $variant ),
265 $msg
266 );
267 }
268
276 protected function assertCyrillic( $text, $msg = '' ) {
277 $this->assertUnConverted( $text, 'sr-ec', $msg );
278 $this->assertConverted( $text, 'sr-el', $msg );
279 }
280
288 protected function assertLatin( $text, $msg = '' ) {
289 $this->assertUnConverted( $text, 'sr-el', $msg );
290 $this->assertConverted( $text, 'sr-ec', $msg );
291 }
292
294 protected function convertTo( $text, $variant ) {
295 return $this->getLang()
296 ->mConverter
297 ->convertTo(
298 $text, $variant
299 );
300 }
301
302 protected function convertToCyrillic( $text ) {
303 return $this->convertTo( $text, 'sr-ec' );
304 }
305
306 protected function convertToLatin( $text ) {
307 return $this->convertTo( $text, 'sr-el' );
308 }
309}
Helping class to run tests using a clean language instance.
LanguageSr SrConverter.
testPlural( $result, $value)
providePlural Language::convertPlural
testGetPluralRuleType( $result, $value)
providePlural Language::getPluralRuleType
assertConverted( $text, $variant, $msg='')
Wrapper to verify a text is different once converted to a variant.
static providePluralTwoForms()
testHasVariantBogus()
Language::hasVariant.
testEasyConversions()
LanguageConverter::convertTo.
assertCyrillic( $text, $msg='')
Verifiy the given Cyrillic text is not converted when using using the Cyrillic variant and converted ...
convertToCyrillic( $text)
assertUnConverted( $text, $variant, $msg='')
Wrapper to verify text stay the same after applying conversion.
testMixedConversions()
LanguageConverter::convertTo.
convertTo( $text, $variant)
Wrapper for converter::convertTo() method.
assertLatin( $text, $msg='')
Verifiy the given Latin text is not converted when using using the Latin variant and converted to Cyr...
testConversionToLatin()
LanguageConverter::convertTo.
testHasVariants()
Language::hasVariants.
testHasVariant()
Language::hasVariant.
testPluralTwoForms( $result, $value)
providePluralTwoForms Language::convertPlural
testSameAmountOfLatinAndCyrillicGetConverted()
LanguageConverter::convertTo.
Serbian (Српски / Srpski)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:895