summaryrefslogtreecommitdiff
path: root/tests/phpunit/languages
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/languages')
-rw-r--r--tests/phpunit/languages/LanguageAmTest.php35
-rw-r--r--tests/phpunit/languages/LanguageArTest.php87
-rw-r--r--tests/phpunit/languages/LanguageBeTest.php42
-rw-r--r--tests/phpunit/languages/LanguageBe_taraskTest.php95
-rw-r--r--tests/phpunit/languages/LanguageBhoTest.php35
-rw-r--r--tests/phpunit/languages/LanguageBsTest.php42
-rw-r--r--tests/phpunit/languages/LanguageClassesTestCase.php74
-rw-r--r--tests/phpunit/languages/LanguageCsTest.php41
-rw-r--r--tests/phpunit/languages/LanguageCuTest.php42
-rw-r--r--tests/phpunit/languages/LanguageCyTest.php43
-rw-r--r--tests/phpunit/languages/LanguageDsbTest.php41
-rw-r--r--tests/phpunit/languages/LanguageFrTest.php35
-rw-r--r--tests/phpunit/languages/LanguageGaTest.php35
-rw-r--r--tests/phpunit/languages/LanguageGdTest.php53
-rw-r--r--tests/phpunit/languages/LanguageGvTest.php44
-rw-r--r--tests/phpunit/languages/LanguageHeTest.php132
-rw-r--r--tests/phpunit/languages/LanguageHiTest.php35
-rw-r--r--tests/phpunit/languages/LanguageHrTest.php42
-rw-r--r--tests/phpunit/languages/LanguageHsbTest.php41
-rw-r--r--tests/phpunit/languages/LanguageHuTest.php35
-rw-r--r--tests/phpunit/languages/LanguageHyTest.php35
-rw-r--r--tests/phpunit/languages/LanguageKshTest.php35
-rw-r--r--tests/phpunit/languages/LanguageLnTest.php35
-rw-r--r--tests/phpunit/languages/LanguageLtTest.php63
-rw-r--r--tests/phpunit/languages/LanguageLvTest.php44
-rw-r--r--tests/phpunit/languages/LanguageMgTest.php36
-rw-r--r--tests/phpunit/languages/LanguageMkTest.php40
-rw-r--r--tests/phpunit/languages/LanguageMlTest.php38
-rw-r--r--tests/phpunit/languages/LanguageMoTest.php45
-rw-r--r--tests/phpunit/languages/LanguageMtTest.php77
-rw-r--r--tests/phpunit/languages/LanguageNlTest.php24
-rw-r--r--tests/phpunit/languages/LanguageNsoTest.php34
-rw-r--r--tests/phpunit/languages/LanguagePlTest.php77
-rw-r--r--tests/phpunit/languages/LanguageRoTest.php45
-rw-r--r--tests/phpunit/languages/LanguageRuTest.php105
-rw-r--r--tests/phpunit/languages/LanguageSeTest.php53
-rw-r--r--tests/phpunit/languages/LanguageSgsTest.php71
-rw-r--r--tests/phpunit/languages/LanguageShTest.php42
-rw-r--r--tests/phpunit/languages/LanguageSkTest.php42
-rw-r--r--tests/phpunit/languages/LanguageSlTest.php44
-rw-r--r--tests/phpunit/languages/LanguageSmaTest.php53
-rw-r--r--tests/phpunit/languages/LanguageSrTest.php246
-rw-r--r--tests/phpunit/languages/LanguageTest.php1567
-rw-r--r--tests/phpunit/languages/LanguageTiTest.php34
-rw-r--r--tests/phpunit/languages/LanguageTlTest.php34
-rw-r--r--tests/phpunit/languages/LanguageTrTest.php59
-rw-r--r--tests/phpunit/languages/LanguageUkTest.php72
-rw-r--r--tests/phpunit/languages/LanguageUzTest.php121
-rw-r--r--tests/phpunit/languages/LanguageWaTest.php34
-rw-r--r--tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php145
50 files changed, 4379 insertions, 0 deletions
diff --git a/tests/phpunit/languages/LanguageAmTest.php b/tests/phpunit/languages/LanguageAmTest.php
new file mode 100644
index 00000000..a644f5e0
--- /dev/null
+++ b/tests/phpunit/languages/LanguageAmTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageAm.php */
+class LanguageAmTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageArTest.php b/tests/phpunit/languages/LanguageArTest.php
new file mode 100644
index 00000000..7b48f236
--- /dev/null
+++ b/tests/phpunit/languages/LanguageArTest.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Based on LanguagMlTest
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageAr.php */
+class LanguageArTest extends LanguageClassesTestCase {
+ /**
+ * @covers Language::formatNum
+ * @todo split into a test and a dataprovider
+ */
+ public function testFormatNum() {
+ $this->assertEquals( '١٬٢٣٤٬٥٦٧', $this->getLang()->formatNum( '1234567' ) );
+ $this->assertEquals( '-١٢٫٨٩', $this->getLang()->formatNum( -12.89 ) );
+ }
+
+ /**
+ * Mostly to test the raw ascii feature.
+ * @dataProvider providerSprintfDate
+ * @covers Language::sprintfDate
+ */
+ public function testSprintfDate( $format, $date, $expected ) {
+ $this->assertEquals( $expected, $this->getLang()->sprintfDate( $format, $date ) );
+ }
+
+ public static function providerSprintfDate() {
+ return array(
+ array(
+ 'xg "vs" g',
+ '20120102030410',
+ 'يناير vs ٣'
+ ),
+ array(
+ 'xmY',
+ '20120102030410',
+ '١٤٣٣'
+ ),
+ array(
+ 'xnxmY',
+ '20120102030410',
+ '1433'
+ ),
+ array(
+ 'xN xmj xmn xN xmY',
+ '20120102030410',
+ ' 7 2 ١٤٣٣'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'zero', 'one', 'two', 'few', 'many', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'zero', 0 ),
+ array( 'one', 1 ),
+ array( 'two', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 9 ),
+ array( 'few', 110 ),
+ array( 'many', 11 ),
+ array( 'many', 15 ),
+ array( 'many', 99 ),
+ array( 'many', 9999 ),
+ array( 'other', 100 ),
+ array( 'other', 102 ),
+ array( 'other', 1000 ),
+ array( 'other', 1.7 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageBeTest.php b/tests/phpunit/languages/LanguageBeTest.php
new file mode 100644
index 00000000..7bd586af
--- /dev/null
+++ b/tests/phpunit/languages/LanguageBeTest.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageBe.php */
+class LanguageBeTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'many', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 1 ),
+ array( 'many', 11 ),
+ array( 'one', 91 ),
+ array( 'one', 121 ),
+ array( 'few', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'few', 334 ),
+ array( 'many', 5 ),
+ array( 'many', 15 ),
+ array( 'many', 120 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageBe_taraskTest.php b/tests/phpunit/languages/LanguageBe_taraskTest.php
new file mode 100644
index 00000000..dbdb5889
--- /dev/null
+++ b/tests/phpunit/languages/LanguageBe_taraskTest.php
@@ -0,0 +1,95 @@
+<?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.
+ */
+ public function testBeTaraskTestsUsesBeTaraskCode() {
+ $this->assertEquals( 'be-tarask',
+ $this->getLang()->getCode()
+ );
+ }
+
+ /**
+ * @see bug 23156 & r64981
+ * @covers Language::commafy
+ */
+ public function testSearchRightSingleQuotationMarkAsApostroph() {
+ $this->assertEquals(
+ "'",
+ $this->getLang()->normalizeForSearch( '’' ),
+ 'bug 23156: U+2019 conversion to U+0027'
+ );
+ }
+
+ /**
+ * @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
+ * @covers Language::commafy
+ */
+ public function testDoesNotCommafyFourDigitsNumber() {
+ $this->assertEquals( '1234', $this->getLang()->commafy( '1234' ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'many', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 1 ),
+ array( 'many', 11 ),
+ array( 'one', 91 ),
+ array( 'one', 121 ),
+ array( 'few', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'few', 334 ),
+ array( 'many', 5 ),
+ array( 'many', 15 ),
+ array( 'many', 120 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( '1=one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 11 ),
+ array( 'other', 91 ),
+ array( 'other', 121 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageBhoTest.php b/tests/phpunit/languages/LanguageBhoTest.php
new file mode 100644
index 00000000..187bfbbc
--- /dev/null
+++ b/tests/phpunit/languages/LanguageBhoTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageBho.php */
+class LanguageBhoTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageBsTest.php b/tests/phpunit/languages/LanguageBsTest.php
new file mode 100644
index 00000000..7aca2ab1
--- /dev/null
+++ b/tests/phpunit/languages/LanguageBsTest.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for Croatian (hrvatski) */
+class LanguageBsTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @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( 'few', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 11 ),
+ array( 'other', 20 ),
+ array( 'one', 21 ),
+ array( 'few', 24 ),
+ array( 'other', 25 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageClassesTestCase.php b/tests/phpunit/languages/LanguageClassesTestCase.php
new file mode 100644
index 00000000..632e037f
--- /dev/null
+++ b/tests/phpunit/languages/LanguageClassesTestCase.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Helping class to run tests using a clean language instance.
+ *
+ * This is intended for the MediaWiki language class tests under
+ * tests/phpunit/languages.
+ *
+ * Before each tests, a new language object is build which you
+ * can retrieve in your test using the $this->getLang() method:
+ *
+ * @par Using the crafted language object:
+ * @code
+ * function testHasLanguageObject() {
+ * $langObject = $this->getLang();
+ * $this->assertInstanceOf( 'LanguageFoo',
+ * $langObject
+ * );
+ * }
+ * @endcode
+ */
+abstract class LanguageClassesTestCase extends MediaWikiTestCase {
+ /**
+ * Internal language object
+ *
+ * A new object is created before each tests thanks to PHPUnit
+ * setUp() method, it is deleted after each test too. To get
+ * this object you simply use the getLang method.
+ *
+ * You must have setup a language code first. See $LanguageClassCode
+ * @code
+ * function testWeAreTheChampions() {
+ * $this->getLang(); # language object
+ * }
+ * @endcode
+ */
+ private $languageObject;
+
+ /**
+ * @return Language
+ */
+ protected function getLang() {
+ return $this->languageObject;
+ }
+
+ /**
+ * Create a new language object before each test.
+ */
+ protected function setUp() {
+ parent::setUp();
+ $found = preg_match( '/Language(.+)Test/', get_called_class(), $m );
+ if ( $found ) {
+ # Normalize language code since classes uses underscores
+ $m[1] = str_replace( '_', '-', $m[1] );
+ } else {
+ # Fallback to english language
+ $m[1] = 'en';
+ wfDebug(
+ __METHOD__ . " could not extract a language name "
+ . "out of " . get_called_class() . " failling back to 'en'\n"
+ );
+ }
+ // @todo validate $m[1] which should be a valid language code
+ $this->languageObject = Language::factory( $m[1] );
+ }
+
+ /**
+ * Delete the internal language object so each test start
+ * out with a fresh language instance.
+ */
+ protected function tearDown() {
+ unset( $this->languageObject );
+ parent::tearDown();
+ }
+}
diff --git a/tests/phpunit/languages/LanguageCsTest.php b/tests/phpunit/languages/LanguageCsTest.php
new file mode 100644
index 00000000..da9e6b88
--- /dev/null
+++ b/tests/phpunit/languages/LanguageCsTest.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/Languagecs.php */
+class LanguageCsTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 11 ),
+ array( 'other', 20 ),
+ array( 'other', 25 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageCuTest.php b/tests/phpunit/languages/LanguageCuTest.php
new file mode 100644
index 00000000..07193172
--- /dev/null
+++ b/tests/phpunit/languages/LanguageCuTest.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageCu.php */
+class LanguageCuTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'two', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'other', 5 ),
+ array( 'one', 11 ),
+ array( 'other', 20 ),
+ array( 'two', 22 ),
+ array( 'few', 223 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageCyTest.php b/tests/phpunit/languages/LanguageCyTest.php
new file mode 100644
index 00000000..eaf663a8
--- /dev/null
+++ b/tests/phpunit/languages/LanguageCyTest.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageCy.php */
+class LanguageCyTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'zero', 'one', 'two', 'few', 'many', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'zero', 0 ),
+ array( 'one', 1 ),
+ array( 'two', 2 ),
+ array( 'few', 3 ),
+ array( 'many', 6 ),
+ array( 'other', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 11 ),
+ array( 'other', 20 ),
+ array( 'other', 22 ),
+ array( 'other', 223 ),
+ array( 'other', 200.00 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageDsbTest.php b/tests/phpunit/languages/LanguageDsbTest.php
new file mode 100644
index 00000000..94c11bcc
--- /dev/null
+++ b/tests/phpunit/languages/LanguageDsbTest.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageDsb.php */
+class LanguageDsbTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @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( 'one', 101 ),
+ array( 'one', 90001 ),
+ array( 'two', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 203 ),
+ array( 'few', 4 ),
+ array( 'other', 99 ),
+ array( 'other', 555 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageFrTest.php b/tests/phpunit/languages/LanguageFrTest.php
new file mode 100644
index 00000000..46b65011
--- /dev/null
+++ b/tests/phpunit/languages/LanguageFrTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageFr.php */
+class LanguageFrTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageGaTest.php b/tests/phpunit/languages/LanguageGaTest.php
new file mode 100644
index 00000000..c009f56b
--- /dev/null
+++ b/tests/phpunit/languages/LanguageGaTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageGa.php */
+class LanguageGaTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'two', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageGdTest.php b/tests/phpunit/languages/LanguageGdTest.php
new file mode 100644
index 00000000..0b2612b2
--- /dev/null
+++ b/tests/phpunit/languages/LanguageGdTest.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012-2013, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageGd.php */
+class LanguageGdTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providerPlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providerPlural() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'two', 2 ),
+ array( 'one', 11 ),
+ array( 'two', 12 ),
+ array( 'few', 3 ),
+ array( 'few', 19 ),
+ array( 'other', 200 ),
+ );
+ }
+
+ /**
+ * @dataProvider 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 ) );
+ }
+
+ 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
new file mode 100644
index 00000000..fc58022a
--- /dev/null
+++ b/tests/phpunit/languages/LanguageGvTest.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Test for Manx (Gaelg) language
+ *
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2013, Santhosh Thottingal
+ * @file
+ */
+
+class LanguageGvTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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 ),
+ array( 'two', 2 ),
+ array( 'other', 3 ),
+ array( 'few', 20 ),
+ array( 'one', 21 ),
+ array( 'two', 22 ),
+ array( 'other', 23 ),
+ array( 'other', 50 ),
+ array( 'few', 60 ),
+ array( 'other', 80 ),
+ array( 'few', 100 )
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageHeTest.php b/tests/phpunit/languages/LanguageHeTest.php
new file mode 100644
index 00000000..8edc6ddf
--- /dev/null
+++ b/tests/phpunit/languages/LanguageHeTest.php
@@ -0,0 +1,132 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** 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.
+ */
+
+ // @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 ) );
+ }
+
+ /**
+ * @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( 'one', 1 ), // Singular
+ 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
+ );
+ }
+
+ 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
+ );
+ }
+
+ public static function provideFourPluralForms() {
+ return array(
+ array( 'other', 0 ), // Zero - plural
+ array( 'one', 1 ), // Singular
+ array( 'two', 2 ), // Dual
+ array( 'other', 3 ), // Plural - other
+ array( 'other', 10 ), // 10 is supposed to be plural (other), not "many"
+ array( 'many', 20 ), // Fourth form provided - rare, but supported by CLDR
+ );
+ }
+
+ /**
+ * @dataProvider provideGrammar
+ * @covers Language::convertGrammar
+ */
+ public function testGrammar( $result, $word, $case ) {
+ $this->assertEquals( $result, $this->getLang()->convertGrammar( $word, $case ) );
+ }
+
+ // The comments in the beginning of the line help avoid RTL problems
+ // with text editors.
+ public static function provideGrammar() {
+ return array(
+ array(
+ /* result */'וויקיפדיה',
+ /* word */'ויקיפדיה',
+ /* case */'תחילית',
+ ),
+ array(
+ /* result */'וולפגנג',
+ /* word */'וולפגנג',
+ /* case */'prefixed',
+ ),
+ array(
+ /* result */'קובץ',
+ /* word */'הקובץ',
+ /* case */'תחילית',
+ ),
+ array(
+ /* result */'־Wikipedia',
+ /* word */'Wikipedia',
+ /* case */'תחילית',
+ ),
+ array(
+ /* result */'־1995',
+ /* word */'1995',
+ /* case */'תחילית',
+ ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageHiTest.php b/tests/phpunit/languages/LanguageHiTest.php
new file mode 100644
index 00000000..f6d2c9e9
--- /dev/null
+++ b/tests/phpunit/languages/LanguageHiTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageHi.php */
+class LanguageHiTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageHrTest.php b/tests/phpunit/languages/LanguageHrTest.php
new file mode 100644
index 00000000..644c5255
--- /dev/null
+++ b/tests/phpunit/languages/LanguageHrTest.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageHr.php */
+class LanguageHrTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'few', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 11 ),
+ array( 'other', 20 ),
+ array( 'one', 21 ),
+ array( 'few', 24 ),
+ array( 'other', 25 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageHsbTest.php b/tests/phpunit/languages/LanguageHsbTest.php
new file mode 100644
index 00000000..f95a43bf
--- /dev/null
+++ b/tests/phpunit/languages/LanguageHsbTest.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageHsb.php */
+class LanguageHsbTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @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( 'one', 101 ),
+ array( 'one', 90001 ),
+ array( 'two', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 203 ),
+ array( 'few', 4 ),
+ array( 'other', 99 ),
+ array( 'other', 555 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageHuTest.php b/tests/phpunit/languages/LanguageHuTest.php
new file mode 100644
index 00000000..ee9197d7
--- /dev/null
+++ b/tests/phpunit/languages/LanguageHuTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageHu.php */
+class LanguageHuTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @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( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageHyTest.php b/tests/phpunit/languages/LanguageHyTest.php
new file mode 100644
index 00000000..92e0ef94
--- /dev/null
+++ b/tests/phpunit/languages/LanguageHyTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for Armenian (Հայերեն) */
+class LanguageHyTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageKshTest.php b/tests/phpunit/languages/LanguageKshTest.php
new file mode 100644
index 00000000..568a3780
--- /dev/null
+++ b/tests/phpunit/languages/LanguageKshTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageKsh.php */
+class LanguageKshTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other', 'zero' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'zero', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageLnTest.php b/tests/phpunit/languages/LanguageLnTest.php
new file mode 100644
index 00000000..10b3234f
--- /dev/null
+++ b/tests/phpunit/languages/LanguageLnTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageLn.php */
+class LanguageLnTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageLtTest.php b/tests/phpunit/languages/LanguageLtTest.php
new file mode 100644
index 00000000..30642f62
--- /dev/null
+++ b/tests/phpunit/languages/LanguageLtTest.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageLt.php */
+class LanguageLtTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'few', 9 ),
+ array( 'other', 10 ),
+ array( 'other', 11 ),
+ array( 'other', 20 ),
+ array( 'one', 21 ),
+ array( 'few', 32 ),
+ array( 'one', 41 ),
+ array( 'one', 40001 ),
+ );
+ }
+
+ /**
+ * @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( '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
new file mode 100644
index 00000000..7120cfe3
--- /dev/null
+++ b/tests/phpunit/languages/LanguageLvTest.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for Latvian */
+class LanguageLvTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'zero', 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'zero', 0 ),
+ array( 'one', 1 ),
+ array( 'zero', 11 ),
+ array( 'one', 21 ),
+ array( 'zero', 411 ),
+ array( 'other', 2 ),
+ array( 'other', 9 ),
+ array( 'zero', 12 ),
+ array( 'other', 12.345 ),
+ array( 'zero', 20 ),
+ array( 'other', 22 ),
+ array( 'one', 31 ),
+ array( 'zero', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageMgTest.php b/tests/phpunit/languages/LanguageMgTest.php
new file mode 100644
index 00000000..65e8fd7b
--- /dev/null
+++ b/tests/phpunit/languages/LanguageMgTest.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageMg.php */
+class LanguageMgTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 200 ),
+ array( 'other', 123.3434 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageMkTest.php b/tests/phpunit/languages/LanguageMkTest.php
new file mode 100644
index 00000000..ed155263
--- /dev/null
+++ b/tests/phpunit/languages/LanguageMkTest.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for македонски/Macedonian */
+class LanguageMkTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'one', 11 ),
+ array( 'one', 21 ),
+ 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
new file mode 100644
index 00000000..4fa45ce3
--- /dev/null
+++ b/tests/phpunit/languages/LanguageMlTest.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2011, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageMl.php */
+class LanguageMlTest extends LanguageClassesTestCase {
+
+ /**
+ * @dataProvider providerFormatNum
+ * @see bug 29495
+ * @covers Language::formatNum
+ */
+ public function testFormatNum( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->formatNum( $value ) );
+ }
+
+ public static function providerFormatNum() {
+ return array(
+ array( '12,34,567', '1234567' ),
+ array( '12,345', '12345' ),
+ array( '1', '1' ),
+ array( '123', '123' ),
+ array( '1,234', '1234' ),
+ array( '12,345.56', '12345.56' ),
+ array( '12,34,56,79,81,23,45,678', '12345679812345678' ),
+ array( '.12345', '.12345' ),
+ array( '-12,00,000', '-1200000' ),
+ array( '-98', '-98' ),
+ array( '-98', -98 ),
+ array( '-1,23,45,678', -12345678 ),
+ array( '', '' ),
+ array( '', null ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageMoTest.php b/tests/phpunit/languages/LanguageMoTest.php
new file mode 100644
index 00000000..e0e54ca8
--- /dev/null
+++ b/tests/phpunit/languages/LanguageMoTest.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageMo.php */
+class LanguageMoTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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 ),
+ array( 'few', 2 ),
+ array( 'few', 19 ),
+ array( 'other', 20 ),
+ array( 'other', 99 ),
+ array( 'other', 100 ),
+ array( 'few', 101 ),
+ array( 'few', 119 ),
+ array( 'other', 120 ),
+ array( 'other', 200 ),
+ array( 'few', 201 ),
+ array( 'few', 219 ),
+ array( 'other', 220 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageMtTest.php b/tests/phpunit/languages/LanguageMtTest.php
new file mode 100644
index 00000000..96d2bc92
--- /dev/null
+++ b/tests/phpunit/languages/LanguageMtTest.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageMt.php */
+class LanguageMtTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'many', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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 ),
+ array( 'few', 2 ),
+ array( 'few', 10 ),
+ array( 'many', 11 ),
+ array( 'many', 19 ),
+ array( 'other', 20 ),
+ array( 'other', 99 ),
+ array( 'other', 100 ),
+ array( 'other', 101 ),
+ array( 'few', 102 ),
+ array( 'few', 110 ),
+ array( 'many', 111 ),
+ array( 'many', 119 ),
+ array( 'other', 120 ),
+ array( 'other', 201 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 10 ),
+ array( 'other', 11 ),
+ array( 'other', 19 ),
+ array( 'other', 20 ),
+ array( 'other', 99 ),
+ array( 'other', 100 ),
+ array( 'other', 101 ),
+ array( 'other', 102 ),
+ array( 'other', 110 ),
+ array( 'other', 111 ),
+ array( 'other', 119 ),
+ array( 'other', 120 ),
+ array( 'other', 201 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageNlTest.php b/tests/phpunit/languages/LanguageNlTest.php
new file mode 100644
index 00000000..26bd691a
--- /dev/null
+++ b/tests/phpunit/languages/LanguageNlTest.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2011, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageNl.php */
+class LanguageNlTest extends LanguageClassesTestCase {
+
+ /**
+ * @covers Language::formatNum
+ * @todo split into a test and a dataprovider
+ */
+ public function testFormatNum() {
+ $this->assertEquals( '1.234.567', $this->getLang()->formatNum( '1234567' ) );
+ $this->assertEquals( '12.345', $this->getLang()->formatNum( '12345' ) );
+ $this->assertEquals( '1', $this->getLang()->formatNum( '1' ) );
+ $this->assertEquals( '123', $this->getLang()->formatNum( '123' ) );
+ $this->assertEquals( '1.234', $this->getLang()->formatNum( '1234' ) );
+ $this->assertEquals( '12.345,56', $this->getLang()->formatNum( '12345.56' ) );
+ $this->assertEquals( ',1234556', $this->getLang()->formatNum( '.1234556' ) );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageNsoTest.php b/tests/phpunit/languages/LanguageNsoTest.php
new file mode 100644
index 00000000..18efd736
--- /dev/null
+++ b/tests/phpunit/languages/LanguageNsoTest.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageNso.php */
+class LanguageNsoTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguagePlTest.php b/tests/phpunit/languages/LanguagePlTest.php
new file mode 100644
index 00000000..d180037b
--- /dev/null
+++ b/tests/phpunit/languages/LanguagePlTest.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguagePl.php */
+class LanguagePlTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'many' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'few', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'many', 5 ),
+ array( 'many', 9 ),
+ array( 'many', 10 ),
+ array( 'many', 11 ),
+ array( 'many', 21 ),
+ array( 'few', 22 ),
+ array( 'few', 23 ),
+ array( 'few', 24 ),
+ array( 'many', 25 ),
+ array( 'many', 200 ),
+ array( 'many', 201 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 3 ),
+ array( 'other', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 9 ),
+ array( 'other', 10 ),
+ array( 'other', 11 ),
+ array( 'other', 21 ),
+ array( 'other', 22 ),
+ array( 'other', 23 ),
+ array( 'other', 24 ),
+ array( 'other', 25 ),
+ array( 'other', 200 ),
+ array( 'other', 201 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageRoTest.php b/tests/phpunit/languages/LanguageRoTest.php
new file mode 100644
index 00000000..ae7816bc
--- /dev/null
+++ b/tests/phpunit/languages/LanguageRoTest.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageRo.php */
+class LanguageRoTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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 ),
+ array( 'few', 2 ),
+ array( 'few', 19 ),
+ array( 'other', 20 ),
+ array( 'other', 99 ),
+ array( 'other', 100 ),
+ array( 'few', 101 ),
+ array( 'few', 119 ),
+ array( 'other', 120 ),
+ array( 'other', 200 ),
+ array( 'few', 201 ),
+ array( 'few', 219 ),
+ array( 'other', 220 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageRuTest.php b/tests/phpunit/languages/LanguageRuTest.php
new file mode 100644
index 00000000..e17c7085
--- /dev/null
+++ b/tests/phpunit/languages/LanguageRuTest.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * based on LanguageBe_tarask.php
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageRu.php */
+class LanguageRuTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'many', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * Test explicit plural forms - n=FormN forms
+ * @covers Language::convertPlural
+ */
+ public function testExplicitPlural() {
+ $forms = array( 'one','many', 'other', '12=dozen' );
+ $this->assertEquals( 'dozen', $this->getLang()->convertPlural( 12, $forms ) );
+ $forms = array( 'one', 'many', '100=hundred', 'other', '12=dozen' );
+ $this->assertEquals( 'hundred', $this->getLang()->convertPlural( 100, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 1 ),
+ array( 'many', 11 ),
+ array( 'one', 91 ),
+ array( 'one', 121 ),
+ array( 'other', 2 ),
+ array( 'other', 3 ),
+ array( 'other', 4 ),
+ array( 'other', 334 ),
+ array( 'many', 5 ),
+ array( 'many', 15 ),
+ array( 'many', 120 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( '1=one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'one', 1 ),
+ array( 'other', 11 ),
+ array( 'other', 91 ),
+ array( 'other', 121 ),
+ );
+ }
+
+ /**
+ * @dataProvider providerGrammar
+ * @covers Language::convertGrammar
+ */
+ public function testGrammar( $result, $word, $case ) {
+ $this->assertEquals( $result, $this->getLang()->convertGrammar( $word, $case ) );
+ }
+
+ public static function providerGrammar() {
+ return array(
+ array(
+ 'Википедии',
+ 'Википедия',
+ 'genitive',
+ ),
+ array(
+ 'Викитеки',
+ 'Викитека',
+ 'genitive',
+ ),
+ array(
+ 'Викитеке',
+ 'Викитека',
+ 'prepositional',
+ ),
+ array(
+ 'Викиданных',
+ 'Викиданные',
+ 'prepositional',
+ ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageSeTest.php b/tests/phpunit/languages/LanguageSeTest.php
new file mode 100644
index 00000000..533aa2bc
--- /dev/null
+++ b/tests/phpunit/languages/LanguageSeTest.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageSe.php */
+class LanguageSeTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'two', 2 ),
+ array( 'other', 3 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 3 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageSgsTest.php b/tests/phpunit/languages/LanguageSgsTest.php
new file mode 100644
index 00000000..fa49a4dd
--- /dev/null
+++ b/tests/phpunit/languages/LanguageSgsTest.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for Samogitian */
+class LanguageSgsTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePluralAllForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralAllForms( $result, $value ) {
+ $forms = array( 'one', 'two', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePluralAllForms
+ * @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 ),
+ array( 'two', 2 ),
+ array( 'other', 3 ),
+ array( 'few', 10 ),
+ array( 'few', 11 ),
+ array( 'few', 12 ),
+ array( 'few', 19 ),
+ array( 'other', 20 ),
+ array( 'few', 100 ),
+ array( 'one', 101 ),
+ array( 'few', 111 ),
+ array( 'few', 112 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 3 ),
+ array( 'other', 10 ),
+ array( 'other', 11 ),
+ array( 'other', 12 ),
+ array( 'other', 19 ),
+ array( 'other', 20 ),
+ array( 'other', 100 ),
+ array( 'one', 101 ),
+ array( 'other', 111 ),
+ array( 'other', 112 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageShTest.php b/tests/phpunit/languages/LanguageShTest.php
new file mode 100644
index 00000000..1b390872
--- /dev/null
+++ b/tests/phpunit/languages/LanguageShTest.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for srpskohrvatski / српскохрватски / Serbocroatian */
+class LanguageShTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'few', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 10 ),
+ array( 'other', 11 ),
+ array( 'other', 12 ),
+ array( 'one', 101 ),
+ array( 'few', 102 ),
+ array( 'other', 111 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageSkTest.php b/tests/phpunit/languages/LanguageSkTest.php
new file mode 100644
index 00000000..cb8a13b8
--- /dev/null
+++ b/tests/phpunit/languages/LanguageSkTest.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * based on LanguageSkTest.php
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageSk.php */
+class LanguageSkTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 11 ),
+ array( 'other', 20 ),
+ array( 'other', 25 ),
+ array( 'other', 200 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageSlTest.php b/tests/phpunit/languages/LanguageSlTest.php
new file mode 100644
index 00000000..9783dd80
--- /dev/null
+++ b/tests/phpunit/languages/LanguageSlTest.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * based on LanguageSkTest.php
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageSl.php */
+class LanguageSlTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providerPlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providerPlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providerPlural() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'two', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'other', 5 ),
+ array( 'other', 99 ),
+ array( 'other', 100 ),
+ array( 'one', 101 ),
+ array( 'two', 102 ),
+ array( 'few', 103 ),
+ array( 'one', 201 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageSmaTest.php b/tests/phpunit/languages/LanguageSmaTest.php
new file mode 100644
index 00000000..95cb333c
--- /dev/null
+++ b/tests/phpunit/languages/LanguageSmaTest.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageSma.php */
+class LanguageSmaTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'two', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider 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( 'two', 2 ),
+ array( 'other', 3 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'other', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ array( 'other', 3 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageSrTest.php b/tests/phpunit/languages/LanguageSrTest.php
new file mode 100644
index 00000000..d6fedb57
--- /dev/null
+++ b/tests/phpunit/languages/LanguageSrTest.php
@@ -0,0 +1,246 @@
+<?php
+/**
+ * PHPUnit tests for the Serbian language.
+ * The language can be represented using two scripts:
+ * - Latin (SR_el)
+ * - Cyrillic (SR_ec)
+ * Both representations seems to be bijective, hence MediaWiki can convert
+ * from one script to the other.
+ *
+ * @author Antoine Musso <hashar at free dot fr>
+ * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
+ * @file
+ *
+ * @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..
+ */
+
+/** Tests for MediaWiki languages/LanguageSr.php */
+class LanguageSrTest extends LanguageClassesTestCase {
+ /**
+ * @covers LanguageConverter::convertTo
+ */
+ public function testEasyConversions() {
+ $this->assertCyrillic(
+ 'шђчћжШЂЧЋЖ',
+ 'Cyrillic guessing characters'
+ );
+ $this->assertLatin(
+ 'šđč枊ĐČĆŽ',
+ 'Latin guessing characters'
+ );
+ }
+
+ /**
+ * @covers LanguageConverter::convertTo
+ */
+ public function testMixedConversions() {
+ $this->assertCyrillic(
+ 'шђчћжШЂЧЋЖ - šđčćž',
+ 'Mostly cyrillic characters'
+ );
+ $this->assertLatin(
+ 'šđč枊ĐČĆŽ - шђчћж',
+ 'Mostly latin characters'
+ );
+ }
+
+ /**
+ * @covers LanguageConverter::convertTo
+ */
+ public function testSameAmountOfLatinAndCyrillicGetConverted() {
+ $this->assertConverted(
+ '4 latin: šđčć | 4 cyrillic: шђчћ',
+ 'sr-ec'
+ );
+ $this->assertConverted(
+ '4 latin: šđčć | 4 cyrillic: шђчћ',
+ 'sr-el'
+ );
+ }
+
+ /**
+ * @author Nikola Smolenski
+ * @covers LanguageConverter::convertTo
+ */
+ public function testConversionToCyrillic() {
+ //A simple convertion of Latin to Cyrillic
+ $this->assertEquals( 'абвг',
+ $this->convertToCyrillic( 'abvg' )
+ );
+ //Same as above, but assert that -{}-s must be removed and not converted
+ $this->assertEquals( 'ljабnjвгdž',
+ $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
+ );
+ //A simple convertion of Cyrillic to Cyrillic
+ $this->assertEquals( 'абвг',
+ $this->convertToCyrillic( 'абвг' )
+ );
+ //Same as above, but assert that -{}-s must be removed and not converted
+ $this->assertEquals( 'ljабnjвгdž',
+ $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
+ );
+ //This text has some Latin, but is recognized as Cyrillic, so it should not be converted
+ $this->assertEquals( 'abvgшђжчћ',
+ $this->convertToCyrillic( 'abvgшђжчћ' )
+ );
+ //Same as above, but assert that -{}-s must be removed
+ $this->assertEquals( 'љabvgњшђжчћџ',
+ $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
+ );
+ //This text has some Cyrillic, but is recognized as Latin, so it should be converted
+ $this->assertEquals( 'абвгшђжчћ',
+ $this->convertToCyrillic( 'абвгšđžčć' )
+ );
+ //Same as above, but assert that -{}-s must be removed and not converted
+ $this->assertEquals( 'ljабвгnjшђжчћdž',
+ $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
+ );
+ // Roman numerals are not converted
+ $this->assertEquals( 'а I б II в III г IV шђжчћ',
+ $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
+ );
+ }
+
+ /**
+ * @covers LanguageConverter::convertTo
+ */
+ public function testConversionToLatin() {
+ //A simple convertion of Latin to Latin
+ $this->assertEquals( 'abcd',
+ $this->convertToLatin( 'abcd' )
+ );
+ //A simple convertion of Cyrillic to Latin
+ $this->assertEquals( 'abcd',
+ $this->convertToLatin( 'абцд' )
+ );
+ //This text has some Latin, but is recognized as Cyrillic, so it should be converted
+ $this->assertEquals( 'abcdšđžčć',
+ $this->convertToLatin( 'abcdшђжчћ' )
+ );
+ //This text has some Cyrillic, but is recognized as Latin, so it should not be converted
+ $this->assertEquals( 'абцдšđžčć',
+ $this->convertToLatin( 'абцдšđžčć' )
+ );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 1 ),
+ array( 'other', 11 ),
+ array( 'one', 91 ),
+ array( 'one', 121 ),
+ array( 'few', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'few', 334 ),
+ array( 'other', 5 ),
+ array( 'other', 15 ),
+ array( 'other', 120 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'one', 1 ),
+ array( 'other', 11 ),
+ array( 'other', 4 ),
+ array( 'one', 91 ),
+ array( 'one', 121 ),
+ );
+ }
+
+ ##### HELPERS #####################################################
+ /**
+ *Wrapper to verify text stay the same after applying conversion
+ * @param $text string Text to convert
+ * @param $variant string Language variant 'sr-ec' or 'sr-el'
+ * @param $msg string Optional message
+ */
+ protected function assertUnConverted( $text, $variant, $msg = '' ) {
+ $this->assertEquals(
+ $text,
+ $this->convertTo( $text, $variant ),
+ $msg
+ );
+ }
+
+ /**
+ * Wrapper to verify a text is different once converted to a variant.
+ * @param $text string Text to convert
+ * @param $variant string Language variant 'sr-ec' or 'sr-el'
+ * @param $msg string Optional message
+ */
+ protected function assertConverted( $text, $variant, $msg = '' ) {
+ $this->assertNotEquals(
+ $text,
+ $this->convertTo( $text, $variant ),
+ $msg
+ );
+ }
+
+ /**
+ * Verifiy the given Cyrillic text is not converted when using
+ * using the cyrillic variant and converted to Latin when using
+ * the Latin variant.
+ */
+ protected function assertCyrillic( $text, $msg = '' ) {
+ $this->assertUnConverted( $text, 'sr-ec', $msg );
+ $this->assertConverted( $text, 'sr-el', $msg );
+ }
+
+ /**
+ * Verifiy the given Latin text is not converted when using
+ * using the Latin variant and converted to Cyrillic when using
+ * the Cyrillic variant.
+ */
+ protected function assertLatin( $text, $msg = '' ) {
+ $this->assertUnConverted( $text, 'sr-el', $msg );
+ $this->assertConverted( $text, 'sr-ec', $msg );
+ }
+
+
+ /** Wrapper for converter::convertTo() method*/
+ protected function convertTo( $text, $variant ) {
+ return $this->getLang()
+ ->mConverter
+ ->convertTo(
+ $text, $variant
+ );
+ }
+
+ protected function convertToCyrillic( $text ) {
+ return $this->convertTo( $text, 'sr-ec' );
+ }
+
+ protected function convertToLatin( $text ) {
+ return $this->convertTo( $text, 'sr-el' );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php
new file mode 100644
index 00000000..78929e23
--- /dev/null
+++ b/tests/phpunit/languages/LanguageTest.php
@@ -0,0 +1,1567 @@
+<?php
+
+class LanguageTest extends LanguageClassesTestCase {
+ /**
+ * @covers Language::convertDoubleWidth
+ * @covers Language::normalizeForSearch
+ */
+ public function testLanguageConvertDoubleWidthToSingleWidth() {
+ $this->assertEquals(
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+ $this->getLang()->normalizeForSearch(
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+ ),
+ 'convertDoubleWidth() with the full alphabet and digits'
+ );
+ }
+
+ /**
+ * @dataProvider provideFormattableTimes#
+ * @covers Language::formatTimePeriod
+ */
+ public function testFormatTimePeriod( $seconds, $format, $expected, $desc ) {
+ $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc );
+ }
+
+ public static function provideFormattableTimes() {
+ return array(
+ array(
+ 9.45,
+ array(),
+ '9.5 s',
+ 'formatTimePeriod() rounding (<10s)'
+ ),
+ array(
+ 9.45,
+ array( 'noabbrevs' => true ),
+ '9.5 seconds',
+ 'formatTimePeriod() rounding (<10s)'
+ ),
+ array(
+ 9.95,
+ array(),
+ '10 s',
+ 'formatTimePeriod() rounding (<10s)'
+ ),
+ array(
+ 9.95,
+ array( 'noabbrevs' => true ),
+ '10 seconds',
+ 'formatTimePeriod() rounding (<10s)'
+ ),
+ array(
+ 59.55,
+ array(),
+ '1 min 0 s',
+ 'formatTimePeriod() rounding (<60s)'
+ ),
+ array(
+ 59.55,
+ array( 'noabbrevs' => true ),
+ '1 minute 0 seconds',
+ 'formatTimePeriod() rounding (<60s)'
+ ),
+ array(
+ 119.55,
+ array(),
+ '2 min 0 s',
+ 'formatTimePeriod() rounding (<1h)'
+ ),
+ array(
+ 119.55,
+ array( 'noabbrevs' => true ),
+ '2 minutes 0 seconds',
+ 'formatTimePeriod() rounding (<1h)'
+ ),
+ array(
+ 3599.55,
+ array(),
+ '1 h 0 min 0 s',
+ 'formatTimePeriod() rounding (<1h)'
+ ),
+ array(
+ 3599.55,
+ array( 'noabbrevs' => true ),
+ '1 hour 0 minutes 0 seconds',
+ 'formatTimePeriod() rounding (<1h)'
+ ),
+ array(
+ 7199.55,
+ array(),
+ '2 h 0 min 0 s',
+ 'formatTimePeriod() rounding (>=1h)'
+ ),
+ array(
+ 7199.55,
+ array( 'noabbrevs' => true ),
+ '2 hours 0 minutes 0 seconds',
+ 'formatTimePeriod() rounding (>=1h)'
+ ),
+ array(
+ 7199.55,
+ 'avoidseconds',
+ '2 h 0 min',
+ 'formatTimePeriod() rounding (>=1h), avoidseconds'
+ ),
+ array(
+ 7199.55,
+ array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
+ '2 hours 0 minutes',
+ 'formatTimePeriod() rounding (>=1h), avoidseconds'
+ ),
+ array(
+ 7199.55,
+ 'avoidminutes',
+ '2 h 0 min',
+ 'formatTimePeriod() rounding (>=1h), avoidminutes'
+ ),
+ array(
+ 7199.55,
+ array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ),
+ '2 hours 0 minutes',
+ 'formatTimePeriod() rounding (>=1h), avoidminutes'
+ ),
+ array(
+ 172799.55,
+ 'avoidseconds',
+ '48 h 0 min',
+ 'formatTimePeriod() rounding (=48h), avoidseconds'
+ ),
+ array(
+ 172799.55,
+ array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
+ '48 hours 0 minutes',
+ 'formatTimePeriod() rounding (=48h), avoidseconds'
+ ),
+ array(
+ 259199.55,
+ 'avoidminutes',
+ '3 d 0 h',
+ 'formatTimePeriod() rounding (>48h), avoidminutes'
+ ),
+ array(
+ 259199.55,
+ array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ),
+ '3 days 0 hours',
+ 'formatTimePeriod() rounding (>48h), avoidminutes'
+ ),
+ array(
+ 176399.55,
+ 'avoidseconds',
+ '2 d 1 h 0 min',
+ 'formatTimePeriod() rounding (>48h), avoidseconds'
+ ),
+ array(
+ 176399.55,
+ array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
+ '2 days 1 hour 0 minutes',
+ 'formatTimePeriod() rounding (>48h), avoidseconds'
+ ),
+ array(
+ 176399.55,
+ 'avoidminutes',
+ '2 d 1 h',
+ 'formatTimePeriod() rounding (>48h), avoidminutes'
+ ),
+ array(
+ 176399.55,
+ array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ),
+ '2 days 1 hour',
+ 'formatTimePeriod() rounding (>48h), avoidminutes'
+ ),
+ array(
+ 259199.55,
+ 'avoidseconds',
+ '3 d 0 h 0 min',
+ 'formatTimePeriod() rounding (>48h), avoidseconds'
+ ),
+ array(
+ 259199.55,
+ array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
+ '3 days 0 hours 0 minutes',
+ 'formatTimePeriod() rounding (>48h), avoidseconds'
+ ),
+ array(
+ 172801.55,
+ 'avoidseconds',
+ '2 d 0 h 0 min',
+ 'formatTimePeriod() rounding, (>48h), avoidseconds'
+ ),
+ array(
+ 172801.55,
+ array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ),
+ '2 days 0 hours 0 minutes',
+ 'formatTimePeriod() rounding, (>48h), avoidseconds'
+ ),
+ array(
+ 176460.55,
+ array(),
+ '2 d 1 h 1 min 1 s',
+ 'formatTimePeriod() rounding, recursion, (>48h)'
+ ),
+ array(
+ 176460.55,
+ array( 'noabbrevs' => true ),
+ '2 days 1 hour 1 minute 1 second',
+ 'formatTimePeriod() rounding, recursion, (>48h)'
+ ),
+ );
+ }
+
+ /**
+ * @covers Language::truncate
+ */
+ public function testTruncate() {
+ $this->assertEquals(
+ "XXX",
+ $this->getLang()->truncate( "1234567890", 0, 'XXX' ),
+ 'truncate prefix, len 0, small ellipsis'
+ );
+
+ $this->assertEquals(
+ "12345XXX",
+ $this->getLang()->truncate( "1234567890", 8, 'XXX' ),
+ 'truncate prefix, small ellipsis'
+ );
+
+ $this->assertEquals(
+ "123456789",
+ $this->getLang()->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ),
+ 'truncate prefix, large ellipsis'
+ );
+
+ $this->assertEquals(
+ "XXX67890",
+ $this->getLang()->truncate( "1234567890", -8, 'XXX' ),
+ 'truncate suffix, small ellipsis'
+ );
+
+ $this->assertEquals(
+ "123456789",
+ $this->getLang()->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ),
+ 'truncate suffix, large ellipsis'
+ );
+ }
+
+ /**
+ * @dataProvider provideHTMLTruncateData
+ * @covers Language::truncateHTML
+ */
+ public function testTruncateHtml( $len, $ellipsis, $input, $expected ) {
+ // Actual HTML...
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->truncateHTML( $input, $len, $ellipsis )
+ );
+ }
+
+ /**
+ * @return array format is ($len, $ellipsis, $input, $expected)
+ */
+ public static function provideHTMLTruncateData() {
+ return array(
+ array( 0, 'XXX', "1234567890", "XXX" ),
+ array( 8, 'XXX', "1234567890", "12345XXX" ),
+ array( 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ),
+ array( 2, '***',
+ '<p><span style="font-weight:bold;"></span></p>',
+ '<p><span style="font-weight:bold;"></span></p>',
+ ),
+ array( 2, '***',
+ '<p><span style="font-weight:bold;">123456789</span></p>',
+ '<p><span style="font-weight:bold;">***</span></p>',
+ ),
+ array( 2, '***',
+ '<p><span style="font-weight:bold;">&nbsp;23456789</span></p>',
+ '<p><span style="font-weight:bold;">***</span></p>',
+ ),
+ array( 3, '***',
+ '<p><span style="font-weight:bold;">123456789</span></p>',
+ '<p><span style="font-weight:bold;">***</span></p>',
+ ),
+ array( 4, '***',
+ '<p><span style="font-weight:bold;">123456789</span></p>',
+ '<p><span style="font-weight:bold;">1***</span></p>',
+ ),
+ array( 5, '***',
+ '<tt><span style="font-weight:bold;">123456789</span></tt>',
+ '<tt><span style="font-weight:bold;">12***</span></tt>',
+ ),
+ array( 6, '***',
+ '<p><a href="www.mediawiki.org">123456789</a></p>',
+ '<p><a href="www.mediawiki.org">123***</a></p>',
+ ),
+ array( 6, '***',
+ '<p><a href="www.mediawiki.org">12&nbsp;456789</a></p>',
+ '<p><a href="www.mediawiki.org">12&nbsp;***</a></p>',
+ ),
+ array( 7, '***',
+ '<small><span style="font-weight:bold;">123<p id="#moo">456</p>789</span></small>',
+ '<small><span style="font-weight:bold;">123<p id="#moo">4***</p></span></small>',
+ ),
+ array( 8, '***',
+ '<div><span style="font-weight:bold;">123<span>4</span>56789</span></div>',
+ '<div><span style="font-weight:bold;">123<span>4</span>5***</span></div>',
+ ),
+ array( 9, '***',
+ '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
+ '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
+ ),
+ array( 10, '***',
+ '<p><font style="font-weight:bold;">123456789</font></p>',
+ '<p><font style="font-weight:bold;">123456789</font></p>',
+ ),
+ );
+ }
+
+ /**
+ * Test Language::isWellFormedLanguageTag()
+ * @dataProvider provideWellFormedLanguageTags
+ * @covers Language::isWellFormedLanguageTag
+ */
+ public function testWellFormedLanguageTag( $code, $message = '' ) {
+ $this->assertTrue(
+ Language::isWellFormedLanguageTag( $code ),
+ "validating code $code $message"
+ );
+ }
+
+ /**
+ * The test cases are based on the tests in the GaBuZoMeu parser
+ * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr>
+ * and distributed as free software, under the GNU General Public Licence.
+ * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html
+ */
+ public static function provideWellFormedLanguageTags() {
+ return array(
+ array( 'fr', 'two-letter code' ),
+ array( 'fr-latn', 'two-letter code with lower case script code' ),
+ array( 'fr-Latn-FR', 'two-letter code with title case script code and uppercase country code' ),
+ array( 'fr-Latn-419', 'two-letter code with title case script code and region number' ),
+ array( 'fr-FR', 'two-letter code with uppercase' ),
+ array( 'ax-TZ', 'Not in the registry, but well-formed' ),
+ array( 'fr-shadok', 'two-letter code with variant' ),
+ array( 'fr-y-myext-myext2', 'non-x singleton' ),
+ array( 'fra-Latn', 'ISO 639 can be 3-letters' ),
+ array( 'fra', 'three-letter language code' ),
+ array( 'fra-FX', 'three-letter language code with country code' ),
+ array( 'i-klingon', 'grandfathered with singleton' ),
+ array( 'I-kLINgon', 'tags are case-insensitive...' ),
+ array( 'no-bok', 'grandfathered without singleton' ),
+ array( 'i-enochian', 'Grandfathered' ),
+ array( 'x-fr-CH', 'private use' ),
+ array( 'es-419', 'two-letter code with region number' ),
+ array( 'en-Latn-GB-boont-r-extended-sequence-x-private', 'weird, but well-formed' ),
+ array( 'ab-x-abc-x-abc', 'anything goes after x' ),
+ array( 'ab-x-abc-a-a', 'anything goes after x, including several non-x singletons' ),
+ array( 'i-default', 'grandfathered' ),
+ array( 'abcd-Latn', 'Language of 4 chars reserved for future use' ),
+ array( 'AaBbCcDd-x-y-any-x', 'Language of 5-8 chars, registered' ),
+ array( 'de-CH-1901', 'with country and year' ),
+ array( 'en-US-x-twain', 'with country and singleton' ),
+ array( 'zh-cmn', 'three-letter variant' ),
+ array( 'zh-cmn-Hant', 'three-letter variant and script' ),
+ array( 'zh-cmn-Hant-HK', 'three-letter variant, script and country' ),
+ array( 'xr-p-lze', 'Extension' ),
+ );
+ }
+
+ /**
+ * Negative test for Language::isWellFormedLanguageTag()
+ * @dataProvider provideMalformedLanguageTags
+ * @covers Language::isWellFormedLanguageTag
+ */
+ public function testMalformedLanguageTag( $code, $message = '' ) {
+ $this->assertFalse(
+ Language::isWellFormedLanguageTag( $code ),
+ "validating that code $code is a malformed language tag - $message"
+ );
+ }
+
+ /**
+ * The test cases are based on the tests in the GaBuZoMeu parser
+ * written by Stéphane Bortzmeyer <bortzmeyer@nic.fr>
+ * and distributed as free software, under the GNU General Public Licence.
+ * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html
+ */
+ public static function provideMalformedLanguageTags() {
+ return array(
+ array( 'f', 'language too short' ),
+ array( 'f-Latn', 'language too short with script' ),
+ array( 'xr-lxs-qut', 'variants too short' ), # extlangS
+ array( 'fr-Latn-F', 'region too short' ),
+ array( 'a-value', 'language too short with region' ),
+ array( 'tlh-a-b-foo', 'valid three-letter with wrong variant' ),
+ array( 'i-notexist', 'grandfathered but not registered: invalid, even if we only test well-formedness' ),
+ array( 'abcdefghi-012345678', 'numbers too long' ),
+ array( 'ab-abc-abc-abc-abc', 'invalid extensions' ),
+ array( 'ab-abcd-abc', 'invalid extensions' ),
+ array( 'ab-ab-abc', 'invalid extensions' ),
+ array( 'ab-123-abc', 'invalid extensions' ),
+ array( 'a-Hant-ZH', 'short language with valid extensions' ),
+ array( 'a1-Hant-ZH', 'invalid character in language' ),
+ array( 'ab-abcde-abc', 'invalid extensions' ),
+ array( 'ab-1abc-abc', 'invalid characters in extensions' ),
+ array( 'ab-ab-abcd', 'invalid order of extensions' ),
+ array( 'ab-123-abcd', 'invalid order of extensions' ),
+ array( 'ab-abcde-abcd', 'invalid extensions' ),
+ array( 'ab-1abc-abcd', 'invalid characters in extensions' ),
+ array( 'ab-a-b', 'extensions too short' ),
+ array( 'ab-a-x', 'extensions too short, even with singleton' ),
+ array( 'ab--ab', 'two separators' ),
+ array( 'ab-abc-', 'separator in the end' ),
+ array( '-ab-abc', 'separator in the beginning' ),
+ array( 'abcd-efg', 'language too long' ),
+ array( 'aabbccddE', 'tag too long' ),
+ array( 'pa_guru', 'A tag with underscore is invalid in strict mode' ),
+ array( 'de-f', 'subtag too short' ),
+ );
+ }
+
+ /**
+ * Negative test for Language::isWellFormedLanguageTag()
+ * @covers Language::isWellFormedLanguageTag
+ */
+ public function testLenientLanguageTag() {
+ $this->assertTrue(
+ Language::isWellFormedLanguageTag( 'pa_guru', true ),
+ 'pa_guru is a well-formed language tag in lenient mode'
+ );
+ }
+
+ /**
+ * Test Language::isValidBuiltInCode()
+ * @dataProvider provideLanguageCodes
+ * @covers Language::isValidBuiltInCode
+ */
+ public function testBuiltInCodeValidation( $code, $message = '' ) {
+ $this->assertTrue(
+ (bool)Language::isValidBuiltInCode( $code ),
+ "validating code $code $message"
+ );
+ }
+
+ /**
+ * @covers Language::isValidBuiltInCode
+ */
+ public function testBuiltInCodeValidationRejectUnderscore() {
+ $this->assertFalse(
+ (bool)Language::isValidBuiltInCode( 'be_tarask' ),
+ "reject underscore in language code"
+ );
+ }
+
+ public static function provideLanguageCodes() {
+ return array(
+ array( 'fr', 'Two letters, minor case' ),
+ array( 'EN', 'Two letters, upper case' ),
+ array( 'tyv', 'Three letters' ),
+ array( 'tokipona', 'long language code' ),
+ array( 'be-tarask', 'With dash' ),
+ array( 'Zh-classical', 'Begin with upper case, dash' ),
+ array( 'Be-x-old', 'With extension (two dashes)' ),
+ );
+ }
+
+ /**
+ * Test Language::isKnownLanguageTag()
+ * @dataProvider provideKnownLanguageTags
+ * @covers Language::isKnownLanguageTag
+ */
+ public function testKnownLanguageTag( $code, $message = '' ) {
+ $this->assertTrue(
+ (bool)Language::isKnownLanguageTag( $code ),
+ "validating code $code - $message"
+ );
+ }
+
+ public static function provideKnownLanguageTags() {
+ return array(
+ array( 'fr', 'simple code' ),
+ array( 'bat-smg', 'an MW legacy tag' ),
+ array( 'sgs', 'an internal standard MW name, for which a legacy tag is used externally' ),
+ );
+ }
+
+ /**
+ * @covers Language::isKnownLanguageTag
+ */
+ public function testKnownCldrLanguageTag() {
+ if ( !class_exists( 'LanguageNames' ) ) {
+ $this->markTestSkipped( 'The LanguageNames class is not available. The cldr extension is probably not installed.' );
+ }
+
+ $this->assertTrue(
+ (bool)Language::isKnownLanguageTag( 'pal' ),
+ 'validating code "pal" an ancient language, which probably will not appear in Names.php, but appears in CLDR in English'
+ );
+ }
+
+ /**
+ * Negative tests for Language::isKnownLanguageTag()
+ * @dataProvider provideUnKnownLanguageTags
+ * @covers Language::isKnownLanguageTag
+ */
+ public function testUnknownLanguageTag( $code, $message = '' ) {
+ $this->assertFalse(
+ (bool)Language::isKnownLanguageTag( $code ),
+ "checking that code $code is invalid - $message"
+ );
+ }
+
+ public static function provideUnknownLanguageTags() {
+ return array(
+ array( 'mw', 'non-existent two-letter code' ),
+ array( 'foo"<bar', 'very invalid language code' ),
+ );
+ }
+
+ /**
+ * Test too short timestamp
+ * @expectedException MWException
+ * @covers Language::sprintfDate
+ */
+ public function testSprintfDateTooShortTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '1234567890123' );
+ }
+
+ /**
+ * Test too long timestamp
+ * @expectedException MWException
+ * @covers Language::sprintfDate
+ */
+ public function testSprintfDateTooLongTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '123456789012345' );
+ }
+
+ /**
+ * Test too short timestamp
+ * @expectedException MWException
+ * @covers Language::sprintfDate
+ */
+ public function testSprintfDateNotAllDigitTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '-1234567890123' );
+ }
+
+ /**
+ * @dataProvider provideSprintfDateSamples
+ * @covers Language::sprintfDate
+ */
+ public function testSprintfDate( $format, $ts, $expected, $msg ) {
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->sprintfDate( $format, $ts ),
+ "sprintfDate('$format', '$ts'): $msg"
+ );
+ }
+
+ /**
+ * sprintfDate should always use UTC when no zone is given.
+ * @dataProvider provideSprintfDateSamples
+ * @covers Language::sprintfDate
+ */
+ public function testSprintfDateNoZone( $format, $ts, $expected, $ignore, $msg ) {
+ $oldTZ = date_default_timezone_get();
+ $res = date_default_timezone_set( 'Asia/Seoul' );
+ if ( !$res ) {
+ $this->markTestSkipped( "Error setting Timezone" );
+ }
+
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->sprintfDate( $format, $ts ),
+ "sprintfDate('$format', '$ts'): $msg"
+ );
+
+ date_default_timezone_set( $oldTZ );
+ }
+
+ /**
+ * 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
+ array(
+ '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'
+ ),
+
+ );
+ }
+
+ /**
+ * @dataProvider provideFormatSizes
+ * @covers Language::formatSize
+ */
+ public function testFormatSize( $size, $expected, $msg ) {
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->formatSize( $size ),
+ "formatSize('$size'): $msg"
+ );
+ }
+
+ public static function provideFormatSizes() {
+ return array(
+ array(
+ 0,
+ "0 B",
+ "Zero bytes"
+ ),
+ array(
+ 1024,
+ "1 KB",
+ "1 kilobyte"
+ ),
+ array(
+ 1024 * 1024,
+ "1 MB",
+ "1,024 megabytes"
+ ),
+ array(
+ 1024 * 1024 * 1024,
+ "1 GB",
+ "1 gigabytes"
+ ),
+ array(
+ pow( 1024, 4 ),
+ "1 TB",
+ "1 terabyte"
+ ),
+ array(
+ pow( 1024, 5 ),
+ "1 PB",
+ "1 petabyte"
+ ),
+ array(
+ pow( 1024, 6 ),
+ "1 EB",
+ "1,024 exabyte"
+ ),
+ array(
+ pow( 1024, 7 ),
+ "1 ZB",
+ "1 zetabyte"
+ ),
+ array(
+ pow( 1024, 8 ),
+ "1 YB",
+ "1 yottabyte"
+ ),
+ // How big!? THIS BIG!
+ );
+ }
+
+ /**
+ * @dataProvider provideFormatBitrate
+ * @covers Language::formatBitrate
+ */
+ public function testFormatBitrate( $bps, $expected, $msg ) {
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->formatBitrate( $bps ),
+ "formatBitrate('$bps'): $msg"
+ );
+ }
+
+ public static function provideFormatBitrate() {
+ return array(
+ array(
+ 0,
+ "0 bps",
+ "0 bits per second"
+ ),
+ array(
+ 999,
+ "999 bps",
+ "999 bits per second"
+ ),
+ array(
+ 1000,
+ "1 kbps",
+ "1 kilobit per second"
+ ),
+ array(
+ 1000 * 1000,
+ "1 Mbps",
+ "1 megabit per second"
+ ),
+ array(
+ pow( 10, 9 ),
+ "1 Gbps",
+ "1 gigabit per second"
+ ),
+ array(
+ pow( 10, 12 ),
+ "1 Tbps",
+ "1 terabit per second"
+ ),
+ array(
+ pow( 10, 15 ),
+ "1 Pbps",
+ "1 petabit per second"
+ ),
+ array(
+ pow( 10, 18 ),
+ "1 Ebps",
+ "1 exabit per second"
+ ),
+ array(
+ pow( 10, 21 ),
+ "1 Zbps",
+ "1 zetabit per second"
+ ),
+ array(
+ pow( 10, 24 ),
+ "1 Ybps",
+ "1 yottabit per second"
+ ),
+ array(
+ pow( 10, 27 ),
+ "1,000 Ybps",
+ "1,000 yottabits per second"
+ ),
+ );
+ }
+
+
+ /**
+ * @dataProvider provideFormatDuration
+ * @covers Language::formatDuration
+ */
+ public function testFormatDuration( $duration, $expected, $intervals = array() ) {
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->formatDuration( $duration, $intervals ),
+ "formatDuration('$duration'): $expected"
+ );
+ }
+
+ public static function provideFormatDuration() {
+ return array(
+ array(
+ 0,
+ '0 seconds',
+ ),
+ array(
+ 1,
+ '1 second',
+ ),
+ array(
+ 2,
+ '2 seconds',
+ ),
+ array(
+ 60,
+ '1 minute',
+ ),
+ array(
+ 2 * 60,
+ '2 minutes',
+ ),
+ array(
+ 3600,
+ '1 hour',
+ ),
+ array(
+ 2 * 3600,
+ '2 hours',
+ ),
+ array(
+ 24 * 3600,
+ '1 day',
+ ),
+ array(
+ 2 * 86400,
+ '2 days',
+ ),
+ array(
+ // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952
+ ( 365 + ( 24 * 3 + 25 ) / 400.0 ) * 86400,
+ '1 year',
+ ),
+ array(
+ 2 * 31556952,
+ '2 years',
+ ),
+ array(
+ 10 * 31556952,
+ '1 decade',
+ ),
+ array(
+ 20 * 31556952,
+ '2 decades',
+ ),
+ array(
+ 100 * 31556952,
+ '1 century',
+ ),
+ array(
+ 200 * 31556952,
+ '2 centuries',
+ ),
+ array(
+ 1000 * 31556952,
+ '1 millennium',
+ ),
+ array(
+ 2000 * 31556952,
+ '2 millennia',
+ ),
+ array(
+ 9001,
+ '2 hours, 30 minutes and 1 second'
+ ),
+ array(
+ 3601,
+ '1 hour and 1 second'
+ ),
+ array(
+ 31556952 + 2 * 86400 + 9000,
+ '1 year, 2 days, 2 hours and 30 minutes'
+ ),
+ array(
+ 42 * 1000 * 31556952 + 42,
+ '42 millennia and 42 seconds'
+ ),
+ array(
+ 60,
+ '60 seconds',
+ array( 'seconds' ),
+ ),
+ array(
+ 61,
+ '61 seconds',
+ array( 'seconds' ),
+ ),
+ array(
+ 1,
+ '1 second',
+ array( 'seconds' ),
+ ),
+ array(
+ 31556952 + 2 * 86400 + 9000,
+ '1 year, 2 days and 150 minutes',
+ array( 'years', 'days', 'minutes' ),
+ ),
+ array(
+ 42,
+ '0 days',
+ array( 'years', 'days' ),
+ ),
+ array(
+ 31556952 + 2 * 86400 + 9000,
+ '1 year, 2 days and 150 minutes',
+ array( 'minutes', 'days', 'years' ),
+ ),
+ array(
+ 42,
+ '0 days',
+ array( 'days', 'years' ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideCheckTitleEncodingData
+ * @covers Language::checkTitleEncoding
+ */
+ public function testCheckTitleEncoding( $s ) {
+ $this->assertEquals(
+ $s,
+ $this->getLang()->checkTitleEncoding( $s ),
+ "checkTitleEncoding('$s')"
+ );
+ }
+
+ public static function provideCheckTitleEncodingData() {
+ return array(
+ array( "" ),
+ array( "United States of America" ), // 7bit ASCII
+ array( rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ),
+ array(
+ rawurldecode(
+ "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn"
+ )
+ ),
+ // The following two data sets come from bug 36839. They fail if checkTitleEncoding uses a regexp to test for
+ // valid UTF-8 encoding and the pcre.recursion_limit is low (like, say, 1024). They succeed if checkTitleEncoding
+ // uses mb_check_encoding for its test.
+ array(
+ rawurldecode(
+ "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn%7C"
+ . "Catherine%20Willows%7CDavid%20Hodges%7CDavid%20Phillips%7CGil%20Grissom%7CGreg%20Sanders%7CHodges%7C"
+ . "Internet%20Movie%20Database%7CJim%20Brass%7CLady%20Heather%7C"
+ . "Les%20Experts%20(s%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e)%7CLes%20Experts%20:%20Manhattan%7C"
+ . "Les%20Experts%20:%20Miami%7CListe%20des%20personnages%20des%20Experts%7C"
+ . "Liste%20des%20%C3%A9pisodes%20des%20Experts%7CMod%C3%A8le%20discussion:Palette%20Les%20Experts%7C"
+ . "Nick%20Stokes%7CPersonnage%20de%20fiction%7CPersonnage%20fictif%7CPersonnage%20de%20fiction%7C"
+ . "Personnages%20r%C3%A9currents%20dans%20Les%20Experts%7CRaymond%20Langston%7CRiley%20Adams%7C"
+ . "Saison%201%20des%20Experts%7CSaison%2010%20des%20Experts%7CSaison%2011%20des%20Experts%7C"
+ . "Saison%2012%20des%20Experts%7CSaison%202%20des%20Experts%7CSaison%203%20des%20Experts%7C"
+ . "Saison%204%20des%20Experts%7CSaison%205%20des%20Experts%7CSaison%206%20des%20Experts%7C"
+ . "Saison%207%20des%20Experts%7CSaison%208%20des%20Experts%7CSaison%209%20des%20Experts%7C"
+ . "Sara%20Sidle%7CSofia%20Curtis%7CS%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e%7CWallace%20Langham%7C"
+ . "Warrick%20Brown%7CWendy%20Simms%7C%C3%89tats-Unis"
+ ),
+ ),
+ array(
+ rawurldecode(
+ "Mod%C3%A8le%3AArrondissements%20homonymes%7CMod%C3%A8le%3ABandeau%20standard%20pour%20page%20d'homonymie%7C"
+ . "Mod%C3%A8le%3ABatailles%20homonymes%7CMod%C3%A8le%3ACantons%20homonymes%7C"
+ . "Mod%C3%A8le%3ACommunes%20fran%C3%A7aises%20homonymes%7CMod%C3%A8le%3AFilms%20homonymes%7C"
+ . "Mod%C3%A8le%3AGouvernements%20homonymes%7CMod%C3%A8le%3AGuerres%20homonymes%7CMod%C3%A8le%3AHomonymie%7C"
+ . "Mod%C3%A8le%3AHomonymie%20bateau%7CMod%C3%A8le%3AHomonymie%20d'%C3%A9tablissements%20scolaires%20ou"
+ . "%20universitaires%7CMod%C3%A8le%3AHomonymie%20d'%C3%AEles%7CMod%C3%A8le%3AHomonymie%20de%20clubs%20sportifs%7C"
+ . "Mod%C3%A8le%3AHomonymie%20de%20comt%C3%A9s%7CMod%C3%A8le%3AHomonymie%20de%20monument%7C"
+ . "Mod%C3%A8le%3AHomonymie%20de%20nom%20romain%7CMod%C3%A8le%3AHomonymie%20de%20parti%20politique%7C"
+ . "Mod%C3%A8le%3AHomonymie%20de%20route%7CMod%C3%A8le%3AHomonymie%20dynastique%7C"
+ . "Mod%C3%A8le%3AHomonymie%20vid%C3%A9oludique%7CMod%C3%A8le%3AHomonymie%20%C3%A9difice%20religieux%7C"
+ . "Mod%C3%A8le%3AInternationalisation%7CMod%C3%A8le%3AIsom%C3%A9rie%7CMod%C3%A8le%3AParonymie%7C"
+ . "Mod%C3%A8le%3APatronyme%7CMod%C3%A8le%3APatronyme%20basque%7CMod%C3%A8le%3APatronyme%20italien%7C"
+ . "Mod%C3%A8le%3APatronymie%7CMod%C3%A8le%3APersonnes%20homonymes%7CMod%C3%A8le%3ASaints%20homonymes%7C"
+ . "Mod%C3%A8le%3ATitres%20homonymes%7CMod%C3%A8le%3AToponymie%7CMod%C3%A8le%3AUnit%C3%A9s%20homonymes%7C"
+ . "Mod%C3%A8le%3AVilles%20homonymes%7CMod%C3%A8le%3A%C3%89difices%20religieux%20homonymes"
+ )
+ )
+ );
+ }
+
+ /**
+ * @dataProvider provideRomanNumeralsData
+ * @covers Language::romanNumeral
+ */
+ public function testRomanNumerals( $num, $numerals ) {
+ $this->assertEquals(
+ $numerals,
+ Language::romanNumeral( $num ),
+ "romanNumeral('$num')"
+ );
+ }
+
+ public static function provideRomanNumeralsData() {
+ return array(
+ array( 1, 'I' ),
+ array( 2, 'II' ),
+ array( 3, 'III' ),
+ array( 4, 'IV' ),
+ array( 5, 'V' ),
+ array( 6, 'VI' ),
+ array( 7, 'VII' ),
+ array( 8, 'VIII' ),
+ array( 9, 'IX' ),
+ array( 10, 'X' ),
+ array( 20, 'XX' ),
+ array( 30, 'XXX' ),
+ array( 40, 'XL' ),
+ array( 49, 'XLIX' ),
+ array( 50, 'L' ),
+ array( 60, 'LX' ),
+ array( 70, 'LXX' ),
+ array( 80, 'LXXX' ),
+ array( 90, 'XC' ),
+ array( 99, 'XCIX' ),
+ array( 100, 'C' ),
+ array( 200, 'CC' ),
+ array( 300, 'CCC' ),
+ array( 400, 'CD' ),
+ array( 500, 'D' ),
+ array( 600, 'DC' ),
+ array( 700, 'DCC' ),
+ array( 800, 'DCCC' ),
+ array( 900, 'CM' ),
+ array( 999, 'CMXCIX' ),
+ array( 1000, 'M' ),
+ array( 1989, 'MCMLXXXIX' ),
+ array( 2000, 'MM' ),
+ array( 3000, 'MMM' ),
+ array( 4000, 'MMMM' ),
+ array( 5000, 'MMMMM' ),
+ array( 6000, 'MMMMMM' ),
+ array( 7000, 'MMMMMMM' ),
+ array( 8000, 'MMMMMMMM' ),
+ array( 9000, 'MMMMMMMMM' ),
+ array( 9999, 'MMMMMMMMMCMXCIX' ),
+ array( 10000, 'MMMMMMMMMM' ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralData
+ * @covers Language::convertPlural
+ */
+ public function testConvertPlural( $expected, $number, $forms ) {
+ $chosen = $this->getLang()->convertPlural( $number, $forms );
+ $this->assertEquals( $expected, $chosen );
+ }
+
+ public static function providePluralData() {
+ // Params are: [expected text, number given, [the plural forms]]
+ return array(
+ array( 'plural', 0, array(
+ 'singular', 'plural'
+ ) ),
+ array( 'explicit zero', 0, array(
+ '0=explicit zero', 'singular', 'plural'
+ ) ),
+ array( 'explicit one', 1, array(
+ 'singular', 'plural', '1=explicit one',
+ ) ),
+ array( 'singular', 1, array(
+ 'singular', 'plural', '0=explicit zero',
+ ) ),
+ array( 'plural', 3, array(
+ '0=explicit zero', '1=explicit one', 'singular', 'plural'
+ ) ),
+ array( 'explicit eleven', 11, array(
+ 'singular', 'plural', '11=explicit eleven',
+ ) ),
+ array( 'plural', 12, array(
+ 'singular', 'plural', '11=explicit twelve',
+ ) ),
+ array( 'plural', 12, array(
+ 'singular', 'plural', '=explicit form',
+ ) ),
+ array( 'other', 2, array(
+ 'kissa=kala', '1=2=3', 'other',
+ ) ),
+ array( '', 2, array(
+ '0=explicit zero', '1=explicit one',
+ ) ),
+ );
+ }
+
+ /**
+ * @covers Language::translateBlockExpiry()
+ * @dataProvider provideTranslateBlockExpiry
+ */
+ public function testTranslateBlockExpiry( $expectedData, $str, $desc ) {
+ $lang = $this->getLang();
+ if ( is_array( $expectedData ) ) {
+ list( $func, $arg ) = $expectedData;
+ $expected = $lang->$func( $arg );
+ } else {
+ $expected = $expectedData;
+ }
+ $this->assertEquals( $expected, $lang->translateBlockExpiry( $str ), $desc );
+ }
+
+ public static function provideTranslateBlockExpiry() {
+ return array(
+ array( '2 hours', '2 hours', 'simple data from ipboptions' ),
+ array( 'indefinite', 'infinite', 'infinite from ipboptions' ),
+ array( 'indefinite', 'infinity', 'alternative infinite from ipboptions' ),
+ array( 'indefinite', 'indefinite', 'another alternative infinite from ipboptions' ),
+ array( array( 'formatDuration', 1023 * 60 * 60 ), '1023 hours', 'relative' ),
+ array( array( 'formatDuration', -1023 ), '-1023 seconds', 'negative relative' ),
+ array( array( 'formatDuration', 0 ), 'now', 'now' ),
+ array( array( 'timeanddate', '20120102070000' ), '2012-1-1 7:00 +1 day', 'mixed, handled as absolute' ),
+ array( array( 'timeanddate', '19910203040506' ), '1991-2-3 4:05:06', 'absolute' ),
+ array( array( 'timeanddate', '19700101000000' ), '1970-1-1 0:00:00', 'absolute at epoch' ),
+ array( array( 'timeanddate', '19691231235959' ), '1969-12-31 23:59:59', 'time before epoch' ),
+ array( 'dummy', 'dummy', 'return garbage as is' ),
+ );
+ }
+
+ /**
+ * @covers Language::commafy()
+ * @dataProvider provideCommafyData
+ */
+ public function testCommafy( $number, $numbersWithCommas ) {
+ $this->assertEquals(
+ $numbersWithCommas,
+ $this->getLang()->commafy( $number ),
+ "commafy('$number')"
+ );
+ }
+
+ public static function provideCommafyData() {
+ return array(
+ array( 1, '1' ),
+ array( 10, '10' ),
+ array( 100, '100' ),
+ array( 1000, '1,000' ),
+ array( 10000, '10,000' ),
+ array( 100000, '100,000' ),
+ array( 1000000, '1,000,000' ),
+ array( 1.0001, '1.0001' ),
+ array( 10.0001, '10.0001' ),
+ array( 100.0001, '100.0001' ),
+ array( 1000.0001, '1,000.0001' ),
+ array( 10000.0001, '10,000.0001' ),
+ array( 100000.0001, '100,000.0001' ),
+ array( 1000000.0001, '1,000,000.0001' ),
+ );
+ }
+
+ /**
+ * @covers Language::listToText
+ */
+ public function testListToText() {
+ $lang = $this->getLang();
+ $and = $lang->getMessageFromDB( 'and' );
+ $s = $lang->getMessageFromDB( 'word-separator' );
+ $c = $lang->getMessageFromDB( 'comma-separator' );
+
+ $this->assertEquals( '', $lang->listToText( array() ) );
+ $this->assertEquals( 'a', $lang->listToText( array( 'a' ) ) );
+ $this->assertEquals( "a{$and}{$s}b", $lang->listToText( array( 'a', 'b' ) ) );
+ $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( array( 'a', 'b', 'c' ) ) );
+ $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( array( 'a', 'b', 'c', 'd' ) ) );
+ }
+
+ /**
+ * @dataProvider provideIsSupportedLanguage
+ * @covers Language::isSupportedLanguage
+ */
+ public function testIsSupportedLanguage( $code, $expected, $comment ) {
+ $this->assertEquals( $expected, Language::isSupportedLanguage( $code ), $comment );
+ }
+
+ public static function provideIsSupportedLanguage() {
+ return array(
+ array( 'en', true, 'is supported language' ),
+ array( 'fi', true, 'is supported language' ),
+ array( 'bunny', false, 'is not supported language' ),
+ array( 'FI', false, 'is not supported language, input should be in lower case' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetParentLanguage
+ * @covers Language::getParentLanguage
+ */
+ public function testGetParentLanguage( $code, $expected, $comment ) {
+ $lang = Language::factory( $code );
+ if ( is_null( $expected ) ) {
+ $this->assertNull( $lang->getParentLanguage(), $comment );
+ } else {
+ $this->assertEquals( $expected, $lang->getParentLanguage()->getCode(), $comment );
+ }
+ }
+
+ public static function provideGetParentLanguage() {
+ return array(
+ array( 'zh-cn', 'zh', 'zh is the parent language of zh-cn' ),
+ array( 'zh', 'zh', 'zh is defined as the parent language of zh, because zh converter can convert zh-cn to zh' ),
+ array( 'zh-invalid', null, 'do not be fooled by arbitrarily composed language codes' ),
+ array( 'en-gb', null, 'en does not have converter' ),
+ array( 'en', null, 'en does not have converter. Although FakeConverter handles en -> en conversion but it is useless' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetNamespaceAliases
+ * @covers Language::getNamespaceAliases
+ */
+ public function testGetNamespaceAliases( $languageCode, $subset ) {
+ $language = Language::factory( $languageCode );
+ $aliases = $language->getNamespaceAliases();
+ foreach ( $subset as $alias => $nsId ) {
+ $this->assertEquals( $nsId, $aliases[$alias] );
+ }
+ }
+
+ public static function provideGetNamespaceAliases() {
+ // TODO: Add tests for NS_PROJECT_TALK and GenderNamespaces
+ return array(
+ array(
+ 'zh',
+ array(
+ '文件' => NS_FILE,
+ '檔案' => NS_FILE,
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageTiTest.php b/tests/phpunit/languages/LanguageTiTest.php
new file mode 100644
index 00000000..e225af97
--- /dev/null
+++ b/tests/phpunit/languages/LanguageTiTest.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageTi.php */
+class LanguageTiTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageTlTest.php b/tests/phpunit/languages/LanguageTlTest.php
new file mode 100644
index 00000000..7ac51c69
--- /dev/null
+++ b/tests/phpunit/languages/LanguageTlTest.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageTl.php */
+class LanguageTlTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageTrTest.php b/tests/phpunit/languages/LanguageTrTest.php
new file mode 100644
index 00000000..8fc2795c
--- /dev/null
+++ b/tests/phpunit/languages/LanguageTrTest.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * @author Antoine Musso
+ * @copyright Copyright © 2011, Antoine Musso
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageTr.php */
+class LanguageTrTest extends LanguageClassesTestCase {
+
+ /**
+ * See @bug 28040
+ * Credits to irc://irc.freenode.net/wikipedia-tr users:
+ * - berm
+ * - []LuCkY[]
+ * - Emperyan
+ * @see http://en.wikipedia.org/wiki/Dotted_and_dotless_I
+ * @dataProvider provideDottedAndDotlessI
+ */
+ public function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) {
+ if ( $func == 'ucfirst' ) {
+ $res = $this->getLang()->ucfirst( $input );
+ } elseif ( $func == 'lcfirst' ) {
+ $res = $this->getLang()->lcfirst( $input );
+ } else {
+ throw new MWException( __METHOD__ . " given an invalid function name '$func'" );
+ }
+
+ $msg = "Converting $inputCase case '$input' with $func should give '$expected'";
+
+ $this->assertEquals( $expected, $res, $msg );
+ }
+
+ public static function provideDottedAndDotlessI() {
+ return array(
+ # function, input, input case, expected
+ # Case changed:
+ array( 'ucfirst', 'ı', 'lower', 'I' ),
+ array( 'ucfirst', 'i', 'lower', 'İ' ),
+ array( 'lcfirst', 'I', 'upper', 'ı' ),
+ array( 'lcfirst', 'İ', 'upper', 'i' ),
+
+ # Already using the correct case
+ array( 'ucfirst', 'I', 'upper', 'I' ),
+ array( 'ucfirst', 'İ', 'upper', 'İ' ),
+ array( 'lcfirst', 'ı', 'lower', 'ı' ),
+ array( 'lcfirst', 'i', 'lower', 'i' ),
+
+ # A real example taken from bug 28040 using
+ # http://tr.wikipedia.org/wiki/%C4%B0Phone
+ array( 'lcfirst', 'iPhone', 'lower', 'iPhone' ),
+
+ # next case is valid in Turkish but are different words if we
+ # consider IPhone is English!
+ array( 'lcfirst', 'IPhone', 'upper', 'ıPhone' ),
+
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageUkTest.php b/tests/phpunit/languages/LanguageUkTest.php
new file mode 100644
index 00000000..9051bcff
--- /dev/null
+++ b/tests/phpunit/languages/LanguageUkTest.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * based on LanguageBe_tarask.php
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for Ukrainian */
+class LanguageUkTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'few', 'many', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * Test explicit plural forms - n=FormN forms
+ * @covers Language::convertPlural
+ */
+ public function testExplicitPlural() {
+ $forms = array( 'one', 'few', 'many', 'other', '12=dozen' );
+ $this->assertEquals( 'dozen', $this->getLang()->convertPlural( 12, $forms ) );
+ $forms = array( 'one', 'few', 'many', '100=hundred', 'other', '12=dozen' );
+ $this->assertEquals( 'hundred', $this->getLang()->convertPlural( 100, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 1 ),
+ array( 'many', 11 ),
+ array( 'one', 91 ),
+ array( 'one', 121 ),
+ array( 'few', 2 ),
+ array( 'few', 3 ),
+ array( 'few', 4 ),
+ array( 'few', 334 ),
+ array( 'many', 5 ),
+ array( 'many', 15 ),
+ array( 'many', 120 ),
+ );
+ }
+
+ /**
+ * @dataProvider providePluralTwoForms
+ * @covers Language::convertPlural
+ */
+ public function testPluralTwoForms( $result, $value ) {
+ $forms = array( '1=one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ public static function providePluralTwoForms() {
+ return array(
+ array( 'one', 1 ),
+ array( 'other', 11 ),
+ array( 'other', 91 ),
+ array( 'other', 121 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageUzTest.php b/tests/phpunit/languages/LanguageUzTest.php
new file mode 100644
index 00000000..13f57c16
--- /dev/null
+++ b/tests/phpunit/languages/LanguageUzTest.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * PHPUnit tests for the Uzbek language.
+ * The language can be represented using two scripts:
+ * - Latin (uz-latn)
+ * - Cyrillic (uz-cyrl)
+ *
+ * @author Robin Pepermans
+ * @author Antoine Musso <hashar at free dot fr>
+ * @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..
+ */
+
+/** Tests for MediaWiki languages/LanguageUz.php */
+class LanguageUzTest extends LanguageClassesTestCase {
+
+ /**
+ * @author Nikola Smolenski
+ * @covers LanguageConverter::convertTo
+ */
+ public function testConversionToCyrillic() {
+ // A convertion of Latin to Cyrillic
+ $this->assertEquals( 'абвгғ',
+ $this->convertToCyrillic( 'abvggʻ' )
+ );
+ // Same as above, but assert that -{}-s must be removed and not converted
+ $this->assertEquals( 'ljабnjвгўоdb',
+ $this->convertToCyrillic( '-{lj}-ab-{nj}-vgoʻo-{db}-' )
+ );
+ // A simple convertion of Cyrillic to Cyrillic
+ $this->assertEquals( 'абвг',
+ $this->convertToCyrillic( 'абвг' )
+ );
+ // Same as above, but assert that -{}-s must be removed and not converted
+ $this->assertEquals( 'ljабnjвгdaž',
+ $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{da}-ž' )
+ );
+ }
+
+ /**
+ * @covers LanguageConverter::convertTo
+ */
+ public function testConversionToLatin() {
+ // A simple convertion of Latin to Latin
+ $this->assertEquals( 'abdef',
+ $this->convertToLatin( 'abdef' )
+ );
+ // A convertion of Cyrillic to Latin
+ $this->assertEquals( 'gʻabtsdOʻQyo',
+ $this->convertToLatin( 'ғабцдЎҚё' )
+ );
+ }
+
+ ##### HELPERS #####################################################
+ /**
+ * Wrapper to verify text stay the same after applying conversion
+ * @param $text string Text to convert
+ * @param $variant string Language variant 'uz-cyrl' or 'uz-latn'
+ * @param $msg string Optional message
+ */
+ protected function assertUnConverted( $text, $variant, $msg = '' ) {
+ $this->assertEquals(
+ $text,
+ $this->convertTo( $text, $variant ),
+ $msg
+ );
+ }
+
+ /**
+ * Wrapper to verify a text is different once converted to a variant.
+ * @param $text string Text to convert
+ * @param $variant string Language variant 'uz-cyrl' or 'uz-latn'
+ * @param $msg string Optional message
+ */
+ protected function assertConverted( $text, $variant, $msg = '' ) {
+ $this->assertNotEquals(
+ $text,
+ $this->convertTo( $text, $variant ),
+ $msg
+ );
+ }
+
+ /**
+ * Verifiy the given Cyrillic text is not converted when using
+ * using the cyrillic variant and converted to Latin when using
+ * the Latin variant.
+ */
+ protected function assertCyrillic( $text, $msg = '' ) {
+ $this->assertUnConverted( $text, 'uz-cyrl', $msg );
+ $this->assertConverted( $text, 'uz-latn', $msg );
+ }
+
+ /**
+ * Verifiy the given Latin text is not converted when using
+ * using the Latin variant and converted to Cyrillic when using
+ * the Cyrillic variant.
+ */
+ protected function assertLatin( $text, $msg = '' ) {
+ $this->assertUnConverted( $text, 'uz-latn', $msg );
+ $this->assertConverted( $text, 'uz-cyrl', $msg );
+ }
+
+
+ /** Wrapper for converter::convertTo() method*/
+ protected function convertTo( $text, $variant ) {
+ return $this->getLang()->mConverter->convertTo( $text, $variant );
+ }
+
+ protected function convertToCyrillic( $text ) {
+ return $this->convertTo( $text, 'uz-cyrl' );
+ }
+
+ protected function convertToLatin( $text ) {
+ return $this->convertTo( $text, 'uz-latn' );
+ }
+}
diff --git a/tests/phpunit/languages/LanguageWaTest.php b/tests/phpunit/languages/LanguageWaTest.php
new file mode 100644
index 00000000..d05196c0
--- /dev/null
+++ b/tests/phpunit/languages/LanguageWaTest.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageWa.php */
+class LanguageWaTest extends LanguageClassesTestCase {
+ /**
+ * @dataProvider providePlural
+ * @covers Language::convertPlural
+ */
+ public function testPlural( $result, $value ) {
+ $forms = array( 'one', 'other' );
+ $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
+ }
+
+ /**
+ * @dataProvider providePlural
+ * @covers Language::getPluralRuleType
+ */
+ public function testGetPluralRuleType( $result, $value ) {
+ $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
+ }
+
+ public static function providePlural() {
+ return array(
+ array( 'one', 0 ),
+ array( 'one', 1 ),
+ array( 'other', 2 ),
+ );
+ }
+}
diff --git a/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php b/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php
new file mode 100644
index 00000000..bd3809d7
--- /dev/null
+++ b/tests/phpunit/languages/utils/CLDRPluralRuleEvaluatorTest.php
@@ -0,0 +1,145 @@
+<?php
+/**
+ * @author Niklas Laxström
+ * @file
+ */
+
+class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase {
+ /**
+ * @dataProvider validTestCases
+ */
+ function testValidRules( $expected, $rules, $number, $comment ) {
+ $result = CLDRPluralRuleEvaluator::evaluate( $number, (array)$rules );
+ $this->assertEquals( $expected, $result, $comment );
+ }
+
+ /**
+ * @dataProvider invalidTestCases
+ * @expectedException CLDRPluralRuleError
+ */
+ function testInvalidRules( $rules, $comment ) {
+ CLDRPluralRuleEvaluator::evaluate( 1, (array)$rules );
+ }
+
+ function validTestCases() {
+ $tests = array(
+ # expected, number, rule, comment
+ array( 0, 'n is 1', 1, 'integer number and is' ),
+ array( 0, 'n is 1', "1", 'string integer number and is' ),
+ array( 0, 'n is 1', 1.0, 'float number and is' ),
+ array( 0, 'n is 1', "1.0", 'string float number and is' ),
+ array( 1, 'n is 1', 1.1, 'float number and is' ),
+ array( 1, 'n is 1', 2, 'float number and is' ),
+
+ array( 0, 'n in 1,3,5', 3, '' ),
+ array( 1, 'n not in 1,3,5', 5, '' ),
+
+ array( 1, 'n in 1,3,5', 2, '' ),
+ array( 0, 'n not in 1,3,5', 4, '' ),
+
+ array( 0, 'n in 1..3', 2, '' ),
+ array( 0, 'n in 1..3', 3, 'in is inclusive' ),
+ array( 1, 'n in 1..3', 0, '' ),
+
+ array( 1, 'n not in 1..3', 2, '' ),
+ array( 1, 'n not in 1..3', 3, 'in is inclusive' ),
+ array( 0, 'n not in 1..3', 0, '' ),
+
+ array( 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ),
+ array( 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ),
+
+ array( 0, 'n is not 1 or n is 1', 1, 'or relation' ),
+ array( 1, 'n is 1 or n is 2', 3, 'or relation' ),
+
+ array( 0, 'n is 1', 1, 'extra whitespace' ),
+
+ array( 0, 'n mod 3 is 1', 7, 'mod' ),
+ array( 0, 'n mod 3 is not 1', 4.3, 'mod with floats' ),
+
+ array( 0, 'n within 1..3', 2, 'within with integer' ),
+ array( 0, 'n within 1..3', 2.5, 'within with float' ),
+ array( 0, 'n in 1..3', 2, 'in with integer' ),
+ array( 1, 'n in 1..3', 2.5, 'in with float' ),
+
+ array( 0, 'n in 3 or n is 4 and n is 5', 3, 'and binds more tightly than or' ),
+ array( 1, 'n is 3 or n is 4 and n is 5', 4, 'and binds more tightly than or' ),
+
+ array( 0, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 24, 'breton rule' ),
+ array( 1, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 25, 'breton rule' ),
+
+ array( 0, 'n within 0..2 and n is not 2', 0, 'french rule' ),
+ array( 0, 'n within 0..2 and n is not 2', 1, 'french rule' ),
+ array( 0, 'n within 0..2 and n is not 2', 1.2, 'french rule' ),
+ array( 1, 'n within 0..2 and n is not 2', 2, 'french rule' ),
+
+ array( 1, 'n in 3..10,13..19', 2, 'scottish rule - ranges with comma' ),
+ array( 0, 'n in 3..10,13..19', 4, 'scottish rule - ranges with comma' ),
+ array( 1, 'n in 3..10,13..19', 12.999, 'scottish rule - ranges with comma' ),
+ array( 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ),
+
+ array( 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ),
+
+ # Revision 33 new operand examples
+ # expected, rule, number, comment
+ array( 0, 'i is 1', '1.00', 'new operand i' ),
+ array( 0, 'v is 2', '1.00', 'new operand v' ),
+ array( 0, 'w is 0', '1.00', 'new operand w' ),
+ array( 0, 'f is 0', '1.00', 'new operand f' ),
+ array( 0, 't is 0', '1.00', 'new operand t' ),
+
+ array( 0, 'i is 1', '1.30', 'new operand i' ),
+ array( 0, 'v is 2', '1.30', 'new operand v' ),
+ array( 0, 'w is 1', '1.30', 'new operand w' ),
+ array( 0, 'f is 30', '1.30', 'new operand f' ),
+ array( 0, 't is 3', '1.30', 'new operand t' ),
+
+ array( 0, 'i is 1', '1.03', 'new operand i' ),
+ array( 0, 'v is 2', '1.03', 'new operand v' ),
+ array( 0, 'w is 2', '1.03', 'new operand w' ),
+ array( 0, 'f is 3', '1.03', 'new operand f' ),
+ array( 0, 't is 3', '1.03', 'new operand t' ),
+
+ # Revision 33 new operator aliases
+ # expected, rule, number, comment
+ array( 0, 'n % 3 is 1', 7, 'new % operator' ),
+ array( 0, 'n = 1,3,5', 3, 'new = operator' ),
+ array( 1, 'n != 1,3,5', 5, 'new != operator' ),
+
+ # Revision 33 samples
+ # expected, rule, number, comment
+ array( 0, 'n in 1,3,5@integer 3~10, 103~110, 1003, … @decimal 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 103.0, 1003.0, …', 3, 'samples' ),
+
+ # Revision 33 some test cases from CLDR
+ array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.1', 'pt one' ),
+ array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.01', 'pt one' ),
+ array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.10', 'pt one' ),
+ array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.010', 'pt one' ),
+ array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.100', 'pt one' ),
+ array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.0', 'pt other' ),
+ array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.2', 'pt other' ),
+ array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '10.0', 'pt other' ),
+ array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '100.0', 'pt other' ),
+ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '2', 'bs few' ),
+ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '4', 'bs few' ),
+ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '22', 'bs few' ),
+ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '102', 'bs few' ),
+ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.2', 'bs few' ),
+ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.4', 'bs few' ),
+ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.2', 'bs few' ),
+ array( 1, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.0', 'bs other' ),
+
+ );
+
+ return $tests;
+ }
+
+ function invalidTestCases() {
+ $tests = array(
+ array( 'n mod mod 5 is 1', 'mod mod' ),
+ array( 'n', 'just n' ),
+ array( 'n is in 5', 'is in' ),
+ );
+
+ return $tests;
+ }
+}