MediaWiki REL1_31
LanguageSrTest.php
Go to the documentation of this file.
1<?php
27 public function testEasyConversions() {
28 $this->assertCyrillic(
29 'шђчћжШЂЧЋЖ',
30 'Cyrillic guessing characters'
31 );
32 $this->assertLatin(
33 'šđč枊ĐČĆŽ',
34 'Latin guessing characters'
35 );
36 }
37
41 public function testMixedConversions() {
42 $this->assertCyrillic(
43 'шђчћжШЂЧЋЖ - šđčćž',
44 'Mostly cyrillic characters'
45 );
46 $this->assertLatin(
47 'šđč枊ĐČĆŽ - шђчћж',
48 'Mostly latin characters'
49 );
50 }
51
56 $this->assertConverted(
57 '4 latin: šđčć | 4 cyrillic: шђчћ',
58 'sr-ec'
59 );
60 $this->assertConverted(
61 '4 latin: šđčć | 4 cyrillic: шђчћ',
62 'sr-el'
63 );
64 }
65
70 public function testConversionToCyrillic() {
71 // A simple convertion of Latin to Cyrillic
72 $this->assertEquals( 'абвг',
73 $this->convertToCyrillic( 'abvg' )
74 );
75 // Same as above, but assert that -{}-s must be removed and not converted
76 $this->assertEquals( 'ljабnjвгdž',
77 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
78 );
79 // A simple convertion of Cyrillic to Cyrillic
80 $this->assertEquals( 'абвг',
81 $this->convertToCyrillic( 'абвг' )
82 );
83 // Same as above, but assert that -{}-s must be removed and not converted
84 $this->assertEquals( 'ljабnjвгdž',
85 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
86 );
87 // This text has some Latin, but is recognized as Cyrillic, so it should not be converted
88 $this->assertEquals( 'abvgшђжчћ',
89 $this->convertToCyrillic( 'abvgшђжчћ' )
90 );
91 // Same as above, but assert that -{}-s must be removed
92 $this->assertEquals( 'љabvgњшђжчћџ',
93 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
94 );
95 // This text has some Cyrillic, but is recognized as Latin, so it should be converted
96 $this->assertEquals( 'абвгшђжчћ',
97 $this->convertToCyrillic( 'абвгšđžčć' )
98 );
99 // Same as above, but assert that -{}-s must be removed and not converted
100 $this->assertEquals( 'ljабвгnjшђжчћdž',
101 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
102 );
103 // Roman numerals are not converted
104 $this->assertEquals( 'а I б II в III г IV шђжчћ',
105 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
106 );
107 }
108
112 public function testConversionToLatin() {
113 // A simple convertion of Latin to Latin
114 $this->assertEquals( 'abcd',
115 $this->convertToLatin( 'abcd' )
116 );
117 // A simple convertion of Cyrillic to Latin
118 $this->assertEquals( 'abcd',
119 $this->convertToLatin( 'абцд' )
120 );
121 // This text has some Latin, but is recognized as Cyrillic, so it should be converted
122 $this->assertEquals( 'abcdšđžčć',
123 $this->convertToLatin( 'abcdшђжчћ' )
124 );
125 // This text has some Cyrillic, but is recognized as Latin, so it should not be converted
126 $this->assertEquals( 'абцдšđžčć',
127 $this->convertToLatin( 'абцдšđžčć' )
128 );
129 }
130
135 public function testPlural( $result, $value ) {
136 $forms = [ 'one', 'few', 'other' ];
137 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
138 }
139
144 public function testGetPluralRuleType( $result, $value ) {
145 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
146 }
147
148 public static function providePlural() {
149 return [
150 [ 'one', 1 ],
151 [ 'other', 11 ],
152 [ 'one', 91 ],
153 [ 'one', 121 ],
154 [ 'few', 2 ],
155 [ 'few', 3 ],
156 [ 'few', 4 ],
157 [ 'few', 334 ],
158 [ 'other', 5 ],
159 [ 'other', 15 ],
160 [ 'other', 120 ],
161 ];
162 }
163
168 public function testPluralTwoForms( $result, $value ) {
169 $forms = [ 'one', 'other' ];
170 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
171 }
172
173 public static function providePluralTwoForms() {
174 return [
175 [ 'one', 1 ],
176 [ 'other', 11 ],
177 [ 'other', 4 ],
178 [ 'one', 91 ],
179 [ 'one', 121 ],
180 ];
181 }
182
183 # #### HELPERS #####################################################
190 protected function assertUnConverted( $text, $variant, $msg = '' ) {
191 $this->assertEquals(
192 $text,
193 $this->convertTo( $text, $variant ),
194 $msg
195 );
196 }
197
204 protected function assertConverted( $text, $variant, $msg = '' ) {
205 $this->assertNotEquals(
206 $text,
207 $this->convertTo( $text, $variant ),
208 $msg
209 );
210 }
211
219 protected function assertCyrillic( $text, $msg = '' ) {
220 $this->assertUnConverted( $text, 'sr-ec', $msg );
221 $this->assertConverted( $text, 'sr-el', $msg );
222 }
223
231 protected function assertLatin( $text, $msg = '' ) {
232 $this->assertUnConverted( $text, 'sr-el', $msg );
233 $this->assertConverted( $text, 'sr-ec', $msg );
234 }
235
237 protected function convertTo( $text, $variant ) {
238 return $this->getLang()
239 ->mConverter
240 ->convertTo(
241 $text, $variant
242 );
243 }
244
245 protected function convertToCyrillic( $text ) {
246 return $this->convertTo( $text, 'sr-ec' );
247 }
248
249 protected function convertToLatin( $text ) {
250 return $this->convertTo( $text, 'sr-el' );
251 }
252}
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()
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.
testPluralTwoForms( $result, $value)
providePluralTwoForms Language::convertPlural
testSameAmountOfLatinAndCyrillicGetConverted()
LanguageConverter::convertTo.