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
{
19 function testEasyConversions() {
20 $this->assertCyrillic(
22 'Cyrillic guessing characters'
26 'Latin guessing characters'
30 function testMixedConversions() {
31 $this->assertCyrillic(
33 'Mostly cyrillic characters'
37 'Mostly latin characters'
41 function testSameAmountOfLatinAndCyrillicGetConverted() {
42 $this->assertConverted(
43 '4 latin: šđčć | 4 cyrillic: шђчћ',
46 $this->assertConverted(
47 '4 latin: šđčć | 4 cyrillic: шђчћ',
53 * @author Nikola Smolenski
55 function testConversionToCyrillic() {
56 //A simple convertion of Latin to Cyrillic
57 $this->assertEquals( 'абвг',
58 $this->convertToCyrillic( 'abvg' )
60 //Same as above, but assert that -{}-s must be removed and not converted
61 $this->assertEquals( 'ljабnjвгdž',
62 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
64 //A simple convertion of Cyrillic to Cyrillic
65 $this->assertEquals( 'абвг',
66 $this->convertToCyrillic( 'абвг' )
68 //Same as above, but assert that -{}-s must be removed and not converted
69 $this->assertEquals( 'ljабnjвгdž',
70 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
72 //This text has some Latin, but is recognized as Cyrillic, so it should not be converted
73 $this->assertEquals( 'abvgшђжчћ',
74 $this->convertToCyrillic( 'abvgшђжчћ' )
76 //Same as above, but assert that -{}-s must be removed
77 $this->assertEquals( 'љabvgњшђжчћџ',
78 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
80 //This text has some Cyrillic, but is recognized as Latin, so it should be converted
81 $this->assertEquals( 'абвгшђжчћ',
82 $this->convertToCyrillic( 'абвгšđžčć' )
84 //Same as above, but assert that -{}-s must be removed and not converted
85 $this->assertEquals( 'ljабвгnjшђжчћdž',
86 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
88 // Roman numerals are not converted
89 $this->assertEquals( 'а I б II в III г IV шђжчћ',
90 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
94 function testConversionToLatin() {
95 //A simple convertion of Latin to Latin
96 $this->assertEquals( 'abcd',
97 $this->convertToLatin( 'abcd' )
99 //A simple convertion of Cyrillic to Latin
100 $this->assertEquals( 'abcd',
101 $this->convertToLatin( 'абцд' )
103 //This text has some Latin, but is recognized as Cyrillic, so it should be converted
104 $this->assertEquals( 'abcdšđžčć',
105 $this->convertToLatin( 'abcdшђжчћ' )
107 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted
108 $this->assertEquals( 'абцдšđžčć',
109 $this->convertToLatin( 'абцдšđžčć' )
113 /** @dataProvider providePlural */
114 function testPlural( $result, $value ) {
115 $forms = array( 'one', 'few', 'many', 'other' );
116 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
119 /** @dataProvider providePlural */
120 function testGetPluralRuleType( $result, $value ) {
121 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
124 public static function providePlural() {
136 array( 'many', 120 ),
140 /** @dataProvider providePluralTwoForms */
141 function testPluralTwoForms( $result, $value ) {
142 $forms = array( 'one', 'other' );
143 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
146 public static function providePluralTwoForms() {
149 array( 'other', 11 ),
150 array( 'other', 91 ),
151 array( 'other', 121 ),
155 ##### HELPERS #####################################################
157 *Wrapper to verify text stay the same after applying conversion
158 * @param $text string Text to convert
159 * @param $variant string Language variant 'sr-ec' or 'sr-el'
160 * @param $msg string Optional message
162 function assertUnConverted( $text, $variant, $msg = '' ) {
165 $this->convertTo( $text, $variant ),
171 * Wrapper to verify a text is different once converted to a variant.
172 * @param $text string Text to convert
173 * @param $variant string Language variant 'sr-ec' or 'sr-el'
174 * @param $msg string Optional message
176 function assertConverted( $text, $variant, $msg = '' ) {
177 $this->assertNotEquals(
179 $this->convertTo( $text, $variant ),
185 * Verifiy the given Cyrillic text is not converted when using
186 * using the cyrillic variant and converted to Latin when using
189 function assertCyrillic( $text, $msg = '' ) {
190 $this->assertUnConverted( $text, 'sr-ec', $msg );
191 $this->assertConverted( $text, 'sr-el', $msg );
195 * Verifiy the given Latin text is not converted when using
196 * using the Latin variant and converted to Cyrillic when using
197 * the Cyrillic variant.
199 function assertLatin( $text, $msg = '' ) {
200 $this->assertUnConverted( $text, 'sr-el', $msg );
201 $this->assertConverted( $text, 'sr-ec', $msg );
205 /** Wrapper for converter::convertTo() method*/
206 function convertTo( $text, $variant ) {
207 return $this->getLang()
214 function convertToCyrillic( $text ) {
215 return $this->convertTo( $text, 'sr-ec' );
218 function convertToLatin( $text ) {
219 return $this->convertTo( $text, 'sr-el' );