Add PHPUnit tests for plural rules. For languages cs, cu, cy, dsb, fr, ga, gd, gv...
authorSanthosh Thottingal <santhosh@users.mediawiki.org>
Fri, 27 Jan 2012 11:13:06 +0000 (11:13 +0000)
committerSanthosh Thottingal <santhosh@users.mediawiki.org>
Fri, 27 Jan 2012 11:13:06 +0000 (11:13 +0000)
13 files changed:
tests/phpunit/languages/LanguageCsTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageCuTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageCyTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageDsbTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageFrTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageGaTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageGdTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageGvTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageHrTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageHsbTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageHyTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageKshTest.php [new file with mode: 0644]
tests/phpunit/languages/LanguageLnTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/languages/LanguageCsTest.php b/tests/phpunit/languages/LanguageCsTest.php
new file mode 100644 (file)
index 0000000..dda29f9
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/Languagecs.php */
+class LanguageCsTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'cs' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'few', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               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 (file)
index 0000000..f8186d7
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageCu.php */
+class LanguageCuTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'cu' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'few', 'many', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               return array (
+                       array( 'other', 0 ),
+                       array( 'one', 1 ),
+                       array( 'few', 2 ),
+                       array( 'many', 3 ),
+                       array( 'many', 4 ),
+                       array( 'other', 5 ),
+                       array( 'one', 11 ),
+                       array( 'other', 20 ),
+                       array( 'few', 22 ),
+                       array( 'many', 223 ),
+                       array( 'other', 200 ),
+               );
+       }
+
+}
diff --git a/tests/phpunit/languages/LanguageCyTest.php b/tests/phpunit/languages/LanguageCyTest.php
new file mode 100644 (file)
index 0000000..e9f9e41
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageCy.php */
+class LanguageCyTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'cy' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'zero', 'one', 'two', 'few', 'many', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               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 (file)
index 0000000..ab7f931
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageDsb.php */
+class LanguageDsbTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'dsb' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providePlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'two', 'few', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       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 (file)
index 0000000..8538744
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageFr.php */
+class LanguageFrTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'fr' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providePlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providePlural() {
+               return array (
+                       array( 'one', 0 ),
+                       array( 'one', 1 ),
+                       array( 'other', 2 ),
+                       array( 'other', 200 ),
+               );
+       }
+
+}
diff --git a/tests/phpunit/languages/LanguageGaTest.php b/tests/phpunit/languages/LanguageGaTest.php
new file mode 100644 (file)
index 0000000..fbd9f11
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageGa.php */
+class LanguageGaTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'ga' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'two', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               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 (file)
index 0000000..24574bd
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageGd.php */
+class LanguageGdTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'gd' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               // The CLDR ticket for this plural forms is not same as mw plural forms. See http://unicode.org/cldr/trac/ticket/2883
+               $forms =  array( 'Form 1', 'Form 2', 'Form 3', 'Form 4', 'Form 5', 'Form 6' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+       function providerPlural() {
+               return array (
+                       array( 'Form 6', 0 ),
+                       array( 'Form 1', 1 ),
+                       array( 'Form 2', 2 ),
+                       array( 'Form 3', 11 ),
+                       array( 'Form 4', 12 ),
+                       array( 'Form 5', 3 ),
+                       array( 'Form 5', 19 ),
+                       array( 'Form 6', 200 ),
+               );
+       }
+
+}
diff --git a/tests/phpunit/languages/LanguageGvTest.php b/tests/phpunit/languages/LanguageGvTest.php
new file mode 100644 (file)
index 0000000..3d298b9
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageGv.php */
+class LanguageGvTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'gv' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               // This is not compatible with CLDR plural rules http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#gv
+               $forms =  array( 'Form 1', 'Form 2', 'Form 3', 'Form 4' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+       function providerPlural() {
+               return array (
+                       array( 'Form 4', 0 ),
+                       array( 'Form 2', 1 ),
+                       array( 'Form 3', 2 ),
+                       array( 'Form 4', 3 ),
+                       array( 'Form 1', 20 ),
+                       array( 'Form 2', 21 ),
+                       array( 'Form 3', 22 ),
+                       array( 'Form 4', 23 ),
+                       array( 'Form 4', 50 ),
+               );
+       }
+
+}
diff --git a/tests/phpunit/languages/LanguageHrTest.php b/tests/phpunit/languages/LanguageHrTest.php
new file mode 100644 (file)
index 0000000..4f1c66b
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageHr.php */
+class LanguageHrTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'hr' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'few', 'many', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               return array (
+                       array( 'many', 0 ),
+                       array( 'one', 1 ),
+                       array( 'few', 2 ),
+                       array( 'few', 4 ),
+                       array( 'many', 5 ),
+                       array( 'many', 11 ),
+                       array( 'many', 20 ),
+                       array( 'one', 21 ),
+                       array( 'few', 24 ),
+                       array( 'many', 25 ),
+                       array( 'many', 200 ),
+               );
+       }
+
+}
diff --git a/tests/phpunit/languages/LanguageHsbTest.php b/tests/phpunit/languages/LanguageHsbTest.php
new file mode 100644 (file)
index 0000000..803c772
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageHsb.php */
+class LanguageHsbTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'hsb' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providePlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'two', 'few', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       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/LanguageHyTest.php b/tests/phpunit/languages/LanguageHyTest.php
new file mode 100644 (file)
index 0000000..7990bdf
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageHy.php */
+class LanguageHyTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'hy' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               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 (file)
index 0000000..ab88946
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageKsh.php */
+class LanguageKshTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'ksh' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array(  'one', 'other', 'zero' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               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 (file)
index 0000000..0fd9167
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageLn.php */
+class LanguageLnTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'ln' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providePlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providePlural() {
+               return array (
+                       array( 'one', 0 ),
+                       array( 'one', 1 ),
+                       array( 'other', 2 ),
+                       array( 'other', 200 ),
+               );
+       }
+
+}