MediaWiki
REL1_21
|
00001 <?php 00015 require_once dirname( __DIR__ ) . '/bootstrap.php'; 00016 00018 class LanguageSrTest extends LanguageClassesTestCase { 00019 00020 ##### TESTS ####################################################### 00021 00022 function testEasyConversions() { 00023 $this->assertCyrillic( 00024 'шђчћжШЂЧЋЖ', 00025 'Cyrillic guessing characters' 00026 ); 00027 $this->assertLatin( 00028 'šđč枊ĐČĆŽ', 00029 'Latin guessing characters' 00030 ); 00031 } 00032 00033 function testMixedConversions() { 00034 $this->assertCyrillic( 00035 'шђчћжШЂЧЋЖ - šđčćž', 00036 'Mostly cyrillic characters' 00037 ); 00038 $this->assertLatin( 00039 'šđč枊ĐČĆŽ - шђчћж', 00040 'Mostly latin characters' 00041 ); 00042 } 00043 00044 function testSameAmountOfLatinAndCyrillicGetConverted() { 00045 $this->assertConverted( 00046 '4 latin: šđčć | 4 cyrillic: шђчћ', 00047 'sr-ec' 00048 ); 00049 $this->assertConverted( 00050 '4 latin: šđčć | 4 cyrillic: шђчћ', 00051 'sr-el' 00052 ); 00053 } 00054 00058 function testConversionToCyrillic() { 00059 //A simple convertion of Latin to Cyrillic 00060 $this->assertEquals( 'абвг', 00061 $this->convertToCyrillic( 'abvg' ) 00062 ); 00063 //Same as above, but assert that -{}-s must be removed and not converted 00064 $this->assertEquals( 'ljабnjвгdž', 00065 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' ) 00066 ); 00067 //A simple convertion of Cyrillic to Cyrillic 00068 $this->assertEquals( 'абвг', 00069 $this->convertToCyrillic( 'абвг' ) 00070 ); 00071 //Same as above, but assert that -{}-s must be removed and not converted 00072 $this->assertEquals( 'ljабnjвгdž', 00073 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' ) 00074 ); 00075 //This text has some Latin, but is recognized as Cyrillic, so it should not be converted 00076 $this->assertEquals( 'abvgшђжчћ', 00077 $this->convertToCyrillic( 'abvgшђжчћ' ) 00078 ); 00079 //Same as above, but assert that -{}-s must be removed 00080 $this->assertEquals( 'љabvgњшђжчћџ', 00081 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' ) 00082 ); 00083 //This text has some Cyrillic, but is recognized as Latin, so it should be converted 00084 $this->assertEquals( 'абвгшђжчћ', 00085 $this->convertToCyrillic( 'абвгšđžčć' ) 00086 ); 00087 //Same as above, but assert that -{}-s must be removed and not converted 00088 $this->assertEquals( 'ljабвгnjшђжчћdž', 00089 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' ) 00090 ); 00091 // Roman numerals are not converted 00092 $this->assertEquals( 'а I б II в III г IV шђжчћ', 00093 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' ) 00094 ); 00095 } 00096 00097 function testConversionToLatin() { 00098 //A simple convertion of Latin to Latin 00099 $this->assertEquals( 'abcd', 00100 $this->convertToLatin( 'abcd' ) 00101 ); 00102 //A simple convertion of Cyrillic to Latin 00103 $this->assertEquals( 'abcd', 00104 $this->convertToLatin( 'абцд' ) 00105 ); 00106 //This text has some Latin, but is recognized as Cyrillic, so it should be converted 00107 $this->assertEquals( 'abcdšđžčć', 00108 $this->convertToLatin( 'abcdшђжчћ' ) 00109 ); 00110 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted 00111 $this->assertEquals( 'абцдšđžčć', 00112 $this->convertToLatin( 'абцдšđžčć' ) 00113 ); 00114 } 00115 00117 function testPluralFourForms( $result, $value ) { 00118 $forms = array( 'one', 'few', 'many', 'other' ); 00119 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); 00120 } 00121 00122 function providePluralFourForms() { 00123 return array( 00124 array( 'one', 1 ), 00125 array( 'many', 11 ), 00126 array( 'one', 91 ), 00127 array( 'one', 121 ), 00128 array( 'few', 2 ), 00129 array( 'few', 3 ), 00130 array( 'few', 4 ), 00131 array( 'few', 334 ), 00132 array( 'many', 5 ), 00133 array( 'many', 15 ), 00134 array( 'many', 120 ), 00135 ); 00136 } 00137 00139 function testPluralTwoForms( $result, $value ) { 00140 $forms = array( 'one', 'several' ); 00141 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); 00142 } 00143 00144 function providePluralTwoForms() { 00145 return array( 00146 array( 'one', 1 ), 00147 array( 'several', 11 ), 00148 array( 'several', 91 ), 00149 array( 'several', 121 ), 00150 ); 00151 } 00152 00153 ##### HELPERS ##################################################### 00154 00160 function assertUnConverted( $text, $variant, $msg = '' ) { 00161 $this->assertEquals( 00162 $text, 00163 $this->convertTo( $text, $variant ), 00164 $msg 00165 ); 00166 } 00167 00174 function assertConverted( $text, $variant, $msg = '' ) { 00175 $this->assertNotEquals( 00176 $text, 00177 $this->convertTo( $text, $variant ), 00178 $msg 00179 ); 00180 } 00181 00187 function assertCyrillic( $text, $msg = '' ) { 00188 $this->assertUnConverted( $text, 'sr-ec', $msg ); 00189 $this->assertConverted( $text, 'sr-el', $msg ); 00190 } 00191 00197 function assertLatin( $text, $msg = '' ) { 00198 $this->assertUnConverted( $text, 'sr-el', $msg ); 00199 $this->assertConverted( $text, 'sr-ec', $msg ); 00200 } 00201 00202 00204 function convertTo( $text, $variant ) { 00205 return $this->getLang() 00206 ->mConverter 00207 ->convertTo( 00208 $text, $variant 00209 ); 00210 } 00211 00212 function convertToCyrillic( $text ) { 00213 return $this->convertTo( $text, 'sr-ec' ); 00214 } 00215 00216 function convertToLatin( $text ) { 00217 return $this->convertTo( $text, 'sr-el' ); 00218 } 00219 }