MediaWiki  REL1_20
LanguageSrTest.php
Go to the documentation of this file.
00001 <?php
00015 require_once dirname( __DIR__ ) . '/bootstrap.php';
00016 
00018 class LanguageSrTest extends MediaWikiTestCase {
00019         /* Language object. Initialized before each test */
00020         private $lang;
00021 
00022         function setUp() {
00023                 $this->lang = Language::factory( 'sr' );
00024         }
00025         function tearDown() {
00026                 unset( $this->lang );
00027         }
00028 
00029         ##### TESTS #######################################################
00030 
00031         function testEasyConversions( ) {
00032                 $this->assertCyrillic(
00033                         'шђчћжШЂЧЋЖ',
00034                         'Cyrillic guessing characters'
00035                 );
00036                 $this->assertLatin(
00037                         'šđč枊ĐČĆŽ',
00038                         'Latin guessing characters'
00039                 );
00040         }
00041 
00042         function testMixedConversions() {
00043                 $this->assertCyrillic(
00044                         'шђчћжШЂЧЋЖ - šđčćž',
00045                         'Mostly cyrillic characters'
00046                 );
00047                 $this->assertLatin(
00048                         'šđč枊ĐČĆŽ - шђчћж',
00049                         'Mostly latin characters'
00050                 );
00051         }
00052 
00053         function testSameAmountOfLatinAndCyrillicGetConverted() {
00054                 $this->assertConverted(
00055                         '4 latin: šđčć | 4 cyrillic: шђчћ',
00056                         'sr-ec'
00057                 );
00058                 $this->assertConverted(
00059                         '4 latin: šđčć | 4 cyrillic: шђчћ',
00060                         'sr-el'
00061                 );
00062         }
00063 
00067         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 
00106         function testConversionToLatin() {
00107                 //A simple convertion of Latin to Latin
00108                 $this->assertEquals( 'abcd',
00109                         $this->convertToLatin( 'abcd' )
00110                 );
00111                 //A simple convertion of Cyrillic to Latin
00112                 $this->assertEquals( 'abcd',
00113                         $this->convertToLatin( 'абцд' )
00114                 );
00115                 //This text has some Latin, but is recognized as Cyrillic, so it should be converted
00116                 $this->assertEquals( 'abcdšđžčć',
00117                         $this->convertToLatin( 'abcdшђжчћ' )
00118                 );
00119                 //This text has some Cyrillic, but is recognized as Latin, so it should not be converted
00120                 $this->assertEquals( 'абцдšđžčć',
00121                         $this->convertToLatin( 'абцдšđžčć' )
00122                 );
00123         }
00124 
00126         function testPluralFourForms( $result, $value ) {
00127                 $forms = array( 'one', 'few', 'many', 'other' );
00128                 $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
00129         }
00130 
00131         function providePluralFourForms() {
00132                 return array (
00133                         array( 'one', 1 ),
00134                         array( 'many', 11 ),
00135                         array( 'one', 91 ),
00136                         array( 'one', 121 ),
00137                         array( 'few', 2 ),
00138                         array( 'few', 3 ),
00139                         array( 'few', 4 ),
00140                         array( 'few', 334 ),
00141                         array( 'many', 5 ),
00142                         array( 'many', 15 ),
00143                         array( 'many', 120 ),
00144                 );
00145         }
00147         function testPluralTwoForms( $result, $value ) {
00148                 $forms = array( 'one', 'several' );
00149                 $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
00150         }
00151         function providePluralTwoForms() {
00152                 return array (
00153                         array( 'one', 1 ),
00154                         array( 'several', 11 ),
00155                         array( 'several', 91 ),
00156                         array( 'several', 121 ),
00157                 );
00158         }
00159 
00160         ##### HELPERS #####################################################
00161 
00167         function assertUnConverted( $text, $variant, $msg = '' ) {
00168                 $this->assertEquals(
00169                         $text,
00170                         $this->convertTo( $text, $variant ),
00171                         $msg
00172                 );
00173         }
00180         function assertConverted( $text, $variant, $msg = '' ) {
00181                 $this->assertNotEquals(
00182                         $text,
00183                         $this->convertTo( $text, $variant ),
00184                         $msg
00185                 );
00186         }
00187 
00193         function assertCyrillic( $text, $msg = '' ) {
00194                 $this->assertUnConverted( $text, 'sr-ec', $msg );
00195                 $this->assertConverted( $text, 'sr-el', $msg );
00196         }
00202         function assertLatin( $text, $msg = '' ) {
00203                 $this->assertUnConverted( $text, 'sr-el', $msg );
00204                 $this->assertConverted( $text, 'sr-ec', $msg );
00205         }
00206 
00207 
00209         function convertTo( $text, $variant ) {
00210                 return $this
00211                         ->lang
00212                         ->mConverter
00213                         ->convertTo(
00214                                 $text, $variant
00215                         );
00216         }
00217         function convertToCyrillic( $text ) {
00218                 return $this->convertTo( $text, 'sr-ec' );
00219         }
00220         function convertToLatin( $text ) {
00221                 return $this->convertTo( $text, 'sr-el' );
00222         }
00223 }