Non-word characters don't terminate tag names.
[mediawiki.git] / tests / phpunit / languages / LanguageSrTest.php
blob40d14e34d4894cbd82c01c57e8dedcb8d4a763be
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
15 /** Tests for MediaWiki languages/LanguageSr.php */
16 class LanguageSrTest extends LanguageClassesTestCase {
17 function testEasyConversions() {
18 $this->assertCyrillic(
19 'шђчћжШЂЧЋЖ',
20 'Cyrillic guessing characters'
22 $this->assertLatin(
23 'šđč枊ĐČĆŽ',
24 'Latin guessing characters'
28 function testMixedConversions() {
29 $this->assertCyrillic(
30 'шђчћжШЂЧЋЖ - šđčćž',
31 'Mostly cyrillic characters'
33 $this->assertLatin(
34 'šđč枊ĐČĆŽ - шђчћж',
35 'Mostly latin characters'
39 function testSameAmountOfLatinAndCyrillicGetConverted() {
40 $this->assertConverted(
41 '4 latin: šđčć | 4 cyrillic: шђчћ',
42 'sr-ec'
44 $this->assertConverted(
45 '4 latin: šđčć | 4 cyrillic: шђчћ',
46 'sr-el'
50 /**
51 * @author Nikola Smolenski
53 function testConversionToCyrillic() {
54 //A simple convertion of Latin to Cyrillic
55 $this->assertEquals( 'абвг',
56 $this->convertToCyrillic( 'abvg' )
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ž}-' )
62 //A simple convertion of Cyrillic to Cyrillic
63 $this->assertEquals( 'абвг',
64 $this->convertToCyrillic( 'абвг' )
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ž}-' )
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шђжчћ' )
74 //Same as above, but assert that -{}-s must be removed
75 $this->assertEquals( 'љabvgњшђжчћџ',
76 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
78 //This text has some Cyrillic, but is recognized as Latin, so it should be converted
79 $this->assertEquals( 'абвгшђжчћ',
80 $this->convertToCyrillic( 'абвгšđžčć' )
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ž}-' )
86 // Roman numerals are not converted
87 $this->assertEquals( 'а I б II в III г IV шђжчћ',
88 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
92 function testConversionToLatin() {
93 //A simple convertion of Latin to Latin
94 $this->assertEquals( 'abcd',
95 $this->convertToLatin( 'abcd' )
97 //A simple convertion of Cyrillic to Latin
98 $this->assertEquals( 'abcd',
99 $this->convertToLatin( 'абцд' )
101 //This text has some Latin, but is recognized as Cyrillic, so it should be converted
102 $this->assertEquals( 'abcdšđžčć',
103 $this->convertToLatin( 'abcdшђжчћ' )
105 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted
106 $this->assertEquals( 'абцдšđžčć',
107 $this->convertToLatin( 'абцдšđžčć' )
111 /** @dataProvider providePlural */
112 function testPlural( $result, $value ) {
113 $forms = array( 'one', 'few', 'many', 'other' );
114 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
117 /** @dataProvider providePlural */
118 function testGetPluralRuleType( $result, $value ) {
119 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
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 ),
138 /** @dataProvider providePluralTwoForms */
139 function testPluralTwoForms( $result, $value ) {
140 $forms = array( 'one', 'other' );
141 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
144 public static function providePluralTwoForms() {
145 return array(
146 array( 'one', 1 ),
147 array( 'other', 11 ),
148 array( 'other', 91 ),
149 array( 'other', 121 ),
153 ##### HELPERS #####################################################
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
160 function assertUnConverted( $text, $variant, $msg = '' ) {
161 $this->assertEquals(
162 $text,
163 $this->convertTo( $text, $variant ),
164 $msg
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
174 function assertConverted( $text, $variant, $msg = '' ) {
175 $this->assertNotEquals(
176 $text,
177 $this->convertTo( $text, $variant ),
178 $msg
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.
187 function assertCyrillic( $text, $msg = '' ) {
188 $this->assertUnConverted( $text, 'sr-ec', $msg );
189 $this->assertConverted( $text, 'sr-el', $msg );
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.
197 function assertLatin( $text, $msg = '' ) {
198 $this->assertUnConverted( $text, 'sr-el', $msg );
199 $this->assertConverted( $text, 'sr-ec', $msg );
203 /** Wrapper for converter::convertTo() method*/
204 function convertTo( $text, $variant ) {
205 return $this->getLang()
206 ->mConverter
207 ->convertTo(
208 $text, $variant
212 function convertToCyrillic( $text ) {
213 return $this->convertTo( $text, 'sr-ec' );
216 function convertToLatin( $text ) {
217 return $this->convertTo( $text, 'sr-el' );