MediaWiki  master
LanguageSrTest.php
Go to the documentation of this file.
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         }
00138         function testPluralTwoForms( $result, $value ) {
00139                 $forms = array( 'one', 'several' );
00140                 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
00141         }
00142         function providePluralTwoForms() {
00143                 return array (
00144                         array( 'one', 1 ),
00145                         array( 'several', 11 ),
00146                         array( 'several', 91 ),
00147                         array( 'several', 121 ),
00148                 );
00149         }
00150 
00151         ##### HELPERS #####################################################
00152 
00158         function assertUnConverted( $text, $variant, $msg = '' ) {
00159                 $this->assertEquals(
00160                         $text,
00161                         $this->convertTo( $text, $variant ),
00162                         $msg
00163                 );
00164         }
00171         function assertConverted( $text, $variant, $msg = '' ) {
00172                 $this->assertNotEquals(
00173                         $text,
00174                         $this->convertTo( $text, $variant ),
00175                         $msg
00176                 );
00177         }
00178 
00184         function assertCyrillic( $text, $msg = '' ) {
00185                 $this->assertUnConverted( $text, 'sr-ec', $msg );
00186                 $this->assertConverted( $text, 'sr-el', $msg );
00187         }
00193         function assertLatin( $text, $msg = '' ) {
00194                 $this->assertUnConverted( $text, 'sr-el', $msg );
00195                 $this->assertConverted( $text, 'sr-ec', $msg );
00196         }
00197 
00198 
00200         function convertTo( $text, $variant ) {
00201                 return $this->getLang()
00202                         ->mConverter
00203                         ->convertTo(
00204                                 $text, $variant
00205                         );
00206         }
00207         function convertToCyrillic( $text ) {
00208                 return $this->convertTo( $text, 'sr-ec' );
00209         }
00210         function convertToLatin( $text ) {
00211                 return $this->convertTo( $text, 'sr-el' );
00212         }
00213 }