diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /tests/phpunit/languages | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'tests/phpunit/languages')
50 files changed, 1200 insertions, 475 deletions
diff --git a/tests/phpunit/languages/LanguageAmTest.php b/tests/phpunit/languages/LanguageAmTest.php index 9723e1e3..a644f5e0 100644 --- a/tests/phpunit/languages/LanguageAmTest.php +++ b/tests/phpunit/languages/LanguageAmTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/LanguageAm.php */ class LanguageAmTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @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 ), diff --git a/tests/phpunit/languages/LanguageArTest.php b/tests/phpunit/languages/LanguageArTest.php index 523ee7f6..7b48f236 100644 --- a/tests/phpunit/languages/LanguageArTest.php +++ b/tests/phpunit/languages/LanguageArTest.php @@ -6,8 +6,11 @@ /** Tests for MediaWiki languages/LanguageAr.php */ class LanguageArTest extends LanguageClassesTestCase { - - function testFormatNum() { + /** + * @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 ) ); } @@ -15,12 +18,13 @@ class LanguageArTest extends LanguageClassesTestCase { /** * Mostly to test the raw ascii feature. * @dataProvider providerSprintfDate + * @covers Language::sprintfDate */ - function testSprintfDate( $format, $date, $expected ) { + 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', @@ -45,13 +49,24 @@ class LanguageArTest extends LanguageClassesTestCase { ); } - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @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() { + /** + * @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 ), diff --git a/tests/phpunit/languages/LanguageBeTest.php b/tests/phpunit/languages/LanguageBeTest.php index 0144941b..7bd586af 100644 --- a/tests/phpunit/languages/LanguageBeTest.php +++ b/tests/phpunit/languages/LanguageBeTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/LanguageBe.php */ class LanguageBeTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @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 providePlural() { + /** + * @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 ), diff --git a/tests/phpunit/languages/LanguageBe_taraskTest.php b/tests/phpunit/languages/LanguageBe_taraskTest.php index 5b246d8e..d5822f4a 100644 --- a/tests/phpunit/languages/LanguageBe_taraskTest.php +++ b/tests/phpunit/languages/LanguageBe_taraskTest.php @@ -1,20 +1,22 @@ <?php 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. */ - function testBeTaraskTestsUsesBeTaraskCode() { + 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->getLang()->normalizeForSearch( '’' ), @@ -22,24 +24,41 @@ class LanguageBe_taraskTest extends LanguageClassesTestCase { ); } - /** see bug 23156 & r64981 */ - function testCommafy() { + /** + * @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() { + /** + * @see bug 23156 & r64981 + * @covers Language::commafy + */ + public function testDoesNotCommafyFourDigitsNumber() { $this->assertEquals( '1234', $this->getLang()->commafy( '1234' ) ); } - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { + /** + * @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() { + /** + * @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 ), @@ -55,19 +74,21 @@ class LanguageBe_taraskTest extends LanguageClassesTestCase { ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { + 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/LanguageBhoTest.php b/tests/phpunit/languages/LanguageBhoTest.php index c364917d..187bfbbc 100644 --- a/tests/phpunit/languages/LanguageBhoTest.php +++ b/tests/phpunit/languages/LanguageBhoTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/LanguageBho.php */ class LanguageBhoTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @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 ), @@ -22,5 +32,4 @@ class LanguageBhoTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageBsTest.php b/tests/phpunit/languages/LanguageBsTest.php index 76d00704..fb965b89 100644 --- a/tests/phpunit/languages/LanguageBsTest.php +++ b/tests/phpunit/languages/LanguageBsTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/LanguageBs.php */ class LanguageBsTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @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 providePlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'many', 0 ), array( 'one', 1 ), @@ -29,5 +39,4 @@ class LanguageBsTest extends LanguageClassesTestCase { array( 'many', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageClassesTestCase.php b/tests/phpunit/languages/LanguageClassesTestCase.php index 6659dad1..632e037f 100644 --- a/tests/phpunit/languages/LanguageClassesTestCase.php +++ b/tests/phpunit/languages/LanguageClassesTestCase.php @@ -3,16 +3,7 @@ * Helping class to run tests using a clean language instance. * * This is intended for the MediaWiki language class tests under - * tests/phpunit/languages. You simply need to extends this test - * and set it up with a language code using setUpBeforeClass: - * - * @par Setting up a language: - * @code - * class LanguageFooTest extends LanguageClassesTestCase { - * public static function setUpBeforeClass() { - * self::setLang( 'Foo' ); - * } - * @endcode + * tests/phpunit/languages. * * Before each tests, a new language object is build which you * can retrieve in your test using the $this->getLang() method: @@ -28,19 +19,6 @@ * @endcode */ abstract class LanguageClassesTestCase extends MediaWikiTestCase { - - /** - * Regex used to find out the language code out of the class name - * used by setUpBeforeClass - */ - private static $reExtractLangFromClass = '/Language(.*)Test/'; - - /** - * Hold the language code we are going to use. This is extracted - * directly from the extending class. - */ - private static $LanguageClassCode; - /** * Internal language object * @@ -57,9 +35,19 @@ abstract class LanguageClassesTestCase extends MediaWikiTestCase { */ private $languageObject; - public static function setUpBeforeClass() { - $found = preg_match( self::$reExtractLangFromClass, - get_called_class(), $m ); + /** + * @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] ); @@ -71,21 +59,8 @@ abstract class LanguageClassesTestCase extends MediaWikiTestCase { . "out of " . get_called_class() . " failling back to 'en'\n" ); } - // TODO: validate $m[1] which should be a valid language code - self::$LanguageClassCode = $m[1]; - } - - protected function getLang() { - return $this->languageObject; - } - - /** - * Create a new language object before each test. - */ - protected function setUp() { - parent::setUp(); - $this->languageObject = Language::factory( - self::$LanguageClassCode ); + // @todo validate $m[1] which should be a valid language code + $this->languageObject = Language::factory( $m[1] ); } /** @@ -96,5 +71,4 @@ abstract class LanguageClassesTestCase extends MediaWikiTestCase { unset( $this->languageObject ); parent::tearDown(); } - } diff --git a/tests/phpunit/languages/LanguageCsTest.php b/tests/phpunit/languages/LanguageCsTest.php index 884a129e..da9e6b88 100644 --- a/tests/phpunit/languages/LanguageCsTest.php +++ b/tests/phpunit/languages/LanguageCsTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/Languagecs.php */ class LanguageCsTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -28,5 +38,4 @@ class LanguageCsTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageCuTest.php b/tests/phpunit/languages/LanguageCuTest.php index e2394b35..07193172 100644 --- a/tests/phpunit/languages/LanguageCuTest.php +++ b/tests/phpunit/languages/LanguageCuTest.php @@ -7,27 +7,36 @@ /** Tests for MediaWiki languages/LanguageCu.php */ class LanguageCuTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'few', 'many', 'other' ); + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'two', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + 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 2a7f4a92..eaf663a8 100644 --- a/tests/phpunit/languages/LanguageCyTest.php +++ b/tests/phpunit/languages/LanguageCyTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageCy.php */ class LanguageCyTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @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 providerPlural() { + /** + * @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 ), @@ -30,5 +40,4 @@ class LanguageCyTest extends LanguageClassesTestCase { array( 'other', 200.00 ), ); } - } diff --git a/tests/phpunit/languages/LanguageDsbTest.php b/tests/phpunit/languages/LanguageDsbTest.php index 285ce648..94c11bcc 100644 --- a/tests/phpunit/languages/LanguageDsbTest.php +++ b/tests/phpunit/languages/LanguageDsbTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageDsb.php */ class LanguageDsbTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'two', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -28,5 +38,4 @@ class LanguageDsbTest extends LanguageClassesTestCase { array( 'other', 555 ), ); } - } diff --git a/tests/phpunit/languages/LanguageFrTest.php b/tests/phpunit/languages/LanguageFrTest.php index faf0de58..46b65011 100644 --- a/tests/phpunit/languages/LanguageFrTest.php +++ b/tests/phpunit/languages/LanguageFrTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageFr.php */ class LanguageFrTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @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 ), @@ -22,5 +32,4 @@ class LanguageFrTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageGaTest.php b/tests/phpunit/languages/LanguageGaTest.php index 2dbb088b..c009f56b 100644 --- a/tests/phpunit/languages/LanguageGaTest.php +++ b/tests/phpunit/languages/LanguageGaTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageGa.php */ class LanguageGaTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'two', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -22,5 +32,4 @@ class LanguageGaTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageGdTest.php b/tests/phpunit/languages/LanguageGdTest.php index 5de1e9d2..0b2612b2 100644 --- a/tests/phpunit/languages/LanguageGdTest.php +++ b/tests/phpunit/languages/LanguageGdTest.php @@ -7,15 +7,17 @@ /** Tests for MediaWiki languages/classes/LanguageGd.php */ class LanguageGdTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @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 providerPlural() { - return array ( + public static function providerPlural() { + return array( array( 'other', 0 ), array( 'one', 1 ), array( 'two', 2 ), @@ -27,22 +29,25 @@ class LanguageGdTest extends LanguageClassesTestCase { ); } - /** @dataProvider providerPluralExplicit */ - function testExplicitPlural( $result, $value ) { + /** + * @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 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 ), + 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 4126e071..a0def628 100644 --- a/tests/phpunit/languages/LanguageGvTest.php +++ b/tests/phpunit/languages/LanguageGvTest.php @@ -7,15 +7,27 @@ /** Tests for MediaWiki languages/classes/LanguageGv.php */ class LanguageGvTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public 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 + // What does this mean? Is there a hard-coded override for gv somewhere? -Ryan Kaldari 2013-01-28 $forms = array( 'Form 1', 'Form 2', 'Form 3', 'Form 4' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->markTestSkipped( "This test won't work since convertPlural for gv doesn't seem to actually follow our plural rules." ); + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'Form 4', 0 ), array( 'Form 2', 1 ), @@ -28,5 +40,4 @@ class LanguageGvTest extends LanguageClassesTestCase { array( 'Form 4', 50 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHeTest.php b/tests/phpunit/languages/LanguageHeTest.php index 6de88e59..8edc6ddf 100644 --- a/tests/phpunit/languages/LanguageHeTest.php +++ b/tests/phpunit/languages/LanguageHeTest.php @@ -7,70 +7,125 @@ /** Tests for MediaWiki languages/classes/LanguageHe.php */ 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. + */ - /** @dataProvider providerPluralDual */ - function testPluralDual( $result, $value ) { + // @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 provideThreePluralForms + * @covers Language::convertPlural + */ + public function testThreePluralForms( $result, $value ) { $forms = array( 'one', 'two', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPluralDual() { + /** + * @dataProvider provideFourPluralForms + * @covers Language::convertPlural + */ + public function testFourPluralForms( $result, $value ) { + $forms = array( 'one', 'two', 'many', 'other' ); + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + /** + * @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( '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->getLang()->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() { + public static function provideFourPluralForms() { return array( - array( 'other', 0 ), // Zero -> plural + 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 providerGrammar */ - function testGrammar( $result, $word, $case ) { + /** + * @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. - function providerGrammar() { + public static function provideGrammar() { return array( array( - /* result */ 'וויקיפדיה', - /* word */ 'ויקיפדיה', - /* case */ 'תחילית', + /* result */'וויקיפדיה', + /* word */'ויקיפדיה', + /* case */'תחילית', ), array( - /* result */ 'וולפגנג', - /* word */ 'וולפגנג', - /* case */ 'prefixed', + /* result */'וולפגנג', + /* word */'וולפגנג', + /* case */'prefixed', ), array( - /* result */ 'קובץ', - /* word */ 'הקובץ', - /* case */ 'תחילית', + /* result */'קובץ', + /* word */'הקובץ', + /* case */'תחילית', ), array( - /* result */ '־Wikipedia', - /* word */ 'Wikipedia', - /* case */ 'תחילית', + /* result */'־Wikipedia', + /* word */'Wikipedia', + /* case */'תחילית', ), array( - /* result */ '־1995', - /* word */ '1995', - /* case */ 'תחילית', + /* result */'־1995', + /* word */'1995', + /* case */'תחילית', ), ); } diff --git a/tests/phpunit/languages/LanguageHiTest.php b/tests/phpunit/languages/LanguageHiTest.php index 86d6af58..f6d2c9e9 100644 --- a/tests/phpunit/languages/LanguageHiTest.php +++ b/tests/phpunit/languages/LanguageHiTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/LanguageHi.php */ class LanguageHiTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @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 ), @@ -22,5 +32,4 @@ class LanguageHiTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHrTest.php b/tests/phpunit/languages/LanguageHrTest.php index 9dce4ea7..6ce4aff9 100644 --- a/tests/phpunit/languages/LanguageHrTest.php +++ b/tests/phpunit/languages/LanguageHrTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageHr.php */ class LanguageHrTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @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 providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'many', 0 ), array( 'one', 1 ), @@ -29,5 +39,4 @@ class LanguageHrTest extends LanguageClassesTestCase { array( 'many', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHsbTest.php b/tests/phpunit/languages/LanguageHsbTest.php index bec7d819..f95a43bf 100644 --- a/tests/phpunit/languages/LanguageHsbTest.php +++ b/tests/phpunit/languages/LanguageHsbTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageHsb.php */ class LanguageHsbTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'two', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -28,5 +38,4 @@ class LanguageHsbTest extends LanguageClassesTestCase { array( 'other', 555 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHuTest.php b/tests/phpunit/languages/LanguageHuTest.php index 23d8e0ce..ee9197d7 100644 --- a/tests/phpunit/languages/LanguageHuTest.php +++ b/tests/phpunit/languages/LanguageHuTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/LanguageHu.php */ class LanguageHuTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -22,5 +32,4 @@ class LanguageHuTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageHyTest.php b/tests/phpunit/languages/LanguageHyTest.php index 7088d37b..896522b0 100644 --- a/tests/phpunit/languages/LanguageHyTest.php +++ b/tests/phpunit/languages/LanguageHyTest.php @@ -7,14 +7,25 @@ /** Tests for MediaWiki languages/LanguageHy.php */ class LanguageHyTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + // This fails for 0, but I'm not sure why. Some voodoo going on here. + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -22,5 +33,4 @@ class LanguageHyTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageKshTest.php b/tests/phpunit/languages/LanguageKshTest.php index 9b4a53ad..568a3780 100644 --- a/tests/phpunit/languages/LanguageKshTest.php +++ b/tests/phpunit/languages/LanguageKshTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageKsh.php */ class LanguageKshTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other', 'zero' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @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 ), @@ -22,5 +32,4 @@ class LanguageKshTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageLnTest.php b/tests/phpunit/languages/LanguageLnTest.php index 669d8b0a..10b3234f 100644 --- a/tests/phpunit/languages/LanguageLnTest.php +++ b/tests/phpunit/languages/LanguageLnTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageLn.php */ class LanguageLnTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @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 ), @@ -22,5 +32,4 @@ class LanguageLnTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageLtTest.php b/tests/phpunit/languages/LanguageLtTest.php index 9d6428b8..30642f62 100644 --- a/tests/phpunit/languages/LanguageLtTest.php +++ b/tests/phpunit/languages/LanguageLtTest.php @@ -7,20 +7,24 @@ /** Tests for MediaWiki languages/LanguageLt.php */ class LanguageLtTest extends LanguageClassesTestCase { - - /** @dataProvider provideOneFewOtherCases */ - function testOneFewOtherPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - /** @dataProvider provideOneFewCases */ - function testOneFewPlural( $result, $value ) { - $forms = array( 'one', 'few' ); - $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 provideOneFewOtherCases() { + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -36,10 +40,24 @@ class LanguageLtTest extends LanguageClassesTestCase { ); } - function provideOneFewCases() { + /** + * @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 bd0c759b..c4d8a6f0 100644 --- a/tests/phpunit/languages/LanguageLvTest.php +++ b/tests/phpunit/languages/LanguageLvTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageLv.php */ class LanguageLvTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'zero', 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @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 ), @@ -27,5 +37,4 @@ class LanguageLvTest extends LanguageClassesTestCase { array( 'other', 200 ), ); } - } diff --git a/tests/phpunit/languages/LanguageMgTest.php b/tests/phpunit/languages/LanguageMgTest.php index c1e516bc..65e8fd7b 100644 --- a/tests/phpunit/languages/LanguageMgTest.php +++ b/tests/phpunit/languages/LanguageMgTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageMg.php */ class LanguageMgTest extends LanguageClassesTestCase { - - /** @dataProvider providePlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePlural() { + /** + * @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 ), @@ -23,5 +33,4 @@ class LanguageMgTest extends LanguageClassesTestCase { array( 'other', 123.3434 ), ); } - } diff --git a/tests/phpunit/languages/LanguageMkTest.php b/tests/phpunit/languages/LanguageMkTest.php index 5c241ba7..7d47b375 100644 --- a/tests/phpunit/languages/LanguageMkTest.php +++ b/tests/phpunit/languages/LanguageMkTest.php @@ -7,27 +7,34 @@ /** Tests for MediaWiki languages/classes/LanguageMk.php */ class LanguageMkTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @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 ) ); + } - function providerPlural() { + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), array( 'other', 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 396114d9..4fa45ce3 100644 --- a/tests/phpunit/languages/LanguageMlTest.php +++ b/tests/phpunit/languages/LanguageMlTest.php @@ -8,13 +8,16 @@ /** Tests for MediaWiki languages/LanguageMl.php */ class LanguageMlTest extends LanguageClassesTestCase { - /** see bug 29495 */ - /** @dataProvider providerFormatNum */ - function testFormatNum( $result, $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,345', '12345' ), diff --git a/tests/phpunit/languages/LanguageMoTest.php b/tests/phpunit/languages/LanguageMoTest.php index f7da1cd6..e0e54ca8 100644 --- a/tests/phpunit/languages/LanguageMoTest.php +++ b/tests/phpunit/languages/LanguageMoTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageMo.php */ class LanguageMoTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'few', 0 ), array( 'one', 1 ), diff --git a/tests/phpunit/languages/LanguageMtTest.php b/tests/phpunit/languages/LanguageMtTest.php index f2b881e7..96d2bc92 100644 --- a/tests/phpunit/languages/LanguageMtTest.php +++ b/tests/phpunit/languages/LanguageMtTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageMt.php */ class LanguageMtTest extends LanguageClassesTestCase { - - /** @dataProvider providerPluralAllForms */ - function testPluralAllForms( $result, $value ) { + /** + * @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 providerPluralAllForms() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'few', 0 ), array( 'one', 1 ), @@ -35,30 +45,33 @@ class LanguageMtTest extends LanguageClassesTestCase { ); } - /** @dataProvider providerPluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'many' ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPluralTwoForms() { + public static function providePluralTwoForms() { return array( - array( 'many', 0 ), + array( 'other', 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 ), + 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 f783f2c0..26bd691a 100644 --- a/tests/phpunit/languages/LanguageNlTest.php +++ b/tests/phpunit/languages/LanguageNlTest.php @@ -8,7 +8,11 @@ /** Tests for MediaWiki languages/LanguageNl.php */ class LanguageNlTest extends LanguageClassesTestCase { - function testFormatNum() { + /** + * @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' ) ); diff --git a/tests/phpunit/languages/LanguageNsoTest.php b/tests/phpunit/languages/LanguageNsoTest.php index 9d80d138..18efd736 100644 --- a/tests/phpunit/languages/LanguageNsoTest.php +++ b/tests/phpunit/languages/LanguageNsoTest.php @@ -7,18 +7,28 @@ /** Tests for MediaWiki languages/classes/LanguageNso.php */ class LanguageNsoTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @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( 'many', 2 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/LanguagePlTest.php b/tests/phpunit/languages/LanguagePlTest.php index 1e36097b..d180037b 100644 --- a/tests/phpunit/languages/LanguagePlTest.php +++ b/tests/phpunit/languages/LanguagePlTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguagePl.php */ class LanguagePlTest extends LanguageClassesTestCase { - - /** @dataProvider providerPluralFourForms */ - function testPluralFourForms( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'few', 'many' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPluralFourForms() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'many', 0 ), array( 'one', 1 ), @@ -35,30 +45,33 @@ class LanguagePlTest extends LanguageClassesTestCase { ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + public static function providePluralTwoForms() { return array( - array( 'many', 0 ), + array( 'other', 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 ), + 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 916ea45d..ae7816bc 100644 --- a/tests/phpunit/languages/LanguageRoTest.php +++ b/tests/phpunit/languages/LanguageRoTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageRo.php */ class LanguageRoTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'few', 0 ), array( 'one', 1 ), diff --git a/tests/phpunit/languages/LanguageRuTest.php b/tests/phpunit/languages/LanguageRuTest.php index 0792f75b..e938be79 100644 --- a/tests/phpunit/languages/LanguageRuTest.php +++ b/tests/phpunit/languages/LanguageRuTest.php @@ -8,14 +8,24 @@ /** Tests for MediaWiki languages/classes/LanguageRu.php */ class LanguageRuTest extends LanguageClassesTestCase { - - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { + /** + * @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() { + /** + * @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 ), @@ -31,27 +41,33 @@ class LanguageRuTest extends LanguageClassesTestCase { ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { + 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 */ - function testGrammar( $result, $word, $case ) { + /** + * @dataProvider providerGrammar + * @covers Language::convertGrammar + */ + public function testGrammar( $result, $word, $case ) { $this->assertEquals( $result, $this->getLang()->convertGrammar( $word, $case ) ); } - function providerGrammar() { + public static function providerGrammar() { return array( array( 'Википедии', diff --git a/tests/phpunit/languages/LanguageSeTest.php b/tests/phpunit/languages/LanguageSeTest.php index c7dd8020..533aa2bc 100644 --- a/tests/phpunit/languages/LanguageSeTest.php +++ b/tests/phpunit/languages/LanguageSeTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageSe.php */ class LanguageSeTest extends LanguageClassesTestCase { - - /** @dataProvider providerPluralThreeForms */ - function testPluralThreeForms( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'two', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPluralThreeForms() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -23,13 +33,16 @@ class LanguageSeTest extends LanguageClassesTestCase { ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + public static function providePluralTwoForms() { return array( array( 'other', 0 ), array( 'one', 1 ), diff --git a/tests/phpunit/languages/LanguageSgsTest.php b/tests/phpunit/languages/LanguageSgsTest.php index 95e63462..bf6a14b1 100644 --- a/tests/phpunit/languages/LanguageSgsTest.php +++ b/tests/phpunit/languages/LanguageSgsTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageSgs.php */ class LanguageSgsTest extends LanguageClassesTestCase { - - /** @dataProvider providePluralAllForms */ - function testPluralAllForms( $result, $value ) { + /** + * @dataProvider providePluralAllForms + * @covers Language::convertPlural + */ + public function testPluralAllForms( $result, $value ) { $forms = array( 'one', 'two', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralAllForms() { + /** + * @dataProvider providePluralAllForms + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePluralAllForms() { return array( array( 'few', 0 ), array( 'one', 1 ), @@ -32,13 +42,16 @@ class LanguageSgsTest extends LanguageClassesTestCase { ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { + public static function providePluralTwoForms() { return array( array( 'other', 0 ), array( 'one', 1 ), diff --git a/tests/phpunit/languages/LanguageShTest.php b/tests/phpunit/languages/LanguageShTest.php index 282fd2f2..6d2e25a6 100644 --- a/tests/phpunit/languages/LanguageShTest.php +++ b/tests/phpunit/languages/LanguageShTest.php @@ -7,18 +7,36 @@ /** Tests for MediaWiki languages/classes/LanguageSh.php */ class LanguageShTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); + /** + * @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 providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'many', 0 ), array( 'one', 1 ), - array( 'many', 2 ), + array( 'few', 2 ), + array( 'few', 4 ), + array( 'many', 5 ), + array( 'many', 10 ), + array( 'many', 11 ), + array( 'many', 12 ), + array( 'one', 101 ), + array( 'few', 102 ), + array( 'many', 111 ), ); } } diff --git a/tests/phpunit/languages/LanguageSkTest.php b/tests/phpunit/languages/LanguageSkTest.php index 89cbbf01..cb8a13b8 100644 --- a/tests/phpunit/languages/LanguageSkTest.php +++ b/tests/phpunit/languages/LanguageSkTest.php @@ -8,14 +8,24 @@ /** Tests for MediaWiki languages/classes/LanguageSk.php */ class LanguageSkTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'few', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), diff --git a/tests/phpunit/languages/LanguageSlTest.php b/tests/phpunit/languages/LanguageSlTest.php index 075e6af3..9783dd80 100644 --- a/tests/phpunit/languages/LanguageSlTest.php +++ b/tests/phpunit/languages/LanguageSlTest.php @@ -8,16 +8,26 @@ /** Tests for MediaWiki languages/classes/LanguageSl.php */ class LanguageSlTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'two', 'few', 'other', 'zero' ); + /** + * @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 providerPlural() { + /** + * @dataProvider providerPlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providerPlural() { return array( - array( 'zero', 0 ), + array( 'other', 0 ), array( 'one', 1 ), array( 'two', 2 ), array( 'few', 3 ), diff --git a/tests/phpunit/languages/LanguageSmaTest.php b/tests/phpunit/languages/LanguageSmaTest.php index 6d655219..95cb333c 100644 --- a/tests/phpunit/languages/LanguageSmaTest.php +++ b/tests/phpunit/languages/LanguageSmaTest.php @@ -7,14 +7,24 @@ /** Tests for MediaWiki languages/classes/LanguageSma.php */ class LanguageSmaTest extends LanguageClassesTestCase { - - /** @dataProvider providerPluralThreeForms */ - function testPluralThreeForms( $result, $value ) { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { $forms = array( 'one', 'two', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPluralThreeForms() { + /** + * @dataProvider providePlural + * @covers Language::getPluralRuleType + */ + public function testGetPluralRuleType( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) ); + } + + public static function providePlural() { return array( array( 'other', 0 ), array( 'one', 1 ), @@ -23,13 +33,16 @@ class LanguageSmaTest extends LanguageClassesTestCase { ); } - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + public static function providePluralTwoForms() { return array( array( 'other', 0 ), array( 'one', 1 ), diff --git a/tests/phpunit/languages/LanguageSrTest.php b/tests/phpunit/languages/LanguageSrTest.php index 5611030b..ab4d4aba 100644 --- a/tests/phpunit/languages/LanguageSrTest.php +++ b/tests/phpunit/languages/LanguageSrTest.php @@ -10,16 +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 LanguageClassesTestCase { - - ##### TESTS ####################################################### - - function testEasyConversions() { + /** + * @covers LanguageConverter::convertTo + */ + public function testEasyConversions() { $this->assertCyrillic( 'шђчћжШЂЧЋЖ', 'Cyrillic guessing characters' @@ -30,7 +32,10 @@ class LanguageSrTest extends LanguageClassesTestCase { ); } - function testMixedConversions() { + /** + * @covers LanguageConverter::convertTo + */ + public function testMixedConversions() { $this->assertCyrillic( 'шђчћжШЂЧЋЖ - šđčćž', 'Mostly cyrillic characters' @@ -41,7 +46,10 @@ class LanguageSrTest extends LanguageClassesTestCase { ); } - function testSameAmountOfLatinAndCyrillicGetConverted() { + /** + * @covers LanguageConverter::convertTo + */ + public function testSameAmountOfLatinAndCyrillicGetConverted() { $this->assertConverted( '4 latin: šđčć | 4 cyrillic: шђчћ', 'sr-ec' @@ -54,8 +62,9 @@ class LanguageSrTest extends LanguageClassesTestCase { /** * @author Nikola Smolenski + * @covers LanguageConverter::convertTo */ - function testConversionToCyrillic() { + public function testConversionToCyrillic() { //A simple convertion of Latin to Cyrillic $this->assertEquals( 'абвг', $this->convertToCyrillic( 'abvg' ) @@ -94,7 +103,10 @@ class LanguageSrTest extends LanguageClassesTestCase { ); } - function testConversionToLatin() { + /** + * @covers LanguageConverter::convertTo + */ + public function testConversionToLatin() { //A simple convertion of Latin to Latin $this->assertEquals( 'abcd', $this->convertToLatin( 'abcd' ) @@ -113,13 +125,24 @@ class LanguageSrTest extends LanguageClassesTestCase { ); } - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { + /** + * @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() { + /** + * @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 ), @@ -135,18 +158,21 @@ class LanguageSrTest extends LanguageClassesTestCase { ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { + 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 ), ); } @@ -157,7 +183,7 @@ class LanguageSrTest extends LanguageClassesTestCase { * @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 ), @@ -171,7 +197,7 @@ class LanguageSrTest extends LanguageClassesTestCase { * @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 ), @@ -184,7 +210,7 @@ class LanguageSrTest extends LanguageClassesTestCase { * 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 ); } @@ -194,26 +220,26 @@ class LanguageSrTest extends LanguageClassesTestCase { * 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 ) { + protected function convertTo( $text, $variant ) { return $this->getLang() ->mConverter ->convertTo( - $text, $variant - ); + $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 76471445..78929e23 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -1,8 +1,11 @@ <?php class LanguageTest extends LanguageClassesTestCase { - - function testLanguageConvertDoubleWidthToSingleWidth() { + /** + * @covers Language::convertDoubleWidth + * @covers Language::normalizeForSearch + */ + public function testLanguageConvertDoubleWidthToSingleWidth() { $this->assertEquals( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", $this->getLang()->normalizeForSearch( @@ -13,13 +16,14 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * @dataProvider provideFormattableTimes + * @dataProvider provideFormattableTimes# + * @covers Language::formatTimePeriod */ - function testFormatTimePeriod( $seconds, $format, $expected, $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, @@ -202,10 +206,12 @@ class LanguageTest extends LanguageClassesTestCase { 'formatTimePeriod() rounding, recursion, (>48h)' ), ); - } - function testTruncate() { + /** + * @covers Language::truncate + */ + public function testTruncate() { $this->assertEquals( "XXX", $this->getLang()->truncate( "1234567890", 0, 'XXX' ), @@ -238,9 +244,10 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * @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, @@ -249,9 +256,9 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * 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" ), @@ -310,8 +317,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * Test Language::isWellFormedLanguageTag() * @dataProvider provideWellFormedLanguageTags + * @covers Language::isWellFormedLanguageTag */ - function testWellFormedLanguageTag( $code, $message = '' ) { + public function testWellFormedLanguageTag( $code, $message = '' ) { $this->assertTrue( Language::isWellFormedLanguageTag( $code ), "validating code $code $message" @@ -324,7 +332,7 @@ class LanguageTest extends LanguageClassesTestCase { * and distributed as free software, under the GNU General Public Licence. * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html */ - function provideWellFormedLanguageTags() { + public static function provideWellFormedLanguageTags() { return array( array( 'fr', 'two-letter code' ), array( 'fr-latn', 'two-letter code with lower case script code' ), @@ -361,8 +369,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * Negative test for Language::isWellFormedLanguageTag() * @dataProvider provideMalformedLanguageTags + * @covers Language::isWellFormedLanguageTag */ - function testMalformedLanguageTag( $code, $message = '' ) { + public function testMalformedLanguageTag( $code, $message = '' ) { $this->assertFalse( Language::isWellFormedLanguageTag( $code ), "validating that code $code is a malformed language tag - $message" @@ -375,7 +384,7 @@ class LanguageTest extends LanguageClassesTestCase { * and distributed as free software, under the GNU General Public Licence. * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html */ - function provideMalformedLanguageTags() { + public static function provideMalformedLanguageTags() { return array( array( 'f', 'language too short' ), array( 'f-Latn', 'language too short with script' ), @@ -411,8 +420,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * Negative test for Language::isWellFormedLanguageTag() + * @covers Language::isWellFormedLanguageTag */ - function testLenientLanguageTag() { + public function testLenientLanguageTag() { $this->assertTrue( Language::isWellFormedLanguageTag( 'pa_guru', true ), 'pa_guru is a well-formed language tag in lenient mode' @@ -422,22 +432,26 @@ class LanguageTest extends LanguageClassesTestCase { /** * Test Language::isValidBuiltInCode() * @dataProvider provideLanguageCodes + * @covers Language::isValidBuiltInCode */ - function testBuiltInCodeValidation( $code, $message = '' ) { + public function testBuiltInCodeValidation( $code, $message = '' ) { $this->assertTrue( (bool)Language::isValidBuiltInCode( $code ), "validating code $code $message" ); } - function testBuiltInCodeValidationRejectUnderscore() { + /** + * @covers Language::isValidBuiltInCode + */ + public function testBuiltInCodeValidationRejectUnderscore() { $this->assertFalse( (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' ), @@ -452,15 +466,16 @@ class LanguageTest extends LanguageClassesTestCase { /** * Test Language::isKnownLanguageTag() * @dataProvider provideKnownLanguageTags + * @covers Language::isKnownLanguageTag */ - function testKnownLanguageTag( $code, $message = '' ) { + public function testKnownLanguageTag( $code, $message = '' ) { $this->assertTrue( (bool)Language::isKnownLanguageTag( $code ), "validating code $code - $message" ); } - function provideKnownLanguageTags() { + public static function provideKnownLanguageTags() { return array( array( 'fr', 'simple code' ), array( 'bat-smg', 'an MW legacy tag' ), @@ -469,9 +484,9 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * Test Language::isKnownLanguageTag() + * @covers Language::isKnownLanguageTag */ - function testKnownCldrLanguageTag() { + public function testKnownCldrLanguageTag() { if ( !class_exists( 'LanguageNames' ) ) { $this->markTestSkipped( 'The LanguageNames class is not available. The cldr extension is probably not installed.' ); } @@ -485,24 +500,54 @@ class LanguageTest extends LanguageClassesTestCase { /** * Negative tests for Language::isKnownLanguageTag() * @dataProvider provideUnKnownLanguageTags + * @covers Language::isKnownLanguageTag */ - function testUnknownLanguageTag( $code, $message = '' ) { + public function testUnknownLanguageTag( $code, $message = '' ) { $this->assertFalse( (bool)Language::isKnownLanguageTag( $code ), "checking that code $code is invalid - $message" ); } - function provideUnknownLanguageTags() { + 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->getLang()->sprintfDate( $format, $ts ), @@ -511,10 +556,11 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * 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 ) { @@ -530,42 +576,66 @@ class LanguageTest extends LanguageClassesTestCase { 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 @@ -573,252 +643,336 @@ class LanguageTest extends LanguageClassesTestCase { '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' ), @@ -827,8 +981,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideFormatSizes + * @covers Language::formatSize */ - function testFormatSize( $size, $expected, $msg ) { + public function testFormatSize( $size, $expected, $msg ) { $this->assertEquals( $expected, $this->getLang()->formatSize( $size ), @@ -836,7 +991,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideFormatSizes() { + public static function provideFormatSizes() { return array( array( 0, @@ -889,8 +1044,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideFormatBitrate + * @covers Language::formatBitrate */ - function testFormatBitrate( $bps, $expected, $msg ) { + public function testFormatBitrate( $bps, $expected, $msg ) { $this->assertEquals( $expected, $this->getLang()->formatBitrate( $bps ), @@ -898,7 +1054,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideFormatBitrate() { + public static function provideFormatBitrate() { return array( array( 0, @@ -961,8 +1117,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideFormatDuration + * @covers Language::formatDuration */ - function testFormatDuration( $duration, $expected, $intervals = array() ) { + public function testFormatDuration( $duration, $expected, $intervals = array() ) { $this->assertEquals( $expected, $this->getLang()->formatDuration( $duration, $intervals ), @@ -970,7 +1127,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideFormatDuration() { + public static function provideFormatDuration() { return array( array( 0, @@ -1097,8 +1254,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideCheckTitleEncodingData + * @covers Language::checkTitleEncoding */ - function testCheckTitleEncoding( $s ) { + public function testCheckTitleEncoding( $s ) { $this->assertEquals( $s, $this->getLang()->checkTitleEncoding( $s ), @@ -1106,7 +1264,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideCheckTitleEncodingData() { + public static function provideCheckTitleEncodingData() { return array( array( "" ), array( "United States of America" ), // 7bit ASCII @@ -1161,8 +1319,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideRomanNumeralsData + * @covers Language::romanNumeral */ - function testRomanNumerals( $num, $numerals ) { + public function testRomanNumerals( $num, $numerals ) { $this->assertEquals( $numerals, Language::romanNumeral( $num ), @@ -1170,7 +1329,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideRomanNumeralsData() { + public static function provideRomanNumeralsData() { return array( array( 1, 'I' ), array( 2, 'II' ), @@ -1219,13 +1378,14 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider providePluralData + * @covers Language::convertPlural */ - function testConvertPlural( $expected, $number, $forms ) { + public function testConvertPlural( $expected, $number, $forms ) { $chosen = $this->getLang()->convertPlural( $number, $forms ); $this->assertEquals( $expected, $chosen ); } - function providePluralData() { + public static function providePluralData() { // Params are: [expected text, number given, [the plural forms]] return array( array( 'plural', 0, array( @@ -1255,6 +1415,9 @@ class LanguageTest extends LanguageClassesTestCase { array( 'other', 2, array( 'kissa=kala', '1=2=3', 'other', ) ), + array( '', 2, array( + '0=explicit zero', '1=explicit one', + ) ), ); } @@ -1262,7 +1425,7 @@ class LanguageTest extends LanguageClassesTestCase { * @covers Language::translateBlockExpiry() * @dataProvider provideTranslateBlockExpiry */ - function testTranslateBlockExpiry( $expectedData, $str, $desc ) { + public function testTranslateBlockExpiry( $expectedData, $str, $desc ) { $lang = $this->getLang(); if ( is_array( $expectedData ) ) { list( $func, $arg ) = $expectedData; @@ -1273,7 +1436,7 @@ class LanguageTest extends LanguageClassesTestCase { $this->assertEquals( $expected, $lang->translateBlockExpiry( $str ), $desc ); } - function provideTranslateBlockExpiry() { + public static function provideTranslateBlockExpiry() { return array( array( '2 hours', '2 hours', 'simple data from ipboptions' ), array( 'indefinite', 'infinite', 'infinite from ipboptions' ), @@ -1294,7 +1457,7 @@ class LanguageTest extends LanguageClassesTestCase { * @covers Language::commafy() * @dataProvider provideCommafyData */ - function testCommafy( $number, $numbersWithCommas ) { + public function testCommafy( $number, $numbersWithCommas ) { $this->assertEquals( $numbersWithCommas, $this->getLang()->commafy( $number ), @@ -1302,7 +1465,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideCommafyData() { + public static function provideCommafyData() { return array( array( 1, '1' ), array( 10, '10' ), @@ -1321,7 +1484,10 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function testListToText() { + /** + * @covers Language::listToText + */ + public function testListToText() { $lang = $this->getLang(); $and = $lang->getMessageFromDB( 'and' ); $s = $lang->getMessageFromDB( 'word-separator' ); @@ -1336,12 +1502,13 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideIsSupportedLanguage + * @covers Language::isSupportedLanguage */ - function testIsSupportedLanguage( $code, $expected, $comment ) { + public function testIsSupportedLanguage( $code, $expected, $comment ) { $this->assertEquals( $expected, Language::isSupportedLanguage( $code ), $comment ); } - static function provideIsSupportedLanguage() { + public static function provideIsSupportedLanguage() { return array( array( 'en', true, 'is supported language' ), array( 'fi', true, 'is supported language' ), @@ -1349,4 +1516,52 @@ class LanguageTest extends LanguageClassesTestCase { 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 8af0eee2..e225af97 100644 --- a/tests/phpunit/languages/LanguageTiTest.php +++ b/tests/phpunit/languages/LanguageTiTest.php @@ -7,18 +7,28 @@ /** Tests for MediaWiki languages/classes/LanguageTi.php */ class LanguageTiTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @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( 'many', 2 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/LanguageTlTest.php b/tests/phpunit/languages/LanguageTlTest.php index abd8581a..7ac51c69 100644 --- a/tests/phpunit/languages/LanguageTlTest.php +++ b/tests/phpunit/languages/LanguageTlTest.php @@ -7,18 +7,28 @@ /** Tests for MediaWiki languages/classes/LanguageTl.php */ class LanguageTlTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @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( 'many', 2 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/LanguageTrTest.php b/tests/phpunit/languages/LanguageTrTest.php index e93d49d9..8fc2795c 100644 --- a/tests/phpunit/languages/LanguageTrTest.php +++ b/tests/phpunit/languages/LanguageTrTest.php @@ -17,7 +17,7 @@ class LanguageTrTest extends LanguageClassesTestCase { * @see http://en.wikipedia.org/wiki/Dotted_and_dotless_I * @dataProvider provideDottedAndDotlessI */ - function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) { + public function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) { if ( $func == 'ucfirst' ) { $res = $this->getLang()->ucfirst( $input ); } elseif ( $func == 'lcfirst' ) { @@ -31,7 +31,7 @@ class LanguageTrTest extends LanguageClassesTestCase { $this->assertEquals( $expected, $res, $msg ); } - function provideDottedAndDotlessI() { + public static function provideDottedAndDotlessI() { return array( # function, input, input case, expected # Case changed: @@ -56,5 +56,4 @@ class LanguageTrTest extends LanguageClassesTestCase { ); } - } diff --git a/tests/phpunit/languages/LanguageUkTest.php b/tests/phpunit/languages/LanguageUkTest.php index 9bbfaf66..0783fcf6 100644 --- a/tests/phpunit/languages/LanguageUkTest.php +++ b/tests/phpunit/languages/LanguageUkTest.php @@ -8,14 +8,24 @@ /** Tests for MediaWiki languages/classes/LanguageUk.php */ class LanguageUkTest extends LanguageClassesTestCase { - - /** @dataProvider providePluralFourForms */ - function testPluralFourForms( $result, $value ) { + /** + * @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() { + /** + * @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 ), @@ -31,18 +41,21 @@ class LanguageUkTest extends LanguageClassesTestCase { ); } - /** @dataProvider providePluralTwoForms */ - function testPluralTwoForms( $result, $value ) { - $forms = array( 'one', 'several' ); + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providePluralTwoForms() { + 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 495c0be6..13f57c16 100644 --- a/tests/phpunit/languages/LanguageUzTest.php +++ b/tests/phpunit/languages/LanguageUzTest.php @@ -10,17 +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 LanguageClassesTestCase { /** * @author Nikola Smolenski + * @covers LanguageConverter::convertTo */ - function testConversionToCyrillic() { + public function testConversionToCyrillic() { // A convertion of Latin to Cyrillic $this->assertEquals( 'абвгғ', $this->convertToCyrillic( 'abvggʻ' ) @@ -39,7 +42,10 @@ class LanguageUzTest extends LanguageClassesTestCase { ); } - function testConversionToLatin() { + /** + * @covers LanguageConverter::convertTo + */ + public function testConversionToLatin() { // A simple convertion of Latin to Latin $this->assertEquals( 'abdef', $this->convertToLatin( 'abdef' ) @@ -57,7 +63,7 @@ class LanguageUzTest extends LanguageClassesTestCase { * @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 ), @@ -71,7 +77,7 @@ class LanguageUzTest extends LanguageClassesTestCase { * @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 ), @@ -84,7 +90,7 @@ class LanguageUzTest extends LanguageClassesTestCase { * 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 ); } @@ -94,22 +100,22 @@ class LanguageUzTest extends LanguageClassesTestCase { * 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 ) { + 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 28329fa3..d05196c0 100644 --- a/tests/phpunit/languages/LanguageWaTest.php +++ b/tests/phpunit/languages/LanguageWaTest.php @@ -7,18 +7,28 @@ /** Tests for MediaWiki languages/classes/LanguageWa.php */ class LanguageWaTest extends LanguageClassesTestCase { - - /** @dataProvider providerPlural */ - function testPlural( $result, $value ) { - $forms = array( 'one', 'many' ); + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); } - function providerPlural() { + /** + * @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( 'many', 2 ), + array( 'other', 2 ), ); } } diff --git a/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php b/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php index 73d5dcc0..3bf74146 100644 --- a/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php +++ b/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php @@ -89,7 +89,7 @@ class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase { array( 'n', 'just n' ), array( 'n is in 5', 'is in' ), ); + return $tests; } - } |