diff options
Diffstat (limited to 'tests/phpunit/languages')
51 files changed, 2025 insertions, 1100 deletions
diff --git a/tests/phpunit/languages/LanguageAmTest.php b/tests/phpunit/languages/LanguageAmTest.php index 3a648ded..a644f5e0 100644 --- a/tests/phpunit/languages/LanguageAmTest.php +++ b/tests/phpunit/languages/LanguageAmTest.php @@ -6,24 +6,26 @@ */ /** Tests for MediaWiki languages/LanguageAm.php */ -class LanguageAmTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Am' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageAmTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'one', 0 ), array( 'one', 1 ), array( 'other', 2 ), diff --git a/tests/phpunit/languages/LanguageArTest.php b/tests/phpunit/languages/LanguageArTest.php index b23e0534..7b48f236 100644 --- a/tests/phpunit/languages/LanguageArTest.php +++ b/tests/phpunit/languages/LanguageArTest.php @@ -5,30 +5,26 @@ */ /** Tests for MediaWiki languages/LanguageAr.php */ -class LanguageArTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Ar' ); - } - function tearDown() { - unset( $this->lang ); - } - - function testFormatNum() { - $this->assertEquals( '١٬٢٣٤٬٥٦٧', $this->lang->formatNum( '1234567' ) ); - $this->assertEquals( '-١٢٫٨٩', $this->lang->formatNum( -12.89 ) ); +class LanguageArTest extends LanguageClassesTestCase { + /** + * @covers Language::formatNum + * @todo split into a test and a dataprovider + */ + public function testFormatNum() { + $this->assertEquals( '١٬٢٣٤٬٥٦٧', $this->getLang()->formatNum( '1234567' ) ); + $this->assertEquals( '-١٢٫٨٩', $this->getLang()->formatNum( -12.89 ) ); } /** * Mostly to test the raw ascii feature. * @dataProvider providerSprintfDate + * @covers Language::sprintfDate */ - function testSprintfDate( $format, $date, $expected ) { - $this->assertEquals( $expected, $this->lang->sprintfDate( $format, $date ) ); + public function testSprintfDate( $format, $date, $expected ) { + $this->assertEquals( $expected, $this->getLang()->sprintfDate( $format, $date ) ); } - function providerSprintfDate() { + public static function providerSprintfDate() { return array( array( 'xg "vs" g', @@ -52,13 +48,26 @@ class LanguageArTest extends MediaWikiTestCase { ), ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'zero', 'one', 'two', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'zero', 'one', 'two', 'few', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { - return array ( + + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { + return array( array( 'zero', 0 ), array( 'one', 1 ), array( 'two', 2 ), diff --git a/tests/phpunit/languages/LanguageBeTest.php b/tests/phpunit/languages/LanguageBeTest.php index 735ccc63..7bd586af 100644 --- a/tests/phpunit/languages/LanguageBeTest.php +++ b/tests/phpunit/languages/LanguageBeTest.php @@ -6,24 +6,26 @@ */ /** Tests for MediaWiki languages/LanguageBe.php */ -class LanguageBeTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Be' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageBeTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'one', 1 ), array( 'many', 11 ), array( 'one', 91 ), diff --git a/tests/phpunit/languages/LanguageBe_taraskTest.php b/tests/phpunit/languages/LanguageBe_taraskTest.php index 765cdb8f..dbdb5889 100644 --- a/tests/phpunit/languages/LanguageBe_taraskTest.php +++ b/tests/phpunit/languages/LanguageBe_taraskTest.php @@ -1,40 +1,65 @@ <?php -class LanguageBeTaraskTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Be-tarask' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageBe_taraskTest extends LanguageClassesTestCase { + /** + * Make sure the language code we are given is indeed + * be-tarask. This is to ensure LanguageClassesTestCase + * does not give us the wrong language. + */ + public function testBeTaraskTestsUsesBeTaraskCode() { + $this->assertEquals( 'be-tarask', + $this->getLang()->getCode() + ); } - /** see bug 23156 & r64981 */ - function testSearchRightSingleQuotationMarkAsApostroph() { + /** + * @see bug 23156 & r64981 + * @covers Language::commafy + */ + public function testSearchRightSingleQuotationMarkAsApostroph() { $this->assertEquals( "'", - $this->lang->normalizeForSearch( '’' ), + $this->getLang()->normalizeForSearch( '’' ), 'bug 23156: U+2019 conversion to U+0027' ); } - /** see bug 23156 & r64981 */ - function testCommafy() { - $this->assertEquals( '1,234,567', $this->lang->commafy( '1234567' ) ); - $this->assertEquals( '12,345', $this->lang->commafy( '12345' ) ); + + /** + * @see bug 23156 & r64981 + * @covers Language::commafy + */ + public function testCommafy() { + $this->assertEquals( '1,234,567', $this->getLang()->commafy( '1234567' ) ); + $this->assertEquals( '12,345', $this->getLang()->commafy( '12345' ) ); } - /** see bug 23156 & r64981 */ - function testDoesNotCommafyFourDigitsNumber() { - $this->assertEquals( '1234', $this->lang->commafy( '1234' ) ); + + /** + * @see bug 23156 & r64981 + * @covers Language::commafy + */ + public function testDoesNotCommafyFourDigitsNumber() { + $this->assertEquals( '1234', $this->getLang()->commafy( '1234' ) ); } - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralFourForms() { - return array ( + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { + return array( array( 'one', 1 ), array( 'many', 11 ), array( 'one', 91 ), @@ -48,18 +73,23 @@ class LanguageBeTaraskTest extends MediaWikiTestCase { array( 'many', 120 ), ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( '1=one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { - return array ( + + public static function providePluralTwoForms() { + return array( + array( 'other', 0 ), array( 'one', 1 ), - array( 'several', 11 ), - array( 'several', 91 ), - array( 'several', 121 ), + array( 'other', 11 ), + array( 'other', 91 ), + array( 'other', 121 ), ); } - } diff --git a/tests/phpunit/languages/LanguageBhTest.php b/tests/phpunit/languages/LanguageBhTest.php deleted file mode 100644 index e1e2a13e..00000000 --- a/tests/phpunit/languages/LanguageBhTest.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php -/** - * @author Santhosh Thottingal - * @copyright Copyright © 2012, Santhosh Thottingal - * @file - */ - -/** Tests for MediaWiki languages/LanguageBh.php */ -class LanguageBhTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Bh' ); - } - function tearDown() { - unset( $this->lang ); - } - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); - } - - function providePlural() { - return array ( - array( 'one', 0 ), - array( 'one', 1 ), - array( 'other', 2 ), - array( 'other', 200 ), - ); - } - -} diff --git a/tests/phpunit/languages/LanguageBhoTest.php b/tests/phpunit/languages/LanguageBhoTest.php new file mode 100644 index 00000000..187bfbbc --- /dev/null +++ b/tests/phpunit/languages/LanguageBhoTest.php @@ -0,0 +1,35 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** Tests for MediaWiki languages/LanguageBho.php */ +class LanguageBhoTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { + return array( + array( 'one', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), + array( 'other', 200 ), + ); + } +} diff --git a/tests/phpunit/languages/LanguageBsTest.php b/tests/phpunit/languages/LanguageBsTest.php index b6631c03..7aca2ab1 100644 --- a/tests/phpunit/languages/LanguageBsTest.php +++ b/tests/phpunit/languages/LanguageBsTest.php @@ -5,37 +5,38 @@ * @file */ -/** Tests for MediaWiki languages/LanguageBs.php */ -class LanguageBsTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Bs' ); - } - function tearDown() { - unset( $this->lang ); +/** Tests for Croatian (hrvatski) */ +class LanguageBsTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( - array( 'many', 0 ), + public static function providePlural() { + return array( + array( 'other', 0 ), array( 'one', 1 ), array( 'few', 2 ), array( 'few', 4 ), - array( 'many', 5 ), - array( 'many', 11 ), - array( 'many', 20 ), + array( 'other', 5 ), + array( 'other', 11 ), + array( 'other', 20 ), array( 'one', 21 ), array( 'few', 24 ), - array( 'many', 25 ), - array( 'many', 200 ), + array( 'other', 25 ), + array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageClassesTestCase.php b/tests/phpunit/languages/LanguageClassesTestCase.php new file mode 100644 index 00000000..632e037f --- /dev/null +++ b/tests/phpunit/languages/LanguageClassesTestCase.php @@ -0,0 +1,74 @@ +<?php +/** + * Helping class to run tests using a clean language instance. + * + * This is intended for the MediaWiki language class tests under + * tests/phpunit/languages. + * + * Before each tests, a new language object is build which you + * can retrieve in your test using the $this->getLang() method: + * + * @par Using the crafted language object: + * @code + * function testHasLanguageObject() { + * $langObject = $this->getLang(); + * $this->assertInstanceOf( 'LanguageFoo', + * $langObject + * ); + * } + * @endcode + */ +abstract class LanguageClassesTestCase extends MediaWikiTestCase { + /** + * Internal language object + * + * A new object is created before each tests thanks to PHPUnit + * setUp() method, it is deleted after each test too. To get + * this object you simply use the getLang method. + * + * You must have setup a language code first. See $LanguageClassCode + * @code + * function testWeAreTheChampions() { + * $this->getLang(); # language object + * } + * @endcode + */ + private $languageObject; + + /** + * @return Language + */ + protected function getLang() { + return $this->languageObject; + } + + /** + * Create a new language object before each test. + */ + protected function setUp() { + parent::setUp(); + $found = preg_match( '/Language(.+)Test/', get_called_class(), $m ); + if ( $found ) { + # Normalize language code since classes uses underscores + $m[1] = str_replace( '_', '-', $m[1] ); + } else { + # Fallback to english language + $m[1] = 'en'; + wfDebug( + __METHOD__ . " could not extract a language name " + . "out of " . get_called_class() . " failling back to 'en'\n" + ); + } + // @todo validate $m[1] which should be a valid language code + $this->languageObject = Language::factory( $m[1] ); + } + + /** + * Delete the internal language object so each test start + * out with a fresh language instance. + */ + protected function tearDown() { + unset( $this->languageObject ); + parent::tearDown(); + } +} diff --git a/tests/phpunit/languages/LanguageCsTest.php b/tests/phpunit/languages/LanguageCsTest.php index dda29f9a..da9e6b88 100644 --- a/tests/phpunit/languages/LanguageCsTest.php +++ b/tests/phpunit/languages/LanguageCsTest.php @@ -6,24 +6,26 @@ */ /** Tests for MediaWiki languages/classes/Languagecs.php */ -class LanguageCsTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'cs' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageCsTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'few', 2 ), @@ -36,5 +38,4 @@ class LanguageCsTest extends MediaWikiTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageCuTest.php b/tests/phpunit/languages/LanguageCuTest.php index f8186d7b..07193172 100644 --- a/tests/phpunit/languages/LanguageCuTest.php +++ b/tests/phpunit/languages/LanguageCuTest.php @@ -6,36 +6,37 @@ */ /** Tests for MediaWiki languages/LanguageCu.php */ -class LanguageCuTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'cu' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageCuTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), - array( 'few', 2 ), - array( 'many', 3 ), - array( 'many', 4 ), + array( 'two', 2 ), + array( 'few', 3 ), + array( 'few', 4 ), array( 'other', 5 ), array( 'one', 11 ), array( 'other', 20 ), - array( 'few', 22 ), - array( 'many', 223 ), + array( 'two', 22 ), + array( 'few', 223 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageCyTest.php b/tests/phpunit/languages/LanguageCyTest.php index e9f9e410..eaf663a8 100644 --- a/tests/phpunit/languages/LanguageCyTest.php +++ b/tests/phpunit/languages/LanguageCyTest.php @@ -6,24 +6,26 @@ */ /** Tests for MediaWiki languages/classes/LanguageCy.php */ -class LanguageCyTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'cy' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageCyTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'zero', 'one', 'two', 'few', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'zero', 'one', 'two', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'zero', 0 ), array( 'one', 1 ), array( 'two', 2 ), @@ -38,5 +40,4 @@ class LanguageCyTest extends MediaWikiTestCase { array( 'other', 200.00 ), ); } - } diff --git a/tests/phpunit/languages/LanguageDsbTest.php b/tests/phpunit/languages/LanguageDsbTest.php index ab7f9313..94c11bcc 100644 --- a/tests/phpunit/languages/LanguageDsbTest.php +++ b/tests/phpunit/languages/LanguageDsbTest.php @@ -6,24 +6,26 @@ */ /** Tests for MediaWiki languages/classes/LanguageDsb.php */ -class LanguageDsbTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'dsb' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageDsbTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'two', 'few', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'one', 101 ), @@ -36,5 +38,4 @@ class LanguageDsbTest extends MediaWikiTestCase { array( 'other', 555 ), ); } - } diff --git a/tests/phpunit/languages/LanguageFrTest.php b/tests/phpunit/languages/LanguageFrTest.php index 8538744e..46b65011 100644 --- a/tests/phpunit/languages/LanguageFrTest.php +++ b/tests/phpunit/languages/LanguageFrTest.php @@ -6,29 +6,30 @@ */ /** Tests for MediaWiki languages/classes/LanguageFr.php */ -class LanguageFrTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'fr' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageFrTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'one', 0 ), array( 'one', 1 ), array( 'other', 2 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageGaTest.php b/tests/phpunit/languages/LanguageGaTest.php index fbd9f11d..c009f56b 100644 --- a/tests/phpunit/languages/LanguageGaTest.php +++ b/tests/phpunit/languages/LanguageGaTest.php @@ -6,29 +6,30 @@ */ /** Tests for MediaWiki languages/classes/LanguageGa.php */ -class LanguageGaTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'ga' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageGaTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'two', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'two', 2 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageGdTest.php b/tests/phpunit/languages/LanguageGdTest.php index 24574bda..0b2612b2 100644 --- a/tests/phpunit/languages/LanguageGdTest.php +++ b/tests/phpunit/languages/LanguageGdTest.php @@ -1,38 +1,53 @@ <?php /** * @author Santhosh Thottingal - * @copyright Copyright © 2012, Santhosh Thottingal + * @copyright Copyright © 2012-2013, Santhosh Thottingal * @file */ /** Tests for MediaWiki languages/classes/LanguageGd.php */ -class LanguageGdTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'gd' ); +class LanguageGdTest extends LanguageClassesTestCase { + /** + * @dataProvider providerPlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function tearDown() { - unset( $this->lang ); + + public static function providerPlural() { + return array( + array( 'other', 0 ), + array( 'one', 1 ), + array( 'two', 2 ), + array( 'one', 11 ), + array( 'two', 12 ), + array( 'few', 3 ), + array( 'few', 19 ), + array( 'other', 200 ), + ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - // The CLDR ticket for this plural forms is not same as mw plural forms. See http://unicode.org/cldr/trac/ticket/2883 - $forms = array( 'Form 1', 'Form 2', 'Form 3', 'Form 4', 'Form 5', 'Form 6' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providerPluralExplicit + * @covers Language::convertPlural + */ + public function testExplicitPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other', '11=Form11', '12=Form12' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { - return array ( - array( 'Form 6', 0 ), - array( 'Form 1', 1 ), - array( 'Form 2', 2 ), - array( 'Form 3', 11 ), - array( 'Form 4', 12 ), - array( 'Form 5', 3 ), - array( 'Form 5', 19 ), - array( 'Form 6', 200 ), + + public static function providerPluralExplicit() { + return array( + array( 'other', 0 ), + array( 'one', 1 ), + array( 'two', 2 ), + array( 'Form11', 11 ), + array( 'Form12', 12 ), + array( 'few', 3 ), + array( 'few', 19 ), + array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageGvTest.php b/tests/phpunit/languages/LanguageGvTest.php index 3d298b9b..fc58022a 100644 --- a/tests/phpunit/languages/LanguageGvTest.php +++ b/tests/phpunit/languages/LanguageGvTest.php @@ -1,39 +1,44 @@ <?php /** + * Test for Manx (Gaelg) language + * * @author Santhosh Thottingal - * @copyright Copyright © 2012, Santhosh Thottingal + * @copyright Copyright © 2013, Santhosh Thottingal * @file */ -/** Tests for MediaWiki languages/classes/LanguageGv.php */ -class LanguageGvTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'gv' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageGvTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - // This is not compatible with CLDR plural rules http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#gv - $forms = array( 'Form 1', 'Form 2', 'Form 3', 'Form 4' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'Form 4', 0 ), - array( 'Form 2', 1 ), - array( 'Form 3', 2 ), - array( 'Form 4', 3 ), - array( 'Form 1', 20 ), - array( 'Form 2', 21 ), - array( 'Form 3', 22 ), - array( 'Form 4', 23 ), - array( 'Form 4', 50 ), + + public static function providePlural() { + return array( + array( 'few', 0 ), + array( 'one', 1 ), + array( 'two', 2 ), + array( 'other', 3 ), + array( 'few', 20 ), + array( 'one', 21 ), + array( 'two', 22 ), + array( 'other', 23 ), + array( 'other', 50 ), + array( 'few', 60 ), + array( 'other', 80 ), + array( 'few', 100 ) ); } - } diff --git a/tests/phpunit/languages/LanguageHeTest.php b/tests/phpunit/languages/LanguageHeTest.php index 7833da71..8edc6ddf 100644 --- a/tests/phpunit/languages/LanguageHeTest.php +++ b/tests/phpunit/languages/LanguageHeTest.php @@ -6,43 +6,127 @@ */ /** Tests for MediaWiki languages/classes/LanguageHe.php */ -class LanguageHeTest extends MediaWikiTestCase { - private $lang; +class LanguageHeTest extends LanguageClassesTestCase { + /** + * The most common usage for the plural forms is two forms, + * for singular and plural. In this case, the second form + * is technically dual, but in practice it's used as plural. + * In some cases, usually with expressions of time, three forms + * are needed - singular, dual and plural. + * CLDR also specifies a fourth form for multiples of 10, + * which is very rare. It also has a mistake, because + * the number 10 itself is supposed to be just plural, + * so currently it's overridden in MediaWiki. + */ - function setUp() { - $this->lang = Language::factory( 'he' ); - } - function tearDown() { - unset( $this->lang ); + // @todo the below test*PluralForms test methods can be refactored + // to use a single test method and data provider.. + + /** + * @dataProvider provideTwoPluralForms + * @covers Language::convertPlural + */ + public function testTwoPluralForms( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPluralDual */ - function testPluralDual( $result, $value ) { + /** + * @dataProvider provideThreePluralForms + * @covers Language::convertPlural + */ + public function testThreePluralForms( $result, $value ) { $forms = array( 'one', 'two', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + /** + * @dataProvider provideFourPluralForms + * @covers Language::convertPlural + */ + public function testFourPluralForms( $result, $value ) { + $forms = array( 'one', 'two', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPluralDual() { - return array ( - array( 'other', 0 ), // Zero -> plural + /** + * @dataProvider provideFourPluralForms + * @covers Language::convertPlural + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function provideTwoPluralForms() { + return array( + array( 'other', 0 ), // Zero - plural array( 'one', 1 ), // Singular - array( 'two', 2 ), // Dual - array( 'other', 3 ), // Plural + array( 'other', 2 ), // No third form provided, use it as plural + array( 'other', 3 ), // Plural - other + array( 'other', 10 ), // No fourth form provided, use it as plural + array( 'other', 20 ), // No fourth form provided, use it as plural ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + public static function provideThreePluralForms() { + return array( + array( 'other', 0 ), // Zero - plural + array( 'one', 1 ), // Singular + array( 'two', 2 ), // Dual + array( 'other', 3 ), // Plural - other + array( 'other', 10 ), // No fourth form provided, use it as plural + array( 'other', 20 ), // No fourth form provided, use it as plural + ); } - function providerPlural() { - return array ( - array( 'other', 0 ), // Zero -> plural + public static function provideFourPluralForms() { + return array( + array( 'other', 0 ), // Zero - plural array( 'one', 1 ), // Singular - array( 'other', 2 ), // Plural, no dual provided - array( 'other', 3 ), // Plural + array( 'two', 2 ), // Dual + array( 'other', 3 ), // Plural - other + array( 'other', 10 ), // 10 is supposed to be plural (other), not "many" + array( 'many', 20 ), // Fourth form provided - rare, but supported by CLDR + ); + } + + /** + * @dataProvider provideGrammar + * @covers Language::convertGrammar + */ + public function testGrammar( $result, $word, $case ) { + $this->assertEquals( $result, $this->getLang()->convertGrammar( $word, $case ) ); + } + + // The comments in the beginning of the line help avoid RTL problems + // with text editors. + public static function provideGrammar() { + return array( + array( + /* result */'וויקיפדיה', + /* word */'ויקיפדיה', + /* case */'תחילית', + ), + array( + /* result */'וולפגנג', + /* word */'וולפגנג', + /* case */'prefixed', + ), + array( + /* result */'קובץ', + /* word */'הקובץ', + /* case */'תחילית', + ), + array( + /* result */'־Wikipedia', + /* word */'Wikipedia', + /* case */'תחילית', + ), + array( + /* result */'־1995', + /* word */'1995', + /* case */'תחילית', + ), ); } } diff --git a/tests/phpunit/languages/LanguageHiTest.php b/tests/phpunit/languages/LanguageHiTest.php index ead9e020..f6d2c9e9 100644 --- a/tests/phpunit/languages/LanguageHiTest.php +++ b/tests/phpunit/languages/LanguageHiTest.php @@ -6,29 +6,30 @@ */ /** Tests for MediaWiki languages/LanguageHi.php */ -class LanguageHiTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Hi' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageHiTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'one', 0 ), array( 'one', 1 ), array( 'other', 2 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHrTest.php b/tests/phpunit/languages/LanguageHrTest.php index 4f1c66bf..644c5255 100644 --- a/tests/phpunit/languages/LanguageHrTest.php +++ b/tests/phpunit/languages/LanguageHrTest.php @@ -6,36 +6,37 @@ */ /** Tests for MediaWiki languages/classes/LanguageHr.php */ -class LanguageHrTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'hr' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageHrTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'many', 0 ), + public static function providePlural() { + return array( + array( 'other', 0 ), array( 'one', 1 ), array( 'few', 2 ), array( 'few', 4 ), - array( 'many', 5 ), - array( 'many', 11 ), - array( 'many', 20 ), + array( 'other', 5 ), + array( 'other', 11 ), + array( 'other', 20 ), array( 'one', 21 ), array( 'few', 24 ), - array( 'many', 25 ), - array( 'many', 200 ), + array( 'other', 25 ), + array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHsbTest.php b/tests/phpunit/languages/LanguageHsbTest.php index 803c7721..f95a43bf 100644 --- a/tests/phpunit/languages/LanguageHsbTest.php +++ b/tests/phpunit/languages/LanguageHsbTest.php @@ -6,24 +6,26 @@ */ /** Tests for MediaWiki languages/classes/LanguageHsb.php */ -class LanguageHsbTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'hsb' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageHsbTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'two', 'few', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'one', 101 ), @@ -36,5 +38,4 @@ class LanguageHsbTest extends MediaWikiTestCase { array( 'other', 555 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHuTest.php b/tests/phpunit/languages/LanguageHuTest.php index adbd37ec..ee9197d7 100644 --- a/tests/phpunit/languages/LanguageHuTest.php +++ b/tests/phpunit/languages/LanguageHuTest.php @@ -6,29 +6,30 @@ */ /** Tests for MediaWiki languages/LanguageHu.php */ -class LanguageHuTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Hu' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageHuTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'other', 2 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHyTest.php b/tests/phpunit/languages/LanguageHyTest.php index 7990bdfc..92e0ef94 100644 --- a/tests/phpunit/languages/LanguageHyTest.php +++ b/tests/phpunit/languages/LanguageHyTest.php @@ -5,30 +5,31 @@ * @file */ -/** Tests for MediaWiki languages/LanguageHy.php */ -class LanguageHyTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'hy' ); - } - function tearDown() { - unset( $this->lang ); +/** Tests for Armenian (Հայերեն) */ +class LanguageHyTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'one', 0 ), array( 'one', 1 ), array( 'other', 2 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageKshTest.php b/tests/phpunit/languages/LanguageKshTest.php index ab889464..568a3780 100644 --- a/tests/phpunit/languages/LanguageKshTest.php +++ b/tests/phpunit/languages/LanguageKshTest.php @@ -6,29 +6,30 @@ */ /** Tests for MediaWiki languages/classes/LanguageKsh.php */ -class LanguageKshTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'ksh' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageKshTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other', 'zero' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other', 'zero' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'zero', 0 ), array( 'one', 1 ), array( 'other', 2 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageLnTest.php b/tests/phpunit/languages/LanguageLnTest.php index 0fd9167e..10b3234f 100644 --- a/tests/phpunit/languages/LanguageLnTest.php +++ b/tests/phpunit/languages/LanguageLnTest.php @@ -6,29 +6,30 @@ */ /** Tests for MediaWiki languages/classes/LanguageLn.php */ -class LanguageLnTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'ln' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageLnTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'one', 0 ), array( 'one', 1 ), array( 'other', 2 ), array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageLtTest.php b/tests/phpunit/languages/LanguageLtTest.php index 0d7c7d3e..30642f62 100644 --- a/tests/phpunit/languages/LanguageLtTest.php +++ b/tests/phpunit/languages/LanguageLtTest.php @@ -6,30 +6,26 @@ */ /** Tests for MediaWiki languages/LanguageLt.php */ -class LanguageLtTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Lt' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageLtTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider provideOneFewOtherCases */ - function testOneFewOtherPlural( $result, $value ) { - $forms = array( 'one', 'few', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); - } - - /** @dataProvider provideOneFewCases */ - function testOneFewPlural( $result, $value ) { - $forms = array( 'one', 'few' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function provideOneFewOtherCases() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'few', 2 ), @@ -43,11 +39,25 @@ class LanguageLtTest extends MediaWikiTestCase { array( 'one', 40001 ), ); } - - function provideOneFewCases() { - return array ( + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testOneFewPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + // This fails for 21, but not sure why. + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return array( array( 'one', 1 ), - array( 'few', 15 ), + array( 'other', 2 ), + array( 'other', 15 ), + array( 'other', 20 ), + array( 'one', 21 ), + array( 'other', 22 ), ); } } diff --git a/tests/phpunit/languages/LanguageLvTest.php b/tests/phpunit/languages/LanguageLvTest.php index 0636da5f..7120cfe3 100644 --- a/tests/phpunit/languages/LanguageLvTest.php +++ b/tests/phpunit/languages/LanguageLvTest.php @@ -5,35 +5,40 @@ * @file */ -/** Tests for MediaWiki languages/classes/LanguageLv.php */ -class LanguageLvTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'lv' ); - } - function tearDown() { - unset( $this->lang ); +/** Tests for Latvian */ +class LanguageLvTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'zero', 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'other', 0 ), #this must be zero form as per CLDR + public static function providePlural() { + return array( + array( 'zero', 0 ), array( 'one', 1 ), - array( 'other', 11 ), + array( 'zero', 11 ), array( 'one', 21 ), - array( 'other', 411 ), + array( 'zero', 411 ), + array( 'other', 2 ), + array( 'other', 9 ), + array( 'zero', 12 ), array( 'other', 12.345 ), - array( 'other', 20 ), + array( 'zero', 20 ), + array( 'other', 22 ), array( 'one', 31 ), - array( 'other', 200 ), + array( 'zero', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageMgTest.php b/tests/phpunit/languages/LanguageMgTest.php index 06b56547..65e8fd7b 100644 --- a/tests/phpunit/languages/LanguageMgTest.php +++ b/tests/phpunit/languages/LanguageMgTest.php @@ -6,24 +6,26 @@ */ /** Tests for MediaWiki languages/classes/LanguageMg.php */ -class LanguageMgTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'mg' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageMgTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePlural() { - return array ( + public static function providePlural() { + return array( array( 'one', 0 ), array( 'one', 1 ), array( 'other', 2 ), @@ -31,5 +33,4 @@ class LanguageMgTest extends MediaWikiTestCase { array( 'other', 123.3434 ), ); } - } diff --git a/tests/phpunit/languages/LanguageMkTest.php b/tests/phpunit/languages/LanguageMkTest.php index cf5ec3d9..ed155263 100644 --- a/tests/phpunit/languages/LanguageMkTest.php +++ b/tests/phpunit/languages/LanguageMkTest.php @@ -5,37 +5,36 @@ * @file */ -/** Tests for MediaWiki languages/classes/LanguageMk.php */ -class LanguageMkTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'mk' ); - } - function tearDown() { - unset( $this->lang ); +/** Tests for македонски/Macedonian */ +class LanguageMkTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), - array( 'other', 11 ), + array( 'one', 11 ), array( 'one', 21 ), - array( 'other', 411 ), + array( 'one', 411 ), array( 'other', 12.345 ), array( 'other', 20 ), array( 'one', 31 ), array( 'other', 200 ), ); } - - } diff --git a/tests/phpunit/languages/LanguageMlTest.php b/tests/phpunit/languages/LanguageMlTest.php index 8c4b0b2f..4fa45ce3 100644 --- a/tests/phpunit/languages/LanguageMlTest.php +++ b/tests/phpunit/languages/LanguageMlTest.php @@ -6,28 +6,23 @@ */ /** Tests for MediaWiki languages/LanguageMl.php */ -class LanguageMlTest extends MediaWikiTestCase { - private $lang; +class LanguageMlTest extends LanguageClassesTestCase { - function setUp() { - $this->lang = Language::factory( 'Ml' ); - } - function tearDown() { - unset( $this->lang ); - } - - /** see bug 29495 */ - /** @dataProvider providerFormatNum*/ - function testFormatNum( $result, $value ) { - $this->assertEquals( $result, $this->lang->formatNum( $value ) ); + /** + * @dataProvider providerFormatNum + * @see bug 29495 + * @covers Language::formatNum + */ + public function testFormatNum( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->formatNum( $value ) ); } - function providerFormatNum() { + public static function providerFormatNum() { return array( - array( '12,34,567', '1234567' ), + array( '12,34,567', '1234567' ), array( '12,345', '12345' ), array( '1', '1' ), - array( '123', '123' ) , + array( '123', '123' ), array( '1,234', '1234' ), array( '12,345.56', '12345.56' ), array( '12,34,56,79,81,23,45,678', '12345679812345678' ), @@ -35,7 +30,7 @@ class LanguageMlTest extends MediaWikiTestCase { array( '-12,00,000', '-1200000' ), array( '-98', '-98' ), array( '-98', -98 ), - array( '-1,23,45,678', -12345678 ), + array( '-1,23,45,678', -12345678 ), array( '', '' ), array( '', null ), ); diff --git a/tests/phpunit/languages/LanguageMoTest.php b/tests/phpunit/languages/LanguageMoTest.php index 533e590f..e0e54ca8 100644 --- a/tests/phpunit/languages/LanguageMoTest.php +++ b/tests/phpunit/languages/LanguageMoTest.php @@ -6,37 +6,39 @@ */ /** Tests for MediaWiki languages/classes/LanguageMo.php */ -class LanguageMoTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'mo' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageMoTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'few', 0 ), - array( 'one', 1 ), - array( 'few', 2 ), - array( 'few', 19 ), + public static function providePlural() { + return array( + array( 'few', 0 ), + array( 'one', 1 ), + array( 'few', 2 ), + array( 'few', 19 ), array( 'other', 20 ), array( 'other', 99 ), array( 'other', 100 ), - array( 'few', 101 ), - array( 'few', 119 ), + array( 'few', 101 ), + array( 'few', 119 ), array( 'other', 120 ), array( 'other', 200 ), - array( 'few', 201 ), - array( 'few', 219 ), + array( 'few', 201 ), + array( 'few', 219 ), array( 'other', 220 ), ); } diff --git a/tests/phpunit/languages/LanguageMtTest.php b/tests/phpunit/languages/LanguageMtTest.php index 421bb388..96d2bc92 100644 --- a/tests/phpunit/languages/LanguageMtTest.php +++ b/tests/phpunit/languages/LanguageMtTest.php @@ -6,67 +6,72 @@ */ /** Tests for MediaWiki languages/classes/LanguageMt.php */ -class LanguageMtTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'mt' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageMtTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPluralAllForms */ - function testPluralAllForms( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPluralAllForms() { - return array ( - array( 'few', 0 ), - array( 'one', 1 ), - array( 'few', 2 ), - array( 'few', 10 ), - array( 'many', 11 ), - array( 'many', 19 ), + public static function providePlural() { + return array( + array( 'few', 0 ), + array( 'one', 1 ), + array( 'few', 2 ), + array( 'few', 10 ), + array( 'many', 11 ), + array( 'many', 19 ), array( 'other', 20 ), array( 'other', 99 ), array( 'other', 100 ), array( 'other', 101 ), - array( 'few', 102 ), - array( 'few', 110 ), - array( 'many', 111 ), - array( 'many', 119 ), + array( 'few', 102 ), + array( 'few', 110 ), + array( 'many', 111 ), + array( 'many', 119 ), array( 'other', 120 ), array( 'other', 201 ), ); } - /** @dataProvider providerPluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPluralTwoForms() { - return array ( - array( 'many', 0 ), - array( 'one', 1 ), - array( 'many', 2 ), - array( 'many', 10 ), - array( 'many', 11 ), - array( 'many', 19 ), - array( 'many', 20 ), - array( 'many', 99 ), - array( 'many', 100 ), - array( 'many', 101 ), - array( 'many', 102 ), - array( 'many', 110 ), - array( 'many', 111 ), - array( 'many', 119 ), - array( 'many', 120 ), - array( 'many', 201 ), + public static function providePluralTwoForms() { + return array( + array( 'other', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), + array( 'other', 10 ), + array( 'other', 11 ), + array( 'other', 19 ), + array( 'other', 20 ), + array( 'other', 99 ), + array( 'other', 100 ), + array( 'other', 101 ), + array( 'other', 102 ), + array( 'other', 110 ), + array( 'other', 111 ), + array( 'other', 119 ), + array( 'other', 120 ), + array( 'other', 201 ), ); } } diff --git a/tests/phpunit/languages/LanguageNlTest.php b/tests/phpunit/languages/LanguageNlTest.php index cf979cd2..26bd691a 100644 --- a/tests/phpunit/languages/LanguageNlTest.php +++ b/tests/phpunit/languages/LanguageNlTest.php @@ -6,23 +6,19 @@ */ /** Tests for MediaWiki languages/LanguageNl.php */ -class LanguageNlTest extends MediaWikiTestCase { - private $lang; +class LanguageNlTest extends LanguageClassesTestCase { - function setUp() { - $this->lang = Language::factory( 'Nl' ); - } - function tearDown() { - unset( $this->lang ); - } - - function testFormatNum() { - $this->assertEquals( '1.234.567', $this->lang->formatNum( '1234567' ) ); - $this->assertEquals( '12.345', $this->lang->formatNum( '12345' ) ); - $this->assertEquals( '1', $this->lang->formatNum( '1' ) ); - $this->assertEquals( '123', $this->lang->formatNum( '123' ) ); - $this->assertEquals( '1.234', $this->lang->formatNum( '1234' ) ); - $this->assertEquals( '12.345,56', $this->lang->formatNum( '12345.56' ) ); - $this->assertEquals( ',1234556', $this->lang->formatNum( '.1234556' ) ); + /** + * @covers Language::formatNum + * @todo split into a test and a dataprovider + */ + public function testFormatNum() { + $this->assertEquals( '1.234.567', $this->getLang()->formatNum( '1234567' ) ); + $this->assertEquals( '12.345', $this->getLang()->formatNum( '12345' ) ); + $this->assertEquals( '1', $this->getLang()->formatNum( '1' ) ); + $this->assertEquals( '123', $this->getLang()->formatNum( '123' ) ); + $this->assertEquals( '1.234', $this->getLang()->formatNum( '1234' ) ); + $this->assertEquals( '12.345,56', $this->getLang()->formatNum( '12345.56' ) ); + $this->assertEquals( ',1234556', $this->getLang()->formatNum( '.1234556' ) ); } } diff --git a/tests/phpunit/languages/LanguageNsoTest.php b/tests/phpunit/languages/LanguageNsoTest.php index ea393628..18efd736 100644 --- a/tests/phpunit/languages/LanguageNsoTest.php +++ b/tests/phpunit/languages/LanguageNsoTest.php @@ -6,27 +6,29 @@ */ /** Tests for MediaWiki languages/classes/LanguageNso.php */ -class LanguageNsoTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'nso' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageNsoTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'one', 0 ), - array( 'one', 1 ), - array( 'many', 2 ), + public static function providePlural() { + return array( + array( 'one', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/LanguagePlTest.php b/tests/phpunit/languages/LanguagePlTest.php index e56d4b77..d180037b 100644 --- a/tests/phpunit/languages/LanguagePlTest.php +++ b/tests/phpunit/languages/LanguagePlTest.php @@ -6,67 +6,72 @@ */ /** Tests for MediaWiki languages/classes/LanguagePl.php */ -class LanguagePlTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'pl' ); - } - function tearDown() { - unset( $this->lang ); +class LanguagePlTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'many' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPluralFourForms */ - function testPluralFourForms( $result, $value ) { - $forms = array( 'one', 'few', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPluralFourForms() { - return array ( - array( 'many', 0 ), - array( 'one', 1 ), - array( 'few', 2 ), - array( 'few', 3 ), - array( 'few', 4 ), - array( 'many', 5 ), - array( 'many', 9 ), - array( 'many', 10 ), - array( 'many', 11 ), - array( 'many', 21 ), - array( 'few', 22 ), - array( 'few', 23 ), - array( 'few', 24 ), - array( 'many', 25 ), - array( 'many', 200 ), - array( 'many', 201 ), + public static function providePlural() { + return array( + array( 'many', 0 ), + array( 'one', 1 ), + array( 'few', 2 ), + array( 'few', 3 ), + array( 'few', 4 ), + array( 'many', 5 ), + array( 'many', 9 ), + array( 'many', 10 ), + array( 'many', 11 ), + array( 'many', 21 ), + array( 'few', 22 ), + array( 'few', 23 ), + array( 'few', 24 ), + array( 'many', 25 ), + array( 'many', 200 ), + array( 'many', 201 ), ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { - return array ( - array( 'many', 0 ), - array( 'one', 1 ), - array( 'many', 2 ), - array( 'many', 3 ), - array( 'many', 4 ), - array( 'many', 5 ), - array( 'many', 9 ), - array( 'many', 10 ), - array( 'many', 11 ), - array( 'many', 21 ), - array( 'many', 22 ), - array( 'many', 23 ), - array( 'many', 24 ), - array( 'many', 25 ), - array( 'many', 200 ), - array( 'many', 201 ), + public static function providePluralTwoForms() { + return array( + array( 'other', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), + array( 'other', 3 ), + array( 'other', 4 ), + array( 'other', 5 ), + array( 'other', 9 ), + array( 'other', 10 ), + array( 'other', 11 ), + array( 'other', 21 ), + array( 'other', 22 ), + array( 'other', 23 ), + array( 'other', 24 ), + array( 'other', 25 ), + array( 'other', 200 ), + array( 'other', 201 ), ); } } diff --git a/tests/phpunit/languages/LanguageRoTest.php b/tests/phpunit/languages/LanguageRoTest.php index 5270f6fe..ae7816bc 100644 --- a/tests/phpunit/languages/LanguageRoTest.php +++ b/tests/phpunit/languages/LanguageRoTest.php @@ -6,37 +6,39 @@ */ /** Tests for MediaWiki languages/classes/LanguageRo.php */ -class LanguageRoTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'ro' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageRoTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'few', 0 ), - array( 'one', 1 ), - array( 'few', 2 ), - array( 'few', 19 ), + public static function providePlural() { + return array( + array( 'few', 0 ), + array( 'one', 1 ), + array( 'few', 2 ), + array( 'few', 19 ), array( 'other', 20 ), array( 'other', 99 ), array( 'other', 100 ), - array( 'few', 101 ), - array( 'few', 119 ), + array( 'few', 101 ), + array( 'few', 119 ), array( 'other', 120 ), array( 'other', 200 ), - array( 'few', 201 ), - array( 'few', 219 ), + array( 'few', 201 ), + array( 'few', 219 ), array( 'other', 220 ), ); } diff --git a/tests/phpunit/languages/LanguageRuTest.php b/tests/phpunit/languages/LanguageRuTest.php index 7a1f193b..e17c7085 100644 --- a/tests/phpunit/languages/LanguageRuTest.php +++ b/tests/phpunit/languages/LanguageRuTest.php @@ -7,48 +7,99 @@ */ /** Tests for MediaWiki languages/classes/LanguageRu.php */ -class LanguageRuTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'ru' ); +class LanguageRuTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function tearDown() { - unset( $this->lang ); + + /** + * Test explicit plural forms - n=FormN forms + * @covers Language::convertPlural + */ + public function testExplicitPlural() { + $forms = array( 'one','many', 'other', '12=dozen' ); + $this->assertEquals( 'dozen', $this->getLang()->convertPlural( 12, $forms ) ); + $forms = array( 'one', 'many', '100=hundred', 'other', '12=dozen' ); + $this->assertEquals( 'hundred', $this->getLang()->convertPlural( 100, $forms ) ); } - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePluralFourForms() { - return array ( + public static function providePlural() { + return array( array( 'one', 1 ), array( 'many', 11 ), array( 'one', 91 ), array( 'one', 121 ), - array( 'few', 2 ), - array( 'few', 3 ), - array( 'few', 4 ), - array( 'few', 334 ), + array( 'other', 2 ), + array( 'other', 3 ), + array( 'other', 4 ), + array( 'other', 334 ), array( 'many', 5 ), array( 'many', 15 ), array( 'many', 120 ), ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( '1=one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { - return array ( + + public static function providePluralTwoForms() { + return array( array( 'one', 1 ), - array( 'several', 11 ), - array( 'several', 91 ), - array( 'several', 121 ), + array( 'other', 11 ), + array( 'other', 91 ), + array( 'other', 121 ), + ); + } + + /** + * @dataProvider providerGrammar + * @covers Language::convertGrammar + */ + public function testGrammar( $result, $word, $case ) { + $this->assertEquals( $result, $this->getLang()->convertGrammar( $word, $case ) ); + } + + public static function providerGrammar() { + return array( + array( + 'Википедии', + 'Википедия', + 'genitive', + ), + array( + 'Викитеки', + 'Викитека', + 'genitive', + ), + array( + 'Викитеке', + 'Викитека', + 'prepositional', + ), + array( + 'Викиданных', + 'Викиданные', + 'prepositional', + ), ); } } diff --git a/tests/phpunit/languages/LanguageSeTest.php b/tests/phpunit/languages/LanguageSeTest.php index 065ec29e..533aa2bc 100644 --- a/tests/phpunit/languages/LanguageSeTest.php +++ b/tests/phpunit/languages/LanguageSeTest.php @@ -6,41 +6,46 @@ */ /** Tests for MediaWiki languages/classes/LanguageSe.php */ -class LanguageSeTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'se' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageSeTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPluralThreeForms */ - function testPluralThreeForms( $result, $value ) { - $forms = array( 'one', 'two', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPluralThreeForms() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), - array( 'one', 1 ), - array( 'two', 2 ), + array( 'one', 1 ), + array( 'two', 2 ), array( 'other', 3 ), ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { - return array ( + public static function providePluralTwoForms() { + return array( array( 'other', 0 ), - array( 'one', 1 ), + array( 'one', 1 ), array( 'other', 2 ), array( 'other', 3 ), ); diff --git a/tests/phpunit/languages/LanguageSgsTest.php b/tests/phpunit/languages/LanguageSgsTest.php index 931c82f0..fa49a4dd 100644 --- a/tests/phpunit/languages/LanguageSgsTest.php +++ b/tests/phpunit/languages/LanguageSgsTest.php @@ -5,51 +5,56 @@ * @file */ -/** Tests for MediaWiki languages/classes/LanguageSgs.php */ -class LanguageSgsTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Sgs' ); - } - function tearDown() { - unset( $this->lang ); +/** Tests for Samogitian */ +class LanguageSgsTest extends LanguageClassesTestCase { + /** + * @dataProvider providePluralAllForms + * @covers Language::convertPlural + */ + public function testPluralAllForms( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providePluralAllForms */ - function testPluralAllForms( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePluralAllForms + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePluralAllForms() { - return array ( - array( 'many', 0 ), - array( 'one', 1 ), - array( 'few', 2 ), + public static function providePluralAllForms() { + return array( + array( 'few', 0 ), + array( 'one', 1 ), + array( 'two', 2 ), array( 'other', 3 ), - array( 'many', 10 ), - array( 'many', 11 ), - array( 'many', 12 ), - array( 'many', 19 ), + array( 'few', 10 ), + array( 'few', 11 ), + array( 'few', 12 ), + array( 'few', 19 ), array( 'other', 20 ), - array( 'many', 100 ), - array( 'one', 101 ), - array( 'many', 111 ), - array( 'many', 112 ), + array( 'few', 100 ), + array( 'one', 101 ), + array( 'few', 111 ), + array( 'few', 112 ), ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { - return array ( + public static function providePluralTwoForms() { + return array( array( 'other', 0 ), - array( 'one', 1 ), + array( 'one', 1 ), array( 'other', 2 ), array( 'other', 3 ), array( 'other', 10 ), @@ -58,7 +63,7 @@ class LanguageSgsTest extends MediaWikiTestCase { array( 'other', 19 ), array( 'other', 20 ), array( 'other', 100 ), - array( 'one', 101 ), + array( 'one', 101 ), array( 'other', 111 ), array( 'other', 112 ), ); diff --git a/tests/phpunit/languages/LanguageShTest.php b/tests/phpunit/languages/LanguageShTest.php index b8169aed..1b390872 100644 --- a/tests/phpunit/languages/LanguageShTest.php +++ b/tests/phpunit/languages/LanguageShTest.php @@ -5,28 +5,38 @@ * @file */ -/** Tests for MediaWiki languages/classes/LanguageSh.php */ -class LanguageShTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'sh' ); - } - function tearDown() { - unset( $this->lang ); +/** Tests for srpskohrvatski / српскохрватски / Serbocroatian */ +class LanguageShTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'many', 0 ), - array( 'one', 1 ), - array( 'many', 2 ), + public static function providePlural() { + return array( + array( 'other', 0 ), + array( 'one', 1 ), + array( 'few', 2 ), + array( 'few', 4 ), + array( 'other', 5 ), + array( 'other', 10 ), + array( 'other', 11 ), + array( 'other', 12 ), + array( 'one', 101 ), + array( 'few', 102 ), + array( 'other', 111 ), ); } } diff --git a/tests/phpunit/languages/LanguageSkTest.php b/tests/phpunit/languages/LanguageSkTest.php index 4cfd840e..cb8a13b8 100644 --- a/tests/phpunit/languages/LanguageSkTest.php +++ b/tests/phpunit/languages/LanguageSkTest.php @@ -7,24 +7,26 @@ */ /** Tests for MediaWiki languages/classes/LanguageSk.php */ -class LanguageSkTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'sk' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageSkTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'few', 2 ), diff --git a/tests/phpunit/languages/LanguageSlTest.php b/tests/phpunit/languages/LanguageSlTest.php index c1f75691..9783dd80 100644 --- a/tests/phpunit/languages/LanguageSlTest.php +++ b/tests/phpunit/languages/LanguageSlTest.php @@ -7,36 +7,38 @@ */ /** Tests for MediaWiki languages/classes/LanguageSl.php */ -class LanguageSlTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'sl' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageSlTest extends LanguageClassesTestCase { + /** + * @dataProvider providerPlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'two', 'few', 'other', 'zero' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providerPlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'zero', 0 ), - array( 'one', 1 ), - array( 'two', 2 ), - array( 'few', 3 ), - array( 'few', 4 ), + public static function providerPlural() { + return array( + array( 'other', 0 ), + array( 'one', 1 ), + array( 'two', 2 ), + array( 'few', 3 ), + array( 'few', 4 ), array( 'other', 5 ), array( 'other', 99 ), array( 'other', 100 ), - array( 'one', 101 ), - array( 'two', 102 ), - array( 'few', 103 ), - array( 'one', 201 ), + array( 'one', 101 ), + array( 'two', 102 ), + array( 'few', 103 ), + array( 'one', 201 ), ); } } diff --git a/tests/phpunit/languages/LanguageSmaTest.php b/tests/phpunit/languages/LanguageSmaTest.php index b7e72e97..95cb333c 100644 --- a/tests/phpunit/languages/LanguageSmaTest.php +++ b/tests/phpunit/languages/LanguageSmaTest.php @@ -6,41 +6,46 @@ */ /** Tests for MediaWiki languages/classes/LanguageSma.php */ -class LanguageSmaTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'sma' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageSmaTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPluralThreeForms */ - function testPluralThreeForms( $result, $value ) { - $forms = array( 'one', 'two', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPluralThreeForms() { - return array ( + public static function providePlural() { + return array( array( 'other', 0 ), - array( 'one', 1 ), - array( 'two', 2 ), + array( 'one', 1 ), + array( 'two', 2 ), array( 'other', 3 ), ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { $forms = array( 'one', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { - return array ( + public static function providePluralTwoForms() { + return array( array( 'other', 0 ), - array( 'one', 1 ), + array( 'one', 1 ), array( 'other', 2 ), array( 'other', 3 ), ); diff --git a/tests/phpunit/languages/LanguageSrTest.php b/tests/phpunit/languages/LanguageSrTest.php index d44ecf8e..d6fedb57 100644 --- a/tests/phpunit/languages/LanguageSrTest.php +++ b/tests/phpunit/languages/LanguageSrTest.php @@ -10,25 +10,18 @@ * @author Antoine Musso <hashar at free dot fr> * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr> * @file + * + * @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.. */ -require_once dirname( __DIR__ ) . '/bootstrap.php'; - /** Tests for MediaWiki languages/LanguageSr.php */ -class LanguageSrTest extends MediaWikiTestCase { - /* Language object. Initialized before each test */ - private $lang; - - function setUp() { - $this->lang = Language::factory( 'sr' ); - } - function tearDown() { - unset( $this->lang ); - } - - ##### TESTS ####################################################### - - function testEasyConversions( ) { +class LanguageSrTest extends LanguageClassesTestCase { + /** + * @covers LanguageConverter::convertTo + */ + public function testEasyConversions() { $this->assertCyrillic( 'шђчћжШЂЧЋЖ', 'Cyrillic guessing characters' @@ -39,7 +32,10 @@ class LanguageSrTest extends MediaWikiTestCase { ); } - function testMixedConversions() { + /** + * @covers LanguageConverter::convertTo + */ + public function testMixedConversions() { $this->assertCyrillic( 'шђчћжШЂЧЋЖ - šđčćž', 'Mostly cyrillic characters' @@ -50,7 +46,10 @@ class LanguageSrTest extends MediaWikiTestCase { ); } - function testSameAmountOfLatinAndCyrillicGetConverted() { + /** + * @covers LanguageConverter::convertTo + */ + public function testSameAmountOfLatinAndCyrillicGetConverted() { $this->assertConverted( '4 latin: šđčć | 4 cyrillic: шђчћ', 'sr-ec' @@ -63,8 +62,9 @@ class LanguageSrTest extends MediaWikiTestCase { /** * @author Nikola Smolenski + * @covers LanguageConverter::convertTo */ - function testConversionToCyrillic() { + public function testConversionToCyrillic() { //A simple convertion of Latin to Cyrillic $this->assertEquals( 'абвг', $this->convertToCyrillic( 'abvg' ) @@ -103,7 +103,10 @@ class LanguageSrTest extends MediaWikiTestCase { ); } - function testConversionToLatin() { + /** + * @covers LanguageConverter::convertTo + */ + public function testConversionToLatin() { //A simple convertion of Latin to Latin $this->assertEquals( 'abcd', $this->convertToLatin( 'abcd' ) @@ -122,38 +125,55 @@ class LanguageSrTest extends MediaWikiTestCase { ); } - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePluralFourForms() { - return array ( + public static function providePlural() { + return array( array( 'one', 1 ), - array( 'many', 11 ), + array( 'other', 11 ), array( 'one', 91 ), array( 'one', 121 ), array( 'few', 2 ), array( 'few', 3 ), array( 'few', 4 ), array( 'few', 334 ), - array( 'many', 5 ), - array( 'many', 15 ), - array( 'many', 120 ), + array( 'other', 5 ), + array( 'other', 15 ), + array( 'other', 120 ), ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { - return array ( + + public static function providePluralTwoForms() { + return array( array( 'one', 1 ), - array( 'several', 11 ), - array( 'several', 91 ), - array( 'several', 121 ), + array( 'other', 11 ), + array( 'other', 4 ), + array( 'one', 91 ), + array( 'one', 121 ), ); } @@ -164,20 +184,21 @@ class LanguageSrTest extends MediaWikiTestCase { * @param $variant string Language variant 'sr-ec' or 'sr-el' * @param $msg string Optional message */ - function assertUnConverted( $text, $variant, $msg = '' ) { + protected function assertUnConverted( $text, $variant, $msg = '' ) { $this->assertEquals( $text, $this->convertTo( $text, $variant ), $msg ); } + /** * Wrapper to verify a text is different once converted to a variant. * @param $text string Text to convert * @param $variant string Language variant 'sr-ec' or 'sr-el' * @param $msg string Optional message */ - function assertConverted( $text, $variant, $msg = '' ) { + protected function assertConverted( $text, $variant, $msg = '' ) { $this->assertNotEquals( $text, $this->convertTo( $text, $variant ), @@ -190,34 +211,36 @@ class LanguageSrTest extends MediaWikiTestCase { * using the cyrillic variant and converted to Latin when using * the Latin variant. */ - function assertCyrillic( $text, $msg = '' ) { + protected function assertCyrillic( $text, $msg = '' ) { $this->assertUnConverted( $text, 'sr-ec', $msg ); $this->assertConverted( $text, 'sr-el', $msg ); } + /** * Verifiy the given Latin text is not converted when using * using the Latin variant and converted to Cyrillic when using * the Cyrillic variant. */ - function assertLatin( $text, $msg = '' ) { + protected function assertLatin( $text, $msg = '' ) { $this->assertUnConverted( $text, 'sr-el', $msg ); $this->assertConverted( $text, 'sr-ec', $msg ); } /** Wrapper for converter::convertTo() method*/ - function convertTo( $text, $variant ) { - return $this - ->lang + protected function convertTo( $text, $variant ) { + return $this->getLang() ->mConverter ->convertTo( $text, $variant ); } - function convertToCyrillic( $text ) { + + protected function convertToCyrillic( $text ) { return $this->convertTo( $text, 'sr-ec' ); } - function convertToLatin( $text ) { + + protected function convertToLatin( $text ) { return $this->convertTo( $text, 'sr-el' ); } } diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index 2fa3e292..78929e23 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -1,23 +1,14 @@ <?php -class LanguageTest extends MediaWikiTestCase { - +class LanguageTest extends LanguageClassesTestCase { /** - * @var Language + * @covers Language::convertDoubleWidth + * @covers Language::normalizeForSearch */ - private $lang; - - function setUp() { - $this->lang = Language::factory( 'en' ); - } - function tearDown() { - unset( $this->lang ); - } - - function testLanguageConvertDoubleWidthToSingleWidth() { + public function testLanguageConvertDoubleWidthToSingleWidth() { $this->assertEquals( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - $this->lang->normalizeForSearch( + $this->getLang()->normalizeForSearch( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ), 'convertDoubleWidth() with the full alphabet and digits' @@ -25,13 +16,14 @@ class LanguageTest extends MediaWikiTestCase { } /** - * @dataProvider provideFormattableTimes + * @dataProvider provideFormattableTimes# + * @covers Language::formatTimePeriod */ - function testFormatTimePeriod( $seconds, $format, $expected, $desc ) { - $this->assertEquals( $expected, $this->lang->formatTimePeriod( $seconds, $format ), $desc ); + public function testFormatTimePeriod( $seconds, $format, $expected, $desc ) { + $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc ); } - function provideFormattableTimes() { + public static function provideFormattableTimes() { return array( array( 9.45, @@ -214,56 +206,59 @@ class LanguageTest extends MediaWikiTestCase { 'formatTimePeriod() rounding, recursion, (>48h)' ), ); - } - function testTruncate() { + /** + * @covers Language::truncate + */ + public function testTruncate() { $this->assertEquals( "XXX", - $this->lang->truncate( "1234567890", 0, 'XXX' ), + $this->getLang()->truncate( "1234567890", 0, 'XXX' ), 'truncate prefix, len 0, small ellipsis' ); $this->assertEquals( "12345XXX", - $this->lang->truncate( "1234567890", 8, 'XXX' ), + $this->getLang()->truncate( "1234567890", 8, 'XXX' ), 'truncate prefix, small ellipsis' ); $this->assertEquals( "123456789", - $this->lang->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ), + $this->getLang()->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ), 'truncate prefix, large ellipsis' ); $this->assertEquals( "XXX67890", - $this->lang->truncate( "1234567890", -8, 'XXX' ), + $this->getLang()->truncate( "1234567890", -8, 'XXX' ), 'truncate suffix, small ellipsis' ); $this->assertEquals( "123456789", - $this->lang->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ), + $this->getLang()->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ), 'truncate suffix, large ellipsis' ); } /** - * @dataProvider provideHTMLTruncateData() + * @dataProvider provideHTMLTruncateData + * @covers Language::truncateHTML */ - function testTruncateHtml( $len, $ellipsis, $input, $expected ) { + public function testTruncateHtml( $len, $ellipsis, $input, $expected ) { // Actual HTML... $this->assertEquals( $expected, - $this->lang->truncateHTML( $input, $len, $ellipsis ) + $this->getLang()->truncateHTML( $input, $len, $ellipsis ) ); } /** - * Array format is ($len, $ellipsis, $input, $expected) + * @return array format is ($len, $ellipsis, $input, $expected) */ - function provideHTMLTruncateData() { + public static function provideHTMLTruncateData() { return array( array( 0, 'XXX', "1234567890", "XXX" ), array( 8, 'XXX', "1234567890", "12345XXX" ), @@ -320,29 +315,148 @@ class LanguageTest extends MediaWikiTestCase { } /** + * Test Language::isWellFormedLanguageTag() + * @dataProvider provideWellFormedLanguageTags + * @covers Language::isWellFormedLanguageTag + */ + public function testWellFormedLanguageTag( $code, $message = '' ) { + $this->assertTrue( + Language::isWellFormedLanguageTag( $code ), + "validating code $code $message" + ); + } + + /** + * The test cases are based on the tests in the GaBuZoMeu parser + * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr> + * and distributed as free software, under the GNU General Public Licence. + * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html + */ + public static function provideWellFormedLanguageTags() { + return array( + array( 'fr', 'two-letter code' ), + array( 'fr-latn', 'two-letter code with lower case script code' ), + array( 'fr-Latn-FR', 'two-letter code with title case script code and uppercase country code' ), + array( 'fr-Latn-419', 'two-letter code with title case script code and region number' ), + array( 'fr-FR', 'two-letter code with uppercase' ), + array( 'ax-TZ', 'Not in the registry, but well-formed' ), + array( 'fr-shadok', 'two-letter code with variant' ), + array( 'fr-y-myext-myext2', 'non-x singleton' ), + array( 'fra-Latn', 'ISO 639 can be 3-letters' ), + array( 'fra', 'three-letter language code' ), + array( 'fra-FX', 'three-letter language code with country code' ), + array( 'i-klingon', 'grandfathered with singleton' ), + array( 'I-kLINgon', 'tags are case-insensitive...' ), + array( 'no-bok', 'grandfathered without singleton' ), + array( 'i-enochian', 'Grandfathered' ), + array( 'x-fr-CH', 'private use' ), + array( 'es-419', 'two-letter code with region number' ), + array( 'en-Latn-GB-boont-r-extended-sequence-x-private', 'weird, but well-formed' ), + array( 'ab-x-abc-x-abc', 'anything goes after x' ), + array( 'ab-x-abc-a-a', 'anything goes after x, including several non-x singletons' ), + array( 'i-default', 'grandfathered' ), + array( 'abcd-Latn', 'Language of 4 chars reserved for future use' ), + array( 'AaBbCcDd-x-y-any-x', 'Language of 5-8 chars, registered' ), + array( 'de-CH-1901', 'with country and year' ), + array( 'en-US-x-twain', 'with country and singleton' ), + array( 'zh-cmn', 'three-letter variant' ), + array( 'zh-cmn-Hant', 'three-letter variant and script' ), + array( 'zh-cmn-Hant-HK', 'three-letter variant, script and country' ), + array( 'xr-p-lze', 'Extension' ), + ); + } + + /** + * Negative test for Language::isWellFormedLanguageTag() + * @dataProvider provideMalformedLanguageTags + * @covers Language::isWellFormedLanguageTag + */ + public function testMalformedLanguageTag( $code, $message = '' ) { + $this->assertFalse( + Language::isWellFormedLanguageTag( $code ), + "validating that code $code is a malformed language tag - $message" + ); + } + + /** + * The test cases are based on the tests in the GaBuZoMeu parser + * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr> + * and distributed as free software, under the GNU General Public Licence. + * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html + */ + public static function provideMalformedLanguageTags() { + return array( + array( 'f', 'language too short' ), + array( 'f-Latn', 'language too short with script' ), + array( 'xr-lxs-qut', 'variants too short' ), # extlangS + array( 'fr-Latn-F', 'region too short' ), + array( 'a-value', 'language too short with region' ), + array( 'tlh-a-b-foo', 'valid three-letter with wrong variant' ), + array( 'i-notexist', 'grandfathered but not registered: invalid, even if we only test well-formedness' ), + array( 'abcdefghi-012345678', 'numbers too long' ), + array( 'ab-abc-abc-abc-abc', 'invalid extensions' ), + array( 'ab-abcd-abc', 'invalid extensions' ), + array( 'ab-ab-abc', 'invalid extensions' ), + array( 'ab-123-abc', 'invalid extensions' ), + array( 'a-Hant-ZH', 'short language with valid extensions' ), + array( 'a1-Hant-ZH', 'invalid character in language' ), + array( 'ab-abcde-abc', 'invalid extensions' ), + array( 'ab-1abc-abc', 'invalid characters in extensions' ), + array( 'ab-ab-abcd', 'invalid order of extensions' ), + array( 'ab-123-abcd', 'invalid order of extensions' ), + array( 'ab-abcde-abcd', 'invalid extensions' ), + array( 'ab-1abc-abcd', 'invalid characters in extensions' ), + array( 'ab-a-b', 'extensions too short' ), + array( 'ab-a-x', 'extensions too short, even with singleton' ), + array( 'ab--ab', 'two separators' ), + array( 'ab-abc-', 'separator in the end' ), + array( '-ab-abc', 'separator in the beginning' ), + array( 'abcd-efg', 'language too long' ), + array( 'aabbccddE', 'tag too long' ), + array( 'pa_guru', 'A tag with underscore is invalid in strict mode' ), + array( 'de-f', 'subtag too short' ), + ); + } + + /** + * Negative test for Language::isWellFormedLanguageTag() + * @covers Language::isWellFormedLanguageTag + */ + public function testLenientLanguageTag() { + $this->assertTrue( + Language::isWellFormedLanguageTag( 'pa_guru', true ), + 'pa_guru is a well-formed language tag in lenient mode' + ); + } + + /** * Test Language::isValidBuiltInCode() * @dataProvider provideLanguageCodes + * @covers Language::isValidBuiltInCode */ - function testBuiltInCodeValidation( $code, $message = '' ) { + public function testBuiltInCodeValidation( $code, $message = '' ) { $this->assertTrue( - (bool) Language::isValidBuiltInCode( $code ), + (bool)Language::isValidBuiltInCode( $code ), "validating code $code $message" ); } - function testBuiltInCodeValidationRejectUnderscore() { + /** + * @covers Language::isValidBuiltInCode + */ + public function testBuiltInCodeValidationRejectUnderscore() { $this->assertFalse( - (bool) Language::isValidBuiltInCode( 'be_tarask' ), + (bool)Language::isValidBuiltInCode( 'be_tarask' ), "reject underscore in language code" ); } - function provideLanguageCodes() { + public static function provideLanguageCodes() { return array( - array( 'fr' , 'Two letters, minor case' ), - array( 'EN' , 'Two letters, upper case' ), - array( 'tyv' , 'Three letters' ), - array( 'tokipona' , 'long language code' ), + array( 'fr', 'Two letters, minor case' ), + array( 'EN', 'Two letters, upper case' ), + array( 'tyv', 'Three letters' ), + array( 'tokipona', 'long language code' ), array( 'be-tarask', 'With dash' ), array( 'Zh-classical', 'Begin with upper case, dash' ), array( 'Be-x-old', 'With extension (two dashes)' ), @@ -350,20 +464,103 @@ class LanguageTest extends MediaWikiTestCase { } /** + * Test Language::isKnownLanguageTag() + * @dataProvider provideKnownLanguageTags + * @covers Language::isKnownLanguageTag + */ + public function testKnownLanguageTag( $code, $message = '' ) { + $this->assertTrue( + (bool)Language::isKnownLanguageTag( $code ), + "validating code $code - $message" + ); + } + + public static function provideKnownLanguageTags() { + return array( + array( 'fr', 'simple code' ), + array( 'bat-smg', 'an MW legacy tag' ), + array( 'sgs', 'an internal standard MW name, for which a legacy tag is used externally' ), + ); + } + + /** + * @covers Language::isKnownLanguageTag + */ + public function testKnownCldrLanguageTag() { + if ( !class_exists( 'LanguageNames' ) ) { + $this->markTestSkipped( 'The LanguageNames class is not available. The cldr extension is probably not installed.' ); + } + + $this->assertTrue( + (bool)Language::isKnownLanguageTag( 'pal' ), + 'validating code "pal" an ancient language, which probably will not appear in Names.php, but appears in CLDR in English' + ); + } + + /** + * Negative tests for Language::isKnownLanguageTag() + * @dataProvider provideUnKnownLanguageTags + * @covers Language::isKnownLanguageTag + */ + public function testUnknownLanguageTag( $code, $message = '' ) { + $this->assertFalse( + (bool)Language::isKnownLanguageTag( $code ), + "checking that code $code is invalid - $message" + ); + } + + public static function provideUnknownLanguageTags() { + return array( + array( 'mw', 'non-existent two-letter code' ), + array( 'foo"<bar', 'very invalid language code' ), + ); + } + + /** + * Test too short timestamp + * @expectedException MWException + * @covers Language::sprintfDate + */ + public function testSprintfDateTooShortTimestamp() { + $this->getLang()->sprintfDate( 'xiY', '1234567890123' ); + } + + /** + * Test too long timestamp + * @expectedException MWException + * @covers Language::sprintfDate + */ + public function testSprintfDateTooLongTimestamp() { + $this->getLang()->sprintfDate( 'xiY', '123456789012345' ); + } + + /** + * Test too short timestamp + * @expectedException MWException + * @covers Language::sprintfDate + */ + public function testSprintfDateNotAllDigitTimestamp() { + $this->getLang()->sprintfDate( 'xiY', '-1234567890123' ); + } + + /** * @dataProvider provideSprintfDateSamples + * @covers Language::sprintfDate */ - function testSprintfDate( $format, $ts, $expected, $msg ) { + public function testSprintfDate( $format, $ts, $expected, $msg ) { $this->assertEquals( $expected, - $this->lang->sprintfDate( $format, $ts ), + $this->getLang()->sprintfDate( $format, $ts ), "sprintfDate('$format', '$ts'): $msg" ); } + /** - * bug 33454. sprintfDate should always use UTC. + * sprintfDate should always use UTC when no zone is given. * @dataProvider provideSprintfDateSamples + * @covers Language::sprintfDate */ - function testSprintfDateTZ( $format, $ts, $expected, $msg ) { + public function testSprintfDateNoZone( $format, $ts, $expected, $ignore, $msg ) { $oldTZ = date_default_timezone_get(); $res = date_default_timezone_set( 'Asia/Seoul' ); if ( !$res ) { @@ -372,49 +569,73 @@ class LanguageTest extends MediaWikiTestCase { $this->assertEquals( $expected, - $this->lang->sprintfDate( $format, $ts ), + $this->getLang()->sprintfDate( $format, $ts ), "sprintfDate('$format', '$ts'): $msg" ); date_default_timezone_set( $oldTZ ); } - function provideSprintfDateSamples() { + /** + * sprintfDate should use passed timezone + * @dataProvider provideSprintfDateSamples + * @covers Language::sprintfDate + */ + public function testSprintfDateTZ( $format, $ts, $ignore, $expected, $msg ) { + $tz = new DateTimeZone( 'Asia/Seoul' ); + if ( !$tz ) { + $this->markTestSkipped( "Error getting Timezone" ); + } + + $this->assertEquals( + $expected, + $this->getLang()->sprintfDate( $format, $ts, $tz ), + "sprintfDate('$format', '$ts', 'Asia/Seoul'): $msg" + ); + } + + public static function provideSprintfDateSamples() { return array( array( 'xiY', '20111212000000', '1390', // note because we're testing English locale we get Latin-standard digits + '1390', 'Iranian calendar full year' ), array( 'xiy', '20111212000000', '90', + '90', 'Iranian calendar short year' ), array( 'o', '20120101235000', '2011', + '2011', 'ISO 8601 (week) year' ), array( 'W', '20120101235000', '52', + '52', 'Week number' ), array( 'W', '20120102235000', '1', + '1', 'Week number' ), array( 'o-\\WW-N', '20091231235000', '2009-W53-4', + '2009-W53-4', 'leap week' ), // What follows is mostly copied from http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time @@ -422,252 +643,336 @@ class LanguageTest extends MediaWikiTestCase { 'Y', '20120102090705', '2012', + '2012', 'Full year' ), array( 'y', '20120102090705', '12', + '12', '2 digit year' ), array( 'L', '20120102090705', '1', + '1', 'Leap year' ), array( 'n', '20120102090705', '1', + '1', 'Month index, not zero pad' ), array( 'N', '20120102090705', '01', + '01', 'Month index. Zero pad' ), array( 'M', '20120102090705', 'Jan', + 'Jan', 'Month abbrev' ), array( 'F', '20120102090705', 'January', + 'January', 'Full month' ), array( 'xg', '20120102090705', 'January', + 'January', 'Genitive month name (same in EN)' ), array( 'j', '20120102090705', '2', + '2', 'Day of month (not zero pad)' ), array( 'd', '20120102090705', '02', + '02', 'Day of month (zero-pad)' ), array( 'z', '20120102090705', '1', + '1', 'Day of year (zero-indexed)' ), array( 'D', '20120102090705', 'Mon', + 'Mon', 'Day of week (abbrev)' ), array( 'l', '20120102090705', 'Monday', + 'Monday', 'Full day of week' ), array( 'N', '20120101090705', '7', + '7', 'Day of week (Mon=1, Sun=7)' ), array( 'w', '20120101090705', '0', + '0', 'Day of week (Sun=0, Sat=6)' ), array( 'N', '20120102090705', '1', + '1', 'Day of week' ), array( 'a', '20120102090705', 'am', + 'am', 'am vs pm' ), array( 'A', '20120102120000', 'PM', + 'PM', 'AM vs PM' ), array( 'a', '20120102000000', 'am', + 'am', 'AM vs PM' ), array( 'g', '20120102090705', '9', + '9', '12 hour, not Zero' ), array( 'h', '20120102090705', '09', + '09', '12 hour, zero padded' ), array( 'G', '20120102090705', '9', + '9', '24 hour, not zero' ), array( 'H', '20120102090705', '09', + '09', '24 hour, zero' ), array( 'H', '20120102110705', '11', + '11', '24 hour, zero' ), array( 'i', '20120102090705', '07', + '07', 'Minutes' ), array( 's', '20120102090705', '05', + '05', 'seconds' ), array( 'U', '20120102090705', '1325495225', + '1325462825', 'unix time' ), array( 't', '20120102090705', '31', + '31', 'Days in current month' ), array( 'c', '20120102090705', '2012-01-02T09:07:05+00:00', + '2012-01-02T09:07:05+09:00', 'ISO 8601 timestamp' ), array( 'r', '20120102090705', 'Mon, 02 Jan 2012 09:07:05 +0000', + 'Mon, 02 Jan 2012 09:07:05 +0900', 'RFC 5322' ), array( + 'e', + '20120102090705', + 'UTC', + 'Asia/Seoul', + 'Timezone identifier' + ), + array( + 'I', + '19880602090705', + '0', + '1', + 'DST indicator' + ), + array( + 'O', + '20120102090705', + '+0000', + '+0900', + 'Timezone offset' + ), + array( + 'P', + '20120102090705', + '+00:00', + '+09:00', + 'Timezone offset with colon' + ), + array( + 'T', + '20120102090705', + 'UTC', + 'KST', + 'Timezone abbreviation' + ), + array( + 'Z', + '20120102090705', + '0', + '32400', + 'Timezone offset in seconds' + ), + array( 'xmj xmF xmn xmY', '20120102090705', '7 Safar 2 1433', + '7 Safar 2 1433', 'Islamic' ), array( 'xij xiF xin xiY', '20120102090705', '12 Dey 10 1390', + '12 Dey 10 1390', 'Iranian' ), array( 'xjj xjF xjn xjY', '20120102090705', '7 Tevet 4 5772', + '7 Tevet 4 5772', 'Hebrew' ), array( 'xjt', '20120102090705', '29', + '29', 'Hebrew number of days in month' ), array( 'xjx', '20120102090705', 'Tevet', + 'Tevet', 'Hebrew genitive month name (No difference in EN)' ), array( 'xkY', '20120102090705', '2555', + '2555', 'Thai year' ), array( 'xoY', '20120102090705', '101', + '101', 'Minguo' ), array( 'xtY', '20120102090705', '平成24', + '平成24', 'nengo' ), array( 'xrxkYY', '20120102090705', 'MMDLV2012', + 'MMDLV2012', 'Roman numerals' ), array( 'xhxjYY', '20120102090705', 'ה\'תשע"ב2012', + 'ה\'תשע"ב2012', 'Hebrew numberals' ), array( 'xnY', '20120102090705', '2012', + '2012', 'Raw numerals (doesn\'t mean much in EN)' ), array( '[[Y "(yea"\\r)]] \\"xx\\"', '20120102090705', '[[2012 (year)]] "x"', + '[[2012 (year)]] "x"', 'Various escaping' ), @@ -676,16 +981,17 @@ class LanguageTest extends MediaWikiTestCase { /** * @dataProvider provideFormatSizes + * @covers Language::formatSize */ - function testFormatSize( $size, $expected, $msg ) { + public function testFormatSize( $size, $expected, $msg ) { $this->assertEquals( $expected, - $this->lang->formatSize( $size ), + $this->getLang()->formatSize( $size ), "formatSize('$size'): $msg" ); } - function provideFormatSizes() { + public static function provideFormatSizes() { return array( array( 0, @@ -738,16 +1044,17 @@ class LanguageTest extends MediaWikiTestCase { /** * @dataProvider provideFormatBitrate + * @covers Language::formatBitrate */ - function testFormatBitrate( $bps, $expected, $msg ) { + public function testFormatBitrate( $bps, $expected, $msg ) { $this->assertEquals( $expected, - $this->lang->formatBitrate( $bps ), + $this->getLang()->formatBitrate( $bps ), "formatBitrate('$bps'): $msg" ); } - function provideFormatBitrate() { + public static function provideFormatBitrate() { return array( array( 0, @@ -808,19 +1115,19 @@ class LanguageTest extends MediaWikiTestCase { } - /** * @dataProvider provideFormatDuration + * @covers Language::formatDuration */ - function testFormatDuration( $duration, $expected, $intervals = array() ) { + public function testFormatDuration( $duration, $expected, $intervals = array() ) { $this->assertEquals( $expected, - $this->lang->formatDuration( $duration, $intervals ), + $this->getLang()->formatDuration( $duration, $intervals ), "formatDuration('$duration'): $expected" ); } - function provideFormatDuration() { + public static function provideFormatDuration() { return array( array( 0, @@ -859,35 +1166,36 @@ class LanguageTest extends MediaWikiTestCase { '2 days', ), array( - 365.25 * 86400, // 365.25 * 86400 = 31557600 + // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952 + ( 365 + ( 24 * 3 + 25 ) / 400.0 ) * 86400, '1 year', ), array( - 2 * 31557600, + 2 * 31556952, '2 years', ), array( - 10 * 31557600, + 10 * 31556952, '1 decade', ), array( - 20 * 31557600, + 20 * 31556952, '2 decades', ), array( - 100 * 31557600, + 100 * 31556952, '1 century', ), array( - 200 * 31557600, + 200 * 31556952, '2 centuries', ), array( - 1000 * 31557600, + 1000 * 31556952, '1 millennium', ), array( - 2000 * 31557600, + 2000 * 31556952, '2 millennia', ), array( @@ -899,11 +1207,11 @@ class LanguageTest extends MediaWikiTestCase { '1 hour and 1 second' ), array( - 31557600 + 2 * 86400 + 9000, + 31556952 + 2 * 86400 + 9000, '1 year, 2 days, 2 hours and 30 minutes' ), array( - 42 * 1000 * 31557600 + 42, + 42 * 1000 * 31556952 + 42, '42 millennia and 42 seconds' ), array( @@ -922,7 +1230,7 @@ class LanguageTest extends MediaWikiTestCase { array( 'seconds' ), ), array( - 31557600 + 2 * 86400 + 9000, + 31556952 + 2 * 86400 + 9000, '1 year, 2 days and 150 minutes', array( 'years', 'days', 'minutes' ), ), @@ -932,7 +1240,7 @@ class LanguageTest extends MediaWikiTestCase { array( 'years', 'days' ), ), array( - 31557600 + 2 * 86400 + 9000, + 31556952 + 2 * 86400 + 9000, '1 year, 2 days and 150 minutes', array( 'minutes', 'days', 'years' ), ), @@ -946,17 +1254,18 @@ class LanguageTest extends MediaWikiTestCase { /** * @dataProvider provideCheckTitleEncodingData + * @covers Language::checkTitleEncoding */ - function testCheckTitleEncoding( $s ) { + public function testCheckTitleEncoding( $s ) { $this->assertEquals( $s, - $this->lang->checkTitleEncoding($s), + $this->getLang()->checkTitleEncoding( $s ), "checkTitleEncoding('$s')" ); } - function provideCheckTitleEncodingData() { - return array ( + public static function provideCheckTitleEncodingData() { + return array( array( "" ), array( "United States of America" ), // 7bit ASCII array( rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ), @@ -1010,8 +1319,9 @@ class LanguageTest extends MediaWikiTestCase { /** * @dataProvider provideRomanNumeralsData + * @covers Language::romanNumeral */ - function testRomanNumerals( $num, $numerals ) { + public function testRomanNumerals( $num, $numerals ) { $this->assertEquals( $numerals, Language::romanNumeral( $num ), @@ -1019,7 +1329,7 @@ class LanguageTest extends MediaWikiTestCase { ); } - function provideRomanNumeralsData() { + public static function provideRomanNumeralsData() { return array( array( 1, 'I' ), array( 2, 'II' ), @@ -1061,9 +1371,197 @@ class LanguageTest extends MediaWikiTestCase { array( 7000, 'MMMMMMM' ), array( 8000, 'MMMMMMMM' ), array( 9000, 'MMMMMMMMM' ), - array( 9999, 'MMMMMMMMMCMXCIX'), + array( 9999, 'MMMMMMMMMCMXCIX' ), array( 10000, 'MMMMMMMMMM' ), ); } -} + /** + * @dataProvider providePluralData + * @covers Language::convertPlural + */ + public function testConvertPlural( $expected, $number, $forms ) { + $chosen = $this->getLang()->convertPlural( $number, $forms ); + $this->assertEquals( $expected, $chosen ); + } + + public static function providePluralData() { + // Params are: [expected text, number given, [the plural forms]] + return array( + array( 'plural', 0, array( + 'singular', 'plural' + ) ), + array( 'explicit zero', 0, array( + '0=explicit zero', 'singular', 'plural' + ) ), + array( 'explicit one', 1, array( + 'singular', 'plural', '1=explicit one', + ) ), + array( 'singular', 1, array( + 'singular', 'plural', '0=explicit zero', + ) ), + array( 'plural', 3, array( + '0=explicit zero', '1=explicit one', 'singular', 'plural' + ) ), + array( 'explicit eleven', 11, array( + 'singular', 'plural', '11=explicit eleven', + ) ), + array( 'plural', 12, array( + 'singular', 'plural', '11=explicit twelve', + ) ), + array( 'plural', 12, array( + 'singular', 'plural', '=explicit form', + ) ), + array( 'other', 2, array( + 'kissa=kala', '1=2=3', 'other', + ) ), + array( '', 2, array( + '0=explicit zero', '1=explicit one', + ) ), + ); + } + + /** + * @covers Language::translateBlockExpiry() + * @dataProvider provideTranslateBlockExpiry + */ + public function testTranslateBlockExpiry( $expectedData, $str, $desc ) { + $lang = $this->getLang(); + if ( is_array( $expectedData ) ) { + list( $func, $arg ) = $expectedData; + $expected = $lang->$func( $arg ); + } else { + $expected = $expectedData; + } + $this->assertEquals( $expected, $lang->translateBlockExpiry( $str ), $desc ); + } + + public static function provideTranslateBlockExpiry() { + return array( + array( '2 hours', '2 hours', 'simple data from ipboptions' ), + array( 'indefinite', 'infinite', 'infinite from ipboptions' ), + array( 'indefinite', 'infinity', 'alternative infinite from ipboptions' ), + array( 'indefinite', 'indefinite', 'another alternative infinite from ipboptions' ), + array( array( 'formatDuration', 1023 * 60 * 60 ), '1023 hours', 'relative' ), + array( array( 'formatDuration', -1023 ), '-1023 seconds', 'negative relative' ), + array( array( 'formatDuration', 0 ), 'now', 'now' ), + array( array( 'timeanddate', '20120102070000' ), '2012-1-1 7:00 +1 day', 'mixed, handled as absolute' ), + array( array( 'timeanddate', '19910203040506' ), '1991-2-3 4:05:06', 'absolute' ), + array( array( 'timeanddate', '19700101000000' ), '1970-1-1 0:00:00', 'absolute at epoch' ), + array( array( 'timeanddate', '19691231235959' ), '1969-12-31 23:59:59', 'time before epoch' ), + array( 'dummy', 'dummy', 'return garbage as is' ), + ); + } + + /** + * @covers Language::commafy() + * @dataProvider provideCommafyData + */ + public function testCommafy( $number, $numbersWithCommas ) { + $this->assertEquals( + $numbersWithCommas, + $this->getLang()->commafy( $number ), + "commafy('$number')" + ); + } + + public static function provideCommafyData() { + return array( + array( 1, '1' ), + array( 10, '10' ), + array( 100, '100' ), + array( 1000, '1,000' ), + array( 10000, '10,000' ), + array( 100000, '100,000' ), + array( 1000000, '1,000,000' ), + array( 1.0001, '1.0001' ), + array( 10.0001, '10.0001' ), + array( 100.0001, '100.0001' ), + array( 1000.0001, '1,000.0001' ), + array( 10000.0001, '10,000.0001' ), + array( 100000.0001, '100,000.0001' ), + array( 1000000.0001, '1,000,000.0001' ), + ); + } + + /** + * @covers Language::listToText + */ + public function testListToText() { + $lang = $this->getLang(); + $and = $lang->getMessageFromDB( 'and' ); + $s = $lang->getMessageFromDB( 'word-separator' ); + $c = $lang->getMessageFromDB( 'comma-separator' ); + + $this->assertEquals( '', $lang->listToText( array() ) ); + $this->assertEquals( 'a', $lang->listToText( array( 'a' ) ) ); + $this->assertEquals( "a{$and}{$s}b", $lang->listToText( array( 'a', 'b' ) ) ); + $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( array( 'a', 'b', 'c' ) ) ); + $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( array( 'a', 'b', 'c', 'd' ) ) ); + } + + /** + * @dataProvider provideIsSupportedLanguage + * @covers Language::isSupportedLanguage + */ + public function testIsSupportedLanguage( $code, $expected, $comment ) { + $this->assertEquals( $expected, Language::isSupportedLanguage( $code ), $comment ); + } + + public static function provideIsSupportedLanguage() { + return array( + array( 'en', true, 'is supported language' ), + array( 'fi', true, 'is supported language' ), + array( 'bunny', false, 'is not supported language' ), + array( 'FI', false, 'is not supported language, input should be in lower case' ), + ); + } + + /** + * @dataProvider provideGetParentLanguage + * @covers Language::getParentLanguage + */ + public function testGetParentLanguage( $code, $expected, $comment ) { + $lang = Language::factory( $code ); + if ( is_null( $expected ) ) { + $this->assertNull( $lang->getParentLanguage(), $comment ); + } else { + $this->assertEquals( $expected, $lang->getParentLanguage()->getCode(), $comment ); + } + } + + public static function provideGetParentLanguage() { + return array( + array( 'zh-cn', 'zh', 'zh is the parent language of zh-cn' ), + array( 'zh', 'zh', 'zh is defined as the parent language of zh, because zh converter can convert zh-cn to zh' ), + array( 'zh-invalid', null, 'do not be fooled by arbitrarily composed language codes' ), + array( 'en-gb', null, 'en does not have converter' ), + array( 'en', null, 'en does not have converter. Although FakeConverter handles en -> en conversion but it is useless' ), + ); + } + + /** + * @dataProvider provideGetNamespaceAliases + * @covers Language::getNamespaceAliases + */ + public function testGetNamespaceAliases( $languageCode, $subset ) { + $language = Language::factory( $languageCode ); + $aliases = $language->getNamespaceAliases(); + foreach ( $subset as $alias => $nsId ) { + $this->assertEquals( $nsId, $aliases[$alias] ); + } + } + + public static function provideGetNamespaceAliases() { + // TODO: Add tests for NS_PROJECT_TALK and GenderNamespaces + return array( + array( + 'zh', + array( + '文件' => NS_FILE, + '檔案' => NS_FILE, + ), + ), + ); + } +} diff --git a/tests/phpunit/languages/LanguageTiTest.php b/tests/phpunit/languages/LanguageTiTest.php index 4bfaa009..e225af97 100644 --- a/tests/phpunit/languages/LanguageTiTest.php +++ b/tests/phpunit/languages/LanguageTiTest.php @@ -6,27 +6,29 @@ */ /** Tests for MediaWiki languages/classes/LanguageTi.php */ -class LanguageTiTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Ti' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageTiTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'one', 0 ), - array( 'one', 1 ), - array( 'many', 2 ), + public static function providePlural() { + return array( + array( 'one', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/LanguageTlTest.php b/tests/phpunit/languages/LanguageTlTest.php index a1facd14..7ac51c69 100644 --- a/tests/phpunit/languages/LanguageTlTest.php +++ b/tests/phpunit/languages/LanguageTlTest.php @@ -6,27 +6,29 @@ */ /** Tests for MediaWiki languages/classes/LanguageTl.php */ -class LanguageTlTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Tl' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageTlTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'one', 0 ), - array( 'one', 1 ), - array( 'many', 2 ), + public static function providePlural() { + return array( + array( 'one', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/LanguageTrTest.php b/tests/phpunit/languages/LanguageTrTest.php index bda4c9d9..8fc2795c 100644 --- a/tests/phpunit/languages/LanguageTrTest.php +++ b/tests/phpunit/languages/LanguageTrTest.php @@ -6,15 +6,7 @@ */ /** Tests for MediaWiki languages/LanguageTr.php */ -class LanguageTrTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Tr' ); - } - function tearDown() { - unset( $this->lang ); - } +class LanguageTrTest extends LanguageClassesTestCase { /** * See @bug 28040 @@ -25,11 +17,11 @@ class LanguageTrTest extends MediaWikiTestCase { * @see http://en.wikipedia.org/wiki/Dotted_and_dotless_I * @dataProvider provideDottedAndDotlessI */ - function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) { - if( $func == 'ucfirst' ) { - $res = $this->lang->ucfirst( $input ); - } elseif( $func == 'lcfirst' ) { - $res = $this->lang->lcfirst( $input ); + public function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) { + if ( $func == 'ucfirst' ) { + $res = $this->getLang()->ucfirst( $input ); + } elseif ( $func == 'lcfirst' ) { + $res = $this->getLang()->lcfirst( $input ); } else { throw new MWException( __METHOD__ . " given an invalid function name '$func'" ); } @@ -39,7 +31,7 @@ class LanguageTrTest extends MediaWikiTestCase { $this->assertEquals( $expected, $res, $msg ); } - function provideDottedAndDotlessI() { + public static function provideDottedAndDotlessI() { return array( # function, input, input case, expected # Case changed: @@ -64,5 +56,4 @@ class LanguageTrTest extends MediaWikiTestCase { ); } - } diff --git a/tests/phpunit/languages/LanguageUkTest.php b/tests/phpunit/languages/LanguageUkTest.php index 60fafb0d..9051bcff 100644 --- a/tests/phpunit/languages/LanguageUkTest.php +++ b/tests/phpunit/languages/LanguageUkTest.php @@ -6,25 +6,38 @@ * @file */ -/** Tests for MediaWiki languages/classes/LanguageUk.php */ -class LanguageUkTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Uk' ); +/** Tests for Ukrainian */ +class LanguageUkTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'few', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function tearDown() { - unset( $this->lang ); + + /** + * Test explicit plural forms - n=FormN forms + * @covers Language::convertPlural + */ + public function testExplicitPlural() { + $forms = array( 'one', 'few', 'many', 'other', '12=dozen' ); + $this->assertEquals( 'dozen', $this->getLang()->convertPlural( 12, $forms ) ); + $forms = array( 'one', 'few', 'many', '100=hundred', 'other', '12=dozen' ); + $this->assertEquals( 'hundred', $this->getLang()->convertPlural( 100, $forms ) ); } - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providePluralFourForms() { - return array ( + public static function providePlural() { + return array( array( 'one', 1 ), array( 'many', 11 ), array( 'one', 91 ), @@ -38,17 +51,22 @@ class LanguageUkTest extends MediaWikiTestCase { array( 'many', 120 ), ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( '1=one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { - return array ( + + public static function providePluralTwoForms() { + return array( array( 'one', 1 ), - array( 'several', 11 ), - array( 'several', 91 ), - array( 'several', 121 ), + array( 'other', 11 ), + array( 'other', 91 ), + array( 'other', 121 ), ); } } diff --git a/tests/phpunit/languages/LanguageUzTest.php b/tests/phpunit/languages/LanguageUzTest.php index 72387283..13f57c16 100644 --- a/tests/phpunit/languages/LanguageUzTest.php +++ b/tests/phpunit/languages/LanguageUzTest.php @@ -10,26 +10,20 @@ * @copyright Copyright © 2012, Robin Pepermans * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr> * @file + * + * @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.. */ -require_once dirname( __DIR__ ) . '/bootstrap.php'; - /** Tests for MediaWiki languages/LanguageUz.php */ -class LanguageUzTest extends MediaWikiTestCase { - /* Language object. Initialized before each test */ - private $lang; - - function setUp() { - $this->lang = Language::factory( 'uz' ); - } - function tearDown() { - unset( $this->lang ); - } +class LanguageUzTest extends LanguageClassesTestCase { /** * @author Nikola Smolenski + * @covers LanguageConverter::convertTo */ - function testConversionToCyrillic() { + public function testConversionToCyrillic() { // A convertion of Latin to Cyrillic $this->assertEquals( 'абвгғ', $this->convertToCyrillic( 'abvggʻ' ) @@ -48,7 +42,10 @@ class LanguageUzTest extends MediaWikiTestCase { ); } - function testConversionToLatin() { + /** + * @covers LanguageConverter::convertTo + */ + public function testConversionToLatin() { // A simple convertion of Latin to Latin $this->assertEquals( 'abdef', $this->convertToLatin( 'abdef' ) @@ -66,20 +63,21 @@ class LanguageUzTest extends MediaWikiTestCase { * @param $variant string Language variant 'uz-cyrl' or 'uz-latn' * @param $msg string Optional message */ - function assertUnConverted( $text, $variant, $msg = '' ) { + protected function assertUnConverted( $text, $variant, $msg = '' ) { $this->assertEquals( $text, $this->convertTo( $text, $variant ), $msg ); } + /** * Wrapper to verify a text is different once converted to a variant. * @param $text string Text to convert * @param $variant string Language variant 'uz-cyrl' or 'uz-latn' * @param $msg string Optional message */ - function assertConverted( $text, $variant, $msg = '' ) { + protected function assertConverted( $text, $variant, $msg = '' ) { $this->assertNotEquals( $text, $this->convertTo( $text, $variant ), @@ -92,29 +90,32 @@ class LanguageUzTest extends MediaWikiTestCase { * using the cyrillic variant and converted to Latin when using * the Latin variant. */ - function assertCyrillic( $text, $msg = '' ) { + protected function assertCyrillic( $text, $msg = '' ) { $this->assertUnConverted( $text, 'uz-cyrl', $msg ); $this->assertConverted( $text, 'uz-latn', $msg ); } + /** * Verifiy the given Latin text is not converted when using * using the Latin variant and converted to Cyrillic when using * the Cyrillic variant. */ - function assertLatin( $text, $msg = '' ) { + protected function assertLatin( $text, $msg = '' ) { $this->assertUnConverted( $text, 'uz-latn', $msg ); $this->assertConverted( $text, 'uz-cyrl', $msg ); } /** Wrapper for converter::convertTo() method*/ - function convertTo( $text, $variant ) { - return $this->lang->mConverter->convertTo( $text, $variant ); + protected function convertTo( $text, $variant ) { + return $this->getLang()->mConverter->convertTo( $text, $variant ); } - function convertToCyrillic( $text ) { + + protected function convertToCyrillic( $text ) { return $this->convertTo( $text, 'uz-cyrl' ); } - function convertToLatin( $text ) { + + protected function convertToLatin( $text ) { return $this->convertTo( $text, 'uz-latn' ); } } diff --git a/tests/phpunit/languages/LanguageWaTest.php b/tests/phpunit/languages/LanguageWaTest.php index 172f19b9..d05196c0 100644 --- a/tests/phpunit/languages/LanguageWaTest.php +++ b/tests/phpunit/languages/LanguageWaTest.php @@ -6,27 +6,29 @@ */ /** Tests for MediaWiki languages/classes/LanguageWa.php */ -class LanguageWaTest extends MediaWikiTestCase { - private $lang; - - function setUp() { - $this->lang = Language::factory( 'Wa' ); - } - function tearDown() { - unset( $this->lang ); +class LanguageWaTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); - $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); } - function providerPlural() { - return array ( - array( 'one', 0 ), - array( 'one', 1 ), - array( 'many', 2 ), + public static function providePlural() { + return array( + array( 'one', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php b/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php index 033164b0..bd3809d7 100644 --- a/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php +++ b/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php @@ -9,7 +9,7 @@ class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase { * @dataProvider validTestCases */ function testValidRules( $expected, $rules, $number, $comment ) { - $result = CLDRPluralRuleEvaluator::evaluate( $number, (array) $rules ); + $result = CLDRPluralRuleEvaluator::evaluate( $number, (array)$rules ); $this->assertEquals( $expected, $result, $comment ); } @@ -18,7 +18,7 @@ class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase { * @expectedException CLDRPluralRuleError */ function testInvalidRules( $rules, $comment ) { - CLDRPluralRuleEvaluator::evaluate( 1, (array) $rules ); + CLDRPluralRuleEvaluator::evaluate( 1, (array)$rules ); } function validTestCases() { @@ -31,19 +31,19 @@ class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase { array( 1, 'n is 1', 1.1, 'float number and is' ), array( 1, 'n is 1', 2, 'float number and is' ), - array( 0, 'n in 1,3,5', 3, '' ), + array( 0, 'n in 1,3,5', 3, '' ), array( 1, 'n not in 1,3,5', 5, '' ), - array( 1, 'n in 1,3,5', 2, '' ), + array( 1, 'n in 1,3,5', 2, '' ), array( 0, 'n not in 1,3,5', 4, '' ), - array( 0, 'n in 1..3', 2, '' ), - array( 0, 'n in 1..3', 3, 'in is inclusive' ), - array( 1, 'n in 1..3', 0, '' ), + array( 0, 'n in 1..3', 2, '' ), + array( 0, 'n in 1..3', 3, 'in is inclusive' ), + array( 1, 'n in 1..3', 0, '' ), - array( 1, 'n not in 1..3', 2, '' ), - array( 1, 'n not in 1..3', 3, 'in is inclusive' ), - array( 0, 'n not in 1..3', 0, '' ), + array( 1, 'n not in 1..3', 2, '' ), + array( 1, 'n not in 1..3', 3, 'in is inclusive' ), + array( 0, 'n not in 1..3', 0, '' ), array( 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ), array( 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ), @@ -78,6 +78,56 @@ class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase { array( 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ), array( 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ), + + # Revision 33 new operand examples + # expected, rule, number, comment + array( 0, 'i is 1', '1.00', 'new operand i' ), + array( 0, 'v is 2', '1.00', 'new operand v' ), + array( 0, 'w is 0', '1.00', 'new operand w' ), + array( 0, 'f is 0', '1.00', 'new operand f' ), + array( 0, 't is 0', '1.00', 'new operand t' ), + + array( 0, 'i is 1', '1.30', 'new operand i' ), + array( 0, 'v is 2', '1.30', 'new operand v' ), + array( 0, 'w is 1', '1.30', 'new operand w' ), + array( 0, 'f is 30', '1.30', 'new operand f' ), + array( 0, 't is 3', '1.30', 'new operand t' ), + + array( 0, 'i is 1', '1.03', 'new operand i' ), + array( 0, 'v is 2', '1.03', 'new operand v' ), + array( 0, 'w is 2', '1.03', 'new operand w' ), + array( 0, 'f is 3', '1.03', 'new operand f' ), + array( 0, 't is 3', '1.03', 'new operand t' ), + + # Revision 33 new operator aliases + # expected, rule, number, comment + array( 0, 'n % 3 is 1', 7, 'new % operator' ), + array( 0, 'n = 1,3,5', 3, 'new = operator' ), + array( 1, 'n != 1,3,5', 5, 'new != operator' ), + + # Revision 33 samples + # expected, rule, number, comment + array( 0, 'n in 1,3,5@integer 3~10, 103~110, 1003, … @decimal 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 103.0, 1003.0, …', 3, 'samples' ), + + # Revision 33 some test cases from CLDR + array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.1', 'pt one' ), + array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.01', 'pt one' ), + array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.10', 'pt one' ), + array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.010', 'pt one' ), + array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.100', 'pt one' ), + array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.0', 'pt other' ), + array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.2', 'pt other' ), + array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '10.0', 'pt other' ), + array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '100.0', 'pt other' ), + array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '2', 'bs few' ), + array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '4', 'bs few' ), + array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '22', 'bs few' ), + array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '102', 'bs few' ), + array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.2', 'bs few' ), + array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.4', 'bs few' ), + array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.2', 'bs few' ), + array( 1, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.0', 'bs other' ), + ); return $tests; @@ -89,7 +139,7 @@ class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase { array( 'n', 'just n' ), array( 'n is in 5', 'is in' ), ); + return $tests; } - } |