3 * PHPUnit tests for the Serbian language.
4 * The language can be represented using two scripts:
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>
15 require_once dirname( __DIR__
) . '/bootstrap.php';
17 /** Tests for MediaWiki languages/LanguageSr.php */
18 class LanguageSrTest
extends LanguageClassesTestCase
{
20 ##### TESTS #######################################################
22 function testEasyConversions( ) {
23 $this->assertCyrillic(
25 'Cyrillic guessing characters'
29 'Latin guessing characters'
33 function testMixedConversions() {
34 $this->assertCyrillic(
36 'Mostly cyrillic characters'
40 'Mostly latin characters'
44 function testSameAmountOfLatinAndCyrillicGetConverted() {
45 $this->assertConverted(
46 '4 latin: šđčć | 4 cyrillic: шђчћ',
49 $this->assertConverted(
50 '4 latin: šđčć | 4 cyrillic: шђчћ',
56 * @author Nikola Smolenski
58 function testConversionToCyrillic() {
59 //A simple convertion of Latin to Cyrillic
60 $this->assertEquals( 'абвг',
61 $this->convertToCyrillic( 'abvg' )
63 //Same as above, but assert that -{}-s must be removed and not converted
64 $this->assertEquals( 'ljабnjвгdž',
65 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
67 //A simple convertion of Cyrillic to Cyrillic
68 $this->assertEquals( 'абвг',
69 $this->convertToCyrillic( 'абвг' )
71 //Same as above, but assert that -{}-s must be removed and not converted
72 $this->assertEquals( 'ljабnjвгdž',
73 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
75 //This text has some Latin, but is recognized as Cyrillic, so it should not be converted
76 $this->assertEquals( 'abvgшђжчћ',
77 $this->convertToCyrillic( 'abvgшђжчћ' )
79 //Same as above, but assert that -{}-s must be removed
80 $this->assertEquals( 'љabvgњшђжчћџ',
81 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
83 //This text has some Cyrillic, but is recognized as Latin, so it should be converted
84 $this->assertEquals( 'абвгшђжчћ',
85 $this->convertToCyrillic( 'абвгšđžčć' )
87 //Same as above, but assert that -{}-s must be removed and not converted
88 $this->assertEquals( 'ljабвгnjшђжчћdž',
89 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
91 // Roman numerals are not converted
92 $this->assertEquals( 'а I б II в III г IV шђжчћ',
93 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
97 function testConversionToLatin() {
98 //A simple convertion of Latin to Latin
99 $this->assertEquals( 'abcd',
100 $this->convertToLatin( 'abcd' )
102 //A simple convertion of Cyrillic to Latin
103 $this->assertEquals( 'abcd',
104 $this->convertToLatin( 'абцд' )
106 //This text has some Latin, but is recognized as Cyrillic, so it should be converted
107 $this->assertEquals( 'abcdšđžčć',
108 $this->convertToLatin( 'abcdшђжчћ' )
110 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted
111 $this->assertEquals( 'абцдšđžčć',
112 $this->convertToLatin( 'абцдšđžčć' )
116 /** @dataProvider providePluralFourForms */
117 function testPluralFourForms( $result, $value ) {
118 $forms = array( 'one', 'few', 'many', 'other' );
119 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
122 function providePluralFourForms() {
134 array( 'many', 120 ),
137 /** @dataProvider providePluralTwoForms */
138 function testPluralTwoForms( $result, $value ) {
139 $forms = array( 'one', 'several' );
140 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
142 function providePluralTwoForms() {
145 array( 'several', 11 ),
146 array( 'several', 91 ),
147 array( 'several', 121 ),
151 ##### HELPERS #####################################################
153 *Wrapper to verify text stay the same after applying conversion
154 * @param $text string Text to convert
155 * @param $variant string Language variant 'sr-ec' or 'sr-el'
156 * @param $msg string Optional message
158 function assertUnConverted( $text, $variant, $msg = '' ) {
161 $this->convertTo( $text, $variant ),
166 * Wrapper to verify a text is different once converted to a variant.
167 * @param $text string Text to convert
168 * @param $variant string Language variant 'sr-ec' or 'sr-el'
169 * @param $msg string Optional message
171 function assertConverted( $text, $variant, $msg = '' ) {
172 $this->assertNotEquals(
174 $this->convertTo( $text, $variant ),
180 * Verifiy the given Cyrillic text is not converted when using
181 * using the cyrillic variant and converted to Latin when using
184 function assertCyrillic( $text, $msg = '' ) {
185 $this->assertUnConverted( $text, 'sr-ec', $msg );
186 $this->assertConverted( $text, 'sr-el', $msg );
189 * Verifiy the given Latin text is not converted when using
190 * using the Latin variant and converted to Cyrillic when using
191 * the Cyrillic variant.
193 function assertLatin( $text, $msg = '' ) {
194 $this->assertUnConverted( $text, 'sr-el', $msg );
195 $this->assertConverted( $text, 'sr-ec', $msg );
199 /** Wrapper for converter::convertTo() method*/
200 function convertTo( $text, $variant ) {
201 return $this->getLang()
207 function convertToCyrillic( $text ) {
208 return $this->convertTo( $text, 'sr-ec' );
210 function convertToLatin( $text ) {
211 return $this->convertTo( $text, 'sr-el' );