MediaWiki
REL1_22
|
00001 <?php 00020 class LanguageSrTest extends LanguageClassesTestCase { 00024 public function testEasyConversions() { 00025 $this->assertCyrillic( 00026 'шђчћжШЂЧЋЖ', 00027 'Cyrillic guessing characters' 00028 ); 00029 $this->assertLatin( 00030 'šđč枊ĐČĆŽ', 00031 'Latin guessing characters' 00032 ); 00033 } 00034 00038 public function testMixedConversions() { 00039 $this->assertCyrillic( 00040 'шђчћжШЂЧЋЖ - šđčćž', 00041 'Mostly cyrillic characters' 00042 ); 00043 $this->assertLatin( 00044 'šđč枊ĐČĆŽ - шђчћж', 00045 'Mostly latin characters' 00046 ); 00047 } 00048 00052 public function testSameAmountOfLatinAndCyrillicGetConverted() { 00053 $this->assertConverted( 00054 '4 latin: šđčć | 4 cyrillic: шђчћ', 00055 'sr-ec' 00056 ); 00057 $this->assertConverted( 00058 '4 latin: šđčć | 4 cyrillic: шђчћ', 00059 'sr-el' 00060 ); 00061 } 00062 00067 public function testConversionToCyrillic() { 00068 //A simple convertion of Latin to Cyrillic 00069 $this->assertEquals( 'абвг', 00070 $this->convertToCyrillic( 'abvg' ) 00071 ); 00072 //Same as above, but assert that -{}-s must be removed and not converted 00073 $this->assertEquals( 'ljабnjвгdž', 00074 $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' ) 00075 ); 00076 //A simple convertion of Cyrillic to Cyrillic 00077 $this->assertEquals( 'абвг', 00078 $this->convertToCyrillic( 'абвг' ) 00079 ); 00080 //Same as above, but assert that -{}-s must be removed and not converted 00081 $this->assertEquals( 'ljабnjвгdž', 00082 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' ) 00083 ); 00084 //This text has some Latin, but is recognized as Cyrillic, so it should not be converted 00085 $this->assertEquals( 'abvgшђжчћ', 00086 $this->convertToCyrillic( 'abvgшђжчћ' ) 00087 ); 00088 //Same as above, but assert that -{}-s must be removed 00089 $this->assertEquals( 'љabvgњшђжчћџ', 00090 $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' ) 00091 ); 00092 //This text has some Cyrillic, but is recognized as Latin, so it should be converted 00093 $this->assertEquals( 'абвгшђжчћ', 00094 $this->convertToCyrillic( 'абвгšđžčć' ) 00095 ); 00096 //Same as above, but assert that -{}-s must be removed and not converted 00097 $this->assertEquals( 'ljабвгnjшђжчћdž', 00098 $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' ) 00099 ); 00100 // Roman numerals are not converted 00101 $this->assertEquals( 'а I б II в III г IV шђжчћ', 00102 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' ) 00103 ); 00104 } 00105 00109 public function testConversionToLatin() { 00110 //A simple convertion of Latin to Latin 00111 $this->assertEquals( 'abcd', 00112 $this->convertToLatin( 'abcd' ) 00113 ); 00114 //A simple convertion of Cyrillic to Latin 00115 $this->assertEquals( 'abcd', 00116 $this->convertToLatin( 'абцд' ) 00117 ); 00118 //This text has some Latin, but is recognized as Cyrillic, so it should be converted 00119 $this->assertEquals( 'abcdšđžčć', 00120 $this->convertToLatin( 'abcdшђжчћ' ) 00121 ); 00122 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted 00123 $this->assertEquals( 'абцдšđžčć', 00124 $this->convertToLatin( 'абцдšđžčć' ) 00125 ); 00126 } 00127 00132 public function testPlural( $result, $value ) { 00133 $forms = array( 'one', 'few', 'other' ); 00134 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); 00135 } 00136 00141 public function testGetPluralRuleType( $result, $value ) { 00142 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); 00143 } 00144 00145 public static function providePlural() { 00146 return array( 00147 array( 'one', 1 ), 00148 array( 'other', 11 ), 00149 array( 'one', 91 ), 00150 array( 'one', 121 ), 00151 array( 'few', 2 ), 00152 array( 'few', 3 ), 00153 array( 'few', 4 ), 00154 array( 'few', 334 ), 00155 array( 'other', 5 ), 00156 array( 'other', 15 ), 00157 array( 'other', 120 ), 00158 ); 00159 } 00160 00165 public function testPluralTwoForms( $result, $value ) { 00166 $forms = array( 'one', 'other' ); 00167 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); 00168 } 00169 00170 public static function providePluralTwoForms() { 00171 return array( 00172 array( 'one', 1 ), 00173 array( 'other', 11 ), 00174 array( 'other', 4 ), 00175 array( 'one', 91 ), 00176 array( 'one', 121 ), 00177 ); 00178 } 00179 00180 ##### HELPERS ##################################################### 00181 00187 protected function assertUnConverted( $text, $variant, $msg = '' ) { 00188 $this->assertEquals( 00189 $text, 00190 $this->convertTo( $text, $variant ), 00191 $msg 00192 ); 00193 } 00194 00201 protected function assertConverted( $text, $variant, $msg = '' ) { 00202 $this->assertNotEquals( 00203 $text, 00204 $this->convertTo( $text, $variant ), 00205 $msg 00206 ); 00207 } 00208 00214 protected function assertCyrillic( $text, $msg = '' ) { 00215 $this->assertUnConverted( $text, 'sr-ec', $msg ); 00216 $this->assertConverted( $text, 'sr-el', $msg ); 00217 } 00218 00224 protected function assertLatin( $text, $msg = '' ) { 00225 $this->assertUnConverted( $text, 'sr-el', $msg ); 00226 $this->assertConverted( $text, 'sr-ec', $msg ); 00227 } 00228 00229 00231 protected function convertTo( $text, $variant ) { 00232 return $this->getLang() 00233 ->mConverter 00234 ->convertTo( 00235 $text, $variant 00236 ); 00237 } 00238 00239 protected function convertToCyrillic( $text ) { 00240 return $this->convertTo( $text, 'sr-ec' ); 00241 } 00242 00243 protected function convertToLatin( $text ) { 00244 return $this->convertTo( $text, 'sr-el' ); 00245 } 00246 }