Remove $wgDebugFunctionEntry, unused
[mediawiki.git] / tests / phpunit / languages / LanguageSrTest.php
blobbfb199f3799bf3498ec3adf7eb3ee3df6b59d345
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.
10 * @author Antoine Musso <hashar at free dot fr>
11 * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
12 * @file
14 * @todo methods in test class should be tidied:
15 * - Should be split into separate test methods and data providers
16 * - Tests for LanguageConverter and Language should probably be separate..
19 /** Tests for MediaWiki languages/LanguageSr.php */
20 class LanguageSrTest extends LanguageClassesTestCase {
21 /**
22 * @covers LanguageConverter::convertTo
24 public function testEasyConversions() {
25 $this->assertCyrillic(
26 'шђчћжШЂЧЋЖ',
27 'Cyrillic guessing characters'
29 $this->assertLatin(
30 'šđč枊ĐČĆŽ',
31 'Latin guessing characters'
35 /**
36 * @covers LanguageConverter::convertTo
38 public function testMixedConversions() {
39 $this->assertCyrillic(
40 'шђчћжШЂЧЋЖ - šđčćž',
41 'Mostly cyrillic characters'
43 $this->assertLatin(
44 'šđč枊ĐČĆŽ - шђчћж',
45 'Mostly latin characters'
49 /**
50 * @covers LanguageConverter::convertTo
52 public function testSameAmountOfLatinAndCyrillicGetConverted() {
53 $this->assertConverted(
54 '4 latin: šđčć | 4 cyrillic: шђчћ',
55 'sr-ec'
57 $this->assertConverted(
58 '4 latin: šđčć | 4 cyrillic: шђчћ',
59 'sr-el'
63 /**
64 * @author Nikola Smolenski
65 * @covers LanguageConverter::convertTo
67 public function testConversionToCyrillic() {
68 //A simple convertion of Latin to Cyrillic
69 $this->assertEquals( 'абвг',
70 $this->convertToCyrillic( 'abvg' )
72 //Same as above, but assert that -{}-s must be removed and not converted
73 $this->assertEquals( 'ljабnjвгdž',
74 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
76 //A simple convertion of Cyrillic to Cyrillic
77 $this->assertEquals( 'абвг',
78 $this->convertToCyrillic( 'абвг' )
80 //Same as above, but assert that -{}-s must be removed and not converted
81 $this->assertEquals( 'ljабnjвгdž',
82 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
84 //This text has some Latin, but is recognized as Cyrillic, so it should not be converted
85 $this->assertEquals( 'abvgшђжчћ',
86 $this->convertToCyrillic( 'abvgшђжчћ' )
88 //Same as above, but assert that -{}-s must be removed
89 $this->assertEquals( 'љabvgњшђжчћџ',
90 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
92 //This text has some Cyrillic, but is recognized as Latin, so it should be converted
93 $this->assertEquals( 'абвгшђжчћ',
94 $this->convertToCyrillic( 'абвгšđžčć' )
96 //Same as above, but assert that -{}-s must be removed and not converted
97 $this->assertEquals( 'ljабвгnjшђжчћdž',
98 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
100 // Roman numerals are not converted
101 $this->assertEquals( 'а I б II в III г IV шђжчћ',
102 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
107 * @covers LanguageConverter::convertTo
109 public function testConversionToLatin() {
110 //A simple convertion of Latin to Latin
111 $this->assertEquals( 'abcd',
112 $this->convertToLatin( 'abcd' )
114 //A simple convertion of Cyrillic to Latin
115 $this->assertEquals( 'abcd',
116 $this->convertToLatin( 'абцд' )
118 //This text has some Latin, but is recognized as Cyrillic, so it should be converted
119 $this->assertEquals( 'abcdšđžčć',
120 $this->convertToLatin( 'abcdшђжчћ' )
122 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted
123 $this->assertEquals( 'абцдšđžčć',
124 $this->convertToLatin( 'абцдšđžčć' )
129 * @dataProvider providePlural
130 * @covers Language::convertPlural
132 public function testPlural( $result, $value ) {
133 $forms = array( 'one', 'few', 'other' );
134 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
138 * @dataProvider providePlural
139 * @covers Language::getPluralRuleType
141 public function testGetPluralRuleType( $result, $value ) {
142 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
145 public static function providePlural() {
146 return array(
147 array( 'one', 1 ),
148 array( 'other', 11 ),
149 array( 'one', 91 ),
150 array( 'one', 121 ),
151 array( 'few', 2 ),
152 array( 'few', 3 ),
153 array( 'few', 4 ),
154 array( 'few', 334 ),
155 array( 'other', 5 ),
156 array( 'other', 15 ),
157 array( 'other', 120 ),
162 * @dataProvider providePluralTwoForms
163 * @covers Language::convertPlural
165 public function testPluralTwoForms( $result, $value ) {
166 $forms = array( 'one', 'other' );
167 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
170 public static function providePluralTwoForms() {
171 return array(
172 array( 'one', 1 ),
173 array( 'other', 11 ),
174 array( 'other', 4 ),
175 array( 'one', 91 ),
176 array( 'one', 121 ),
180 ##### HELPERS #####################################################
182 *Wrapper to verify text stay the same after applying conversion
183 * @param string $text Text to convert
184 * @param string $variant Language variant 'sr-ec' or 'sr-el'
185 * @param string $msg Optional message
187 protected function assertUnConverted( $text, $variant, $msg = '' ) {
188 $this->assertEquals(
189 $text,
190 $this->convertTo( $text, $variant ),
191 $msg
196 * Wrapper to verify a text is different once converted to a variant.
197 * @param string $text Text to convert
198 * @param string $variant Language variant 'sr-ec' or 'sr-el'
199 * @param string $msg Optional message
201 protected function assertConverted( $text, $variant, $msg = '' ) {
202 $this->assertNotEquals(
203 $text,
204 $this->convertTo( $text, $variant ),
205 $msg
210 * Verifiy the given Cyrillic text is not converted when using
211 * using the cyrillic variant and converted to Latin when using
212 * the Latin variant.
213 * @param string $text Text to convert
214 * @param string $msg Optional message
216 protected function assertCyrillic( $text, $msg = '' ) {
217 $this->assertUnConverted( $text, 'sr-ec', $msg );
218 $this->assertConverted( $text, 'sr-el', $msg );
222 * Verifiy the given Latin text is not converted when using
223 * using the Latin variant and converted to Cyrillic when using
224 * the Cyrillic variant.
225 * @param string $text Text to convert
226 * @param string $msg Optional message
228 protected function assertLatin( $text, $msg = '' ) {
229 $this->assertUnConverted( $text, 'sr-el', $msg );
230 $this->assertConverted( $text, 'sr-ec', $msg );
233 /** Wrapper for converter::convertTo() method*/
234 protected function convertTo( $text, $variant ) {
235 return $this->getLang()
236 ->mConverter
237 ->convertTo(
238 $text, $variant
242 protected function convertToCyrillic( $text ) {
243 return $this->convertTo( $text, 'sr-ec' );
246 protected function convertToLatin( $text ) {
247 return $this->convertTo( $text, 'sr-el' );