2011-11-16 15:12:00 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* PHPUnit tests for the Serbian language.
|
|
|
|
|
|
* The language can be represented using two scripts:
|
|
|
|
|
|
* - Latin (SR_el)
|
|
|
|
|
|
* - Cyrillic (SR_ec)
|
|
|
|
|
|
* Both representations seems to be bijective, hence MediaWiki can convert
|
|
|
|
|
|
* from one script to the other.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author Antoine Musso <hashar at free dot fr>
|
|
|
|
|
|
* @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
|
|
|
|
|
|
* @file
|
2013-10-22 10:32:29 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @todo methods in test class should be tidied:
|
|
|
|
|
|
* - Should be split into separate test methods and data providers
|
|
|
|
|
|
* - Tests for LanguageConverter and Language should probably be separate..
|
2011-11-16 15:12:00 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
2012-07-27 13:56:50 +00:00
|
|
|
|
/** Tests for MediaWiki languages/LanguageSr.php */
|
2012-10-23 20:53:17 +00:00
|
|
|
|
class LanguageSrTest extends LanguageClassesTestCase {
|
2013-10-22 10:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LanguageConverter::convertTo
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testEasyConversions() {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertCyrillic(
|
|
|
|
|
|
'шђчћжШЂЧЋЖ',
|
|
|
|
|
|
'Cyrillic guessing characters'
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertLatin(
|
|
|
|
|
|
'šđč枊ĐČĆŽ',
|
|
|
|
|
|
'Latin guessing characters'
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LanguageConverter::convertTo
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testMixedConversions() {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertCyrillic(
|
|
|
|
|
|
'шђчћжШЂЧЋЖ - šđčćž',
|
|
|
|
|
|
'Mostly cyrillic characters'
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertLatin(
|
|
|
|
|
|
'šđč枊ĐČĆŽ - шђчћж',
|
|
|
|
|
|
'Mostly latin characters'
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LanguageConverter::convertTo
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testSameAmountOfLatinAndCyrillicGetConverted() {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertConverted(
|
|
|
|
|
|
'4 latin: šđčć | 4 cyrillic: шђчћ',
|
|
|
|
|
|
'sr-ec'
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertConverted(
|
|
|
|
|
|
'4 latin: šđčć | 4 cyrillic: шђчћ',
|
|
|
|
|
|
'sr-el'
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-02 11:14:26 +00:00
|
|
|
|
* @author Nikola Smolenski
|
2013-10-22 10:32:29 +00:00
|
|
|
|
* @covers LanguageConverter::convertTo
|
2011-11-16 15:12:00 +00:00
|
|
|
|
*/
|
2013-10-22 10:32:29 +00:00
|
|
|
|
public function testConversionToCyrillic() {
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// A simple convertion of Latin to Cyrillic
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'абвг',
|
|
|
|
|
|
$this->convertToCyrillic( 'abvg' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// Same as above, but assert that -{}-s must be removed and not converted
|
2012-04-10 16:36:51 +00:00
|
|
|
|
$this->assertEquals( 'ljабnjвгdž',
|
|
|
|
|
|
$this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// A simple convertion of Cyrillic to Cyrillic
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'абвг',
|
|
|
|
|
|
$this->convertToCyrillic( 'абвг' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// Same as above, but assert that -{}-s must be removed and not converted
|
2012-04-10 16:36:51 +00:00
|
|
|
|
$this->assertEquals( 'ljабnjвгdž',
|
|
|
|
|
|
$this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// This text has some Latin, but is recognized as Cyrillic, so it should not be converted
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'abvgшђжчћ',
|
|
|
|
|
|
$this->convertToCyrillic( 'abvgшђжчћ' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// Same as above, but assert that -{}-s must be removed
|
2012-04-10 16:36:51 +00:00
|
|
|
|
$this->assertEquals( 'љabvgњшђжчћџ',
|
|
|
|
|
|
$this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// This text has some Cyrillic, but is recognized as Latin, so it should be converted
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'абвгшђжчћ',
|
|
|
|
|
|
$this->convertToCyrillic( 'абвгšđžčć' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// Same as above, but assert that -{}-s must be removed and not converted
|
2012-04-10 16:36:51 +00:00
|
|
|
|
$this->assertEquals( 'ljабвгnjшђжчћdž',
|
|
|
|
|
|
$this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
|
|
|
|
|
|
);
|
2012-02-02 11:14:26 +00:00
|
|
|
|
// Roman numerals are not converted
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'а I б II в III г IV шђжчћ',
|
|
|
|
|
|
$this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LanguageConverter::convertTo
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testConversionToLatin() {
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// A simple convertion of Latin to Latin
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'abcd',
|
|
|
|
|
|
$this->convertToLatin( 'abcd' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// A simple convertion of Cyrillic to Latin
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'abcd',
|
|
|
|
|
|
$this->convertToLatin( 'абцд' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// This text has some Latin, but is recognized as Cyrillic, so it should be converted
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'abcdšđžčć',
|
|
|
|
|
|
$this->convertToLatin( 'abcdшђжчћ' )
|
|
|
|
|
|
);
|
2015-09-11 13:44:59 +00:00
|
|
|
|
// This text has some Cyrillic, but is recognized as Latin, so it should not be converted
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals( 'абцдšđžčć',
|
|
|
|
|
|
$this->convertToLatin( 'абцдšđžčć' )
|
|
|
|
|
|
);
|
2012-02-01 15:59:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider providePlural
|
|
|
|
|
|
* @covers Language::convertPlural
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testPlural( $result, $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$forms = [ 'one', 'few', 'other' ];
|
2012-10-23 20:53:17 +00:00
|
|
|
|
$this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
|
2012-02-01 15:59:26 +00:00
|
|
|
|
}
|
2011-11-16 15:12:00 +00:00
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider providePlural
|
|
|
|
|
|
* @covers Language::getPluralRuleType
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testGetPluralRuleType( $result, $value ) {
|
2013-01-25 01:10:37 +00:00
|
|
|
|
$this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
|
public static function providePlural() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
return [
|
|
|
|
|
|
[ 'one', 1 ],
|
|
|
|
|
|
[ 'other', 11 ],
|
|
|
|
|
|
[ 'one', 91 ],
|
|
|
|
|
|
[ 'one', 121 ],
|
|
|
|
|
|
[ 'few', 2 ],
|
|
|
|
|
|
[ 'few', 3 ],
|
|
|
|
|
|
[ 'few', 4 ],
|
|
|
|
|
|
[ 'few', 334 ],
|
|
|
|
|
|
[ 'other', 5 ],
|
|
|
|
|
|
[ 'other', 15 ],
|
|
|
|
|
|
[ 'other', 120 ],
|
|
|
|
|
|
];
|
2012-02-01 15:59:26 +00:00
|
|
|
|
}
|
2013-02-15 10:27:48 +00:00
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider providePluralTwoForms
|
|
|
|
|
|
* @covers Language::convertPlural
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testPluralTwoForms( $result, $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$forms = [ 'one', 'other' ];
|
2012-10-23 20:53:17 +00:00
|
|
|
|
$this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
|
2012-02-01 15:59:26 +00:00
|
|
|
|
}
|
2013-02-15 10:27:48 +00:00
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
|
public static function providePluralTwoForms() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
return [
|
|
|
|
|
|
[ 'one', 1 ],
|
|
|
|
|
|
[ 'other', 11 ],
|
|
|
|
|
|
[ 'other', 4 ],
|
|
|
|
|
|
[ 'one', 91 ],
|
|
|
|
|
|
[ 'one', 121 ],
|
|
|
|
|
|
];
|
2011-11-16 15:12:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
|
# #### HELPERS #####################################################
|
2011-11-16 15:12:00 +00:00
|
|
|
|
/**
|
|
|
|
|
|
*Wrapper to verify text stay the same after applying conversion
|
2014-04-17 18:43:42 +00:00
|
|
|
|
* @param string $text Text to convert
|
|
|
|
|
|
* @param string $variant Language variant 'sr-ec' or 'sr-el'
|
|
|
|
|
|
* @param string $msg Optional message
|
2011-11-16 15:12:00 +00:00
|
|
|
|
*/
|
2013-10-22 10:32:29 +00:00
|
|
|
|
protected function assertUnConverted( $text, $variant, $msg = '' ) {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
$text,
|
|
|
|
|
|
$this->convertTo( $text, $variant ),
|
|
|
|
|
|
$msg
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2013-02-15 10:27:48 +00:00
|
|
|
|
|
2011-11-16 15:12:00 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Wrapper to verify a text is different once converted to a variant.
|
2014-04-17 18:43:42 +00:00
|
|
|
|
* @param string $text Text to convert
|
|
|
|
|
|
* @param string $variant Language variant 'sr-ec' or 'sr-el'
|
|
|
|
|
|
* @param string $msg Optional message
|
2011-11-16 15:12:00 +00:00
|
|
|
|
*/
|
2013-10-22 10:32:29 +00:00
|
|
|
|
protected function assertConverted( $text, $variant, $msg = '' ) {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertNotEquals(
|
|
|
|
|
|
$text,
|
|
|
|
|
|
$this->convertTo( $text, $variant ),
|
|
|
|
|
|
$msg
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Verifiy the given Cyrillic text is not converted when using
|
|
|
|
|
|
* using the cyrillic variant and converted to Latin when using
|
|
|
|
|
|
* the Latin variant.
|
2014-04-17 18:43:42 +00:00
|
|
|
|
* @param string $text Text to convert
|
|
|
|
|
|
* @param string $msg Optional message
|
2011-11-16 15:12:00 +00:00
|
|
|
|
*/
|
2013-10-22 10:32:29 +00:00
|
|
|
|
protected function assertCyrillic( $text, $msg = '' ) {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertUnConverted( $text, 'sr-ec', $msg );
|
|
|
|
|
|
$this->assertConverted( $text, 'sr-el', $msg );
|
|
|
|
|
|
}
|
2013-02-15 10:27:48 +00:00
|
|
|
|
|
2011-11-16 15:12:00 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Verifiy the given Latin text is not converted when using
|
|
|
|
|
|
* using the Latin variant and converted to Cyrillic when using
|
|
|
|
|
|
* the Cyrillic variant.
|
2014-04-17 18:43:42 +00:00
|
|
|
|
* @param string $text Text to convert
|
|
|
|
|
|
* @param string $msg Optional message
|
2011-11-16 15:12:00 +00:00
|
|
|
|
*/
|
2013-10-22 10:32:29 +00:00
|
|
|
|
protected function assertLatin( $text, $msg = '' ) {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
$this->assertUnConverted( $text, 'sr-el', $msg );
|
|
|
|
|
|
$this->assertConverted( $text, 'sr-ec', $msg );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Wrapper for converter::convertTo() method*/
|
2013-10-22 10:32:29 +00:00
|
|
|
|
protected function convertTo( $text, $variant ) {
|
2012-10-23 20:53:17 +00:00
|
|
|
|
return $this->getLang()
|
2011-11-16 15:12:00 +00:00
|
|
|
|
->mConverter
|
|
|
|
|
|
->convertTo(
|
2013-03-25 23:27:14 +00:00
|
|
|
|
$text, $variant
|
|
|
|
|
|
);
|
2011-11-16 15:12:00 +00:00
|
|
|
|
}
|
2013-02-15 10:27:48 +00:00
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
protected function convertToCyrillic( $text ) {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
return $this->convertTo( $text, 'sr-ec' );
|
|
|
|
|
|
}
|
2013-02-15 10:27:48 +00:00
|
|
|
|
|
2013-10-22 10:32:29 +00:00
|
|
|
|
protected function convertToLatin( $text ) {
|
2011-11-16 15:12:00 +00:00
|
|
|
|
return $this->convertTo( $text, 'sr-el' );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|