3 * PHPUnit tests for the Serbian language.
4 * The language can be represented using two scripts:
7 * Both representations seems to be bijective, hence MediaWiki can convert
8 * from one script to the other.
10 * @author Antoine Musso <hashar at free dot fr>
11 * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
15 require_once dirname( dirname( __FILE__
) ) . '/bootstrap.php';
17 /** Tests for MediaWiki languages/LanguageTr.php */
18 class LanguageSrTest
extends MediaWikiTestCase
{
19 /* Language object. Initialized before each test */
23 $this->lang
= Language
::factory( 'sr' );
29 ##### TESTS #######################################################
31 function testEasyConversions( ) {
32 $this->assertCyrillic(
34 'Cyrillic guessing characters'
38 'Latin guessing characters'
42 function testMixedConversions() {
43 $this->assertCyrillic(
45 'Mostly cyrillic characters'
49 'Mostly latin characters'
53 function testSameAmountOfLatinAndCyrillicGetConverted() {
54 $this->assertConverted(
55 '4 latin: šđčć | 4 cyrillic: шђчћ',
58 $this->assertConverted(
59 '4 latin: šđčć | 4 cyrillic: шђчћ',
65 * @author Nikola Smolenski
67 function testConversionToCyrillic() {
68 $this->assertEquals( 'абвг',
69 $this->convertToCyrillic( 'abvg' )
71 $this->assertEquals( 'абвг',
72 $this->convertToCyrillic( 'абвг' )
74 $this->assertEquals( 'abvgшђжчћ',
75 $this->convertToCyrillic( 'abvgшђжчћ' )
77 $this->assertEquals( 'абвгшђжчћ',
78 $this->convertToCyrillic( 'абвгšđžčć' )
80 // Roman numerals are not converted
81 $this->assertEquals( 'а I б II в III г IV шђжчћ',
82 $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
86 function testConversionToLatin() {
87 $this->assertEquals( 'abcd',
88 $this->convertToLatin( 'abcd' )
90 $this->assertEquals( 'abcd',
91 $this->convertToLatin( 'абцд' )
93 $this->assertEquals( 'abcdšđžčć',
94 $this->convertToLatin( 'abcdшђжчћ' )
96 $this->assertEquals( 'абцдšđžčć',
97 $this->convertToLatin( 'абцдšđžčć' )
101 /** @dataProvider providePluralFourForms */
102 function testPluralFourForms( $result, $value ) {
103 $forms = array( 'one', 'few', 'many', 'other' );
104 $this->assertEquals( $result, $this->lang
->convertPlural( $value, $forms ) );
107 function providePluralFourForms() {
119 array( 'many', 120 ),
122 /** @dataProvider providePluralTwoForms */
123 function testPluralTwoForms( $result, $value ) {
124 $forms = array( 'one', 'several' );
125 $this->assertEquals( $result, $this->lang
->convertPlural( $value, $forms ) );
127 function providePluralTwoForms() {
130 array( 'several', 11 ),
131 array( 'several', 91 ),
132 array( 'several', 121 ),
136 ##### HELPERS #####################################################
138 *Wrapper to verify text stay the same after applying conversion
139 * @param $text string Text to convert
140 * @param $variant string Language variant 'sr-ec' or 'sr-el'
141 * @param $msg string Optional message
143 function assertUnConverted( $text, $variant, $msg = '' ) {
146 $this->convertTo( $text, $variant ),
151 * Wrapper to verify a text is different once converted to a variant.
152 * @param $text string Text to convert
153 * @param $variant string Language variant 'sr-ec' or 'sr-el'
154 * @param $msg string Optional message
156 function assertConverted( $text, $variant, $msg = '' ) {
157 $this->assertNotEquals(
159 $this->convertTo( $text, $variant ),
165 * Verifiy the given Cyrillic text is not converted when using
166 * using the cyrillic variant and converted to Latin when using
169 function assertCyrillic( $text, $msg = '' ) {
170 $this->assertUnConverted( $text, 'sr-ec', $msg );
171 $this->assertConverted( $text, 'sr-el', $msg );
174 * Verifiy the given Latin text is not converted when using
175 * using the Latin variant and converted to Cyrillic when using
176 * the Cyrillic variant.
178 function assertLatin( $text, $msg = '' ) {
179 $this->assertUnConverted( $text, 'sr-el', $msg );
180 $this->assertConverted( $text, 'sr-ec', $msg );
184 /** Wrapper for converter::convertTo() method*/
185 function convertTo( $text, $variant ) {
193 function convertToCyrillic( $text ) {
194 return $this->convertTo( $text, 'sr-ec' );
196 function convertToLatin( $text ) {
197 return $this->convertTo( $text, 'sr-el' );