MediaWiki  REL1_19
LanguageSrTest.php
Go to the documentation of this file.
00001 <?php
00015 require_once dirname( dirname( __FILE__ ) ) . '/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                 $this->assertEquals( 'абвг',
00069                         $this->convertToCyrillic( 'abvg' )
00070                 );
00071                 $this->assertEquals( 'абвг',
00072                         $this->convertToCyrillic( 'абвг' )
00073                 );
00074                 $this->assertEquals( 'abvgшђжчћ',
00075                         $this->convertToCyrillic( 'abvgшђжчћ' )
00076                 );
00077                 $this->assertEquals( 'абвгшђжчћ',
00078                         $this->convertToCyrillic( 'абвгšđžčć' )
00079                 );
00080                 // Roman numerals are not converted
00081                 $this->assertEquals( 'а I б II в III г IV шђжчћ',
00082                         $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
00083                 );
00084         }
00085 
00086         function testConversionToLatin() {
00087                 $this->assertEquals( 'abcd',
00088                         $this->convertToLatin( 'abcd' )
00089                 );
00090                 $this->assertEquals( 'abcd',
00091                         $this->convertToLatin( 'абцд' )
00092                 );
00093                 $this->assertEquals( 'abcdšđžčć',
00094                         $this->convertToLatin( 'abcdшђжчћ' )
00095                 );
00096                 $this->assertEquals( 'абцдšđžčć',
00097                         $this->convertToLatin( 'абцдšđžčć' )
00098                 );
00099         }
00100 
00102         function testPluralFourForms( $result, $value ) {
00103                 $forms = array( 'one', 'few', 'many', 'other' );
00104                 $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
00105         }
00106 
00107         function providePluralFourForms() {
00108                 return array (
00109                         array( 'one', 1 ),
00110                         array( 'many', 11 ),
00111                         array( 'one', 91 ),
00112                         array( 'one', 121 ),
00113                         array( 'few', 2 ),
00114                         array( 'few', 3 ),
00115                         array( 'few', 4 ),
00116                         array( 'few', 334 ),
00117                         array( 'many', 5 ),
00118                         array( 'many', 15 ),
00119                         array( 'many', 120 ),
00120                 );
00121         }
00123         function testPluralTwoForms( $result, $value ) {
00124                 $forms = array( 'one', 'several' );
00125                 $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
00126         }
00127         function providePluralTwoForms() {
00128                 return array (
00129                         array( 'one', 1 ),
00130                         array( 'several', 11 ),
00131                         array( 'several', 91 ),
00132                         array( 'several', 121 ),
00133                 );
00134         }
00135 
00136         ##### HELPERS #####################################################
00137 
00143         function assertUnConverted( $text, $variant, $msg = '' ) {
00144                 $this->assertEquals(
00145                         $text,
00146                         $this->convertTo( $text, $variant ),
00147                         $msg
00148                 );
00149         }
00156         function assertConverted( $text, $variant, $msg = '' ) {
00157                 $this->assertNotEquals(
00158                         $text,
00159                         $this->convertTo( $text, $variant ),
00160                         $msg
00161                 );
00162         }
00163 
00169         function assertCyrillic( $text, $msg = '' ) {
00170                 $this->assertUnConverted( $text, 'sr-ec', $msg );
00171                 $this->assertConverted( $text, 'sr-el', $msg );
00172         }
00178         function assertLatin( $text, $msg = '' ) {
00179                 $this->assertUnConverted( $text, 'sr-el', $msg );
00180                 $this->assertConverted( $text, 'sr-ec', $msg );
00181         }
00182 
00183 
00185         function convertTo( $text, $variant ) {
00186                 return $this
00187                         ->lang
00188                         ->mConverter
00189                         ->convertTo(
00190                                 $text, $variant
00191                         );
00192         }
00193         function convertToCyrillic( $text ) {
00194                 return $this->convertTo( $text, 'sr-ec' );
00195         }
00196         function convertToLatin( $text ) {
00197                 return $this->convertTo( $text, 'sr-el' );
00198         }
00199 }