r110103 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110102‎ | r110103 | r110104 >
Date:06:01, 27 January 2012
Author:santhosh
Status:ok (Comments)
Tags:i18nreview 
Comment:
phpunit testcases on the plural rules for am, ar, be, be_tarask, bh, bs and hi languages
Modified paths:
  • /trunk/phase3/tests/phpunit/languages/LanguageAmTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageArTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageBeTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageBe_taraskTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageBhTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageBsTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageHiTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/languages/LanguageArTest.php
@@ -52,4 +52,27 @@
5353 ),
5454 );
5555 }
 56+ /** @dataProvider providePlural */
 57+ function testPlural( $result, $value ) {
 58+ $forms = array( 'zero', 'one', 'two', 'few', 'many', 'other' );
 59+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 60+ }
 61+ function providePlural() {
 62+ return array (
 63+ array( 'zero', 0 ),
 64+ array( 'one', 1 ),
 65+ array( 'two', 2 ),
 66+ array( 'few', 3 ),
 67+ array( 'few', 9 ),
 68+ array( 'few', 110 ),
 69+ array( 'many', 11 ),
 70+ array( 'many', 15 ),
 71+ array( 'many', 99 ),
 72+ array( 'many', 9999 ),
 73+ array( 'other', 100 ),
 74+ array( 'other', 102 ),
 75+ array( 'other', 1000 ),
 76+ array( 'other', 1.7 ),
 77+ );
 78+ }
5679 }
Index: trunk/phase3/tests/phpunit/languages/LanguageBsTest.php
@@ -0,0 +1,41 @@
 2+<?php
 3+/**
 4+ * @author Santhosh Thottingal
 5+ * @copyright Copyright © 2012, Santhosh Thottingal
 6+ * @file
 7+ */
 8+
 9+/** Tests for MediaWiki languages/LanguageBs.php */
 10+class LanguageBsTest extends MediaWikiTestCase {
 11+ private $lang;
 12+
 13+ function setUp() {
 14+ $this->lang = Language::factory( 'Bs' );
 15+ }
 16+ function tearDown() {
 17+ unset( $this->lang );
 18+ }
 19+
 20+ /** @dataProvider providePlural */
 21+ function testPlural( $result, $value ) {
 22+ $forms = array( 'one', 'few', 'many', 'other' );
 23+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 24+ }
 25+
 26+ function providePlural() {
 27+ return array (
 28+ array( 'many', 0 ),
 29+ array( 'one', 1 ),
 30+ array( 'few', 2 ),
 31+ array( 'few', 4 ),
 32+ array( 'many', 5 ),
 33+ array( 'many', 11 ),
 34+ array( 'many', 20 ),
 35+ array( 'one', 21 ),
 36+ array( 'few', 24 ),
 37+ array( 'many', 25 ),
 38+ array( 'many', 200 ),
 39+ );
 40+ }
 41+
 42+}
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageBsTest.php
___________________________________________________________________
Added: svn:eol-style
143 + native
Index: trunk/phase3/tests/phpunit/languages/LanguageBeTest.php
@@ -0,0 +1,40 @@
 2+<?php
 3+/**
 4+ * @author Santhosh Thottingal
 5+ * @copyright Copyright © 2012, Santhosh Thottingal
 6+ * @file
 7+ */
 8+
 9+/** Tests for MediaWiki languages/LanguageBe.php */
 10+class LanguageBeTest extends MediaWikiTestCase {
 11+ private $lang;
 12+
 13+ function setUp() {
 14+ $this->lang = Language::factory( 'Be' );
 15+ }
 16+ function tearDown() {
 17+ unset( $this->lang );
 18+ }
 19+
 20+ /** @dataProvider providePlural */
 21+ function testPlural( $result, $value ) {
 22+ $forms = array( 'one', 'few', 'many', 'other' );
 23+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 24+ }
 25+
 26+ function providePlural() {
 27+ return array (
 28+ array( 'one', 1 ),
 29+ array( 'many', 11 ),
 30+ array( 'one', 91 ),
 31+ array( 'one', 121 ),
 32+ array( 'few', 2 ),
 33+ array( 'few', 3 ),
 34+ array( 'few', 4 ),
 35+ array( 'few', 334 ),
 36+ array( 'many', 5 ),
 37+ array( 'many', 15 ),
 38+ array( 'many', 120 ),
 39+ );
 40+ }
 41+}
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageBeTest.php
___________________________________________________________________
Added: svn:eol-style
142 + native
Index: trunk/phase3/tests/phpunit/languages/LanguageBhTest.php
@@ -0,0 +1,34 @@
 2+<?php
 3+/**
 4+ * @author Santhosh Thottingal
 5+ * @copyright Copyright © 2012, Santhosh Thottingal
 6+ * @file
 7+ */
 8+
 9+/** Tests for MediaWiki languages/LanguageBh.php */
 10+class LanguageBhTest extends MediaWikiTestCase {
 11+ private $lang;
 12+
 13+ function setUp() {
 14+ $this->lang = Language::factory( 'Bh' );
 15+ }
 16+ function tearDown() {
 17+ unset( $this->lang );
 18+ }
 19+
 20+ /** @dataProvider providePlural */
 21+ function testPlural( $result, $value ) {
 22+ $forms = array( 'one', 'other' );
 23+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 24+ }
 25+
 26+ function providePlural() {
 27+ return array (
 28+ array( 'one', 0 ),
 29+ array( 'one', 1 ),
 30+ array( 'other', 2 ),
 31+ array( 'other', 200 ),
 32+ );
 33+ }
 34+
 35+}
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageBhTest.php
___________________________________________________________________
Added: svn:eol-style
136 + native
Index: trunk/phase3/tests/phpunit/languages/LanguageBe_taraskTest.php
@@ -27,4 +27,39 @@
2828 function testDoesNotCommafyFourDigitsNumber() {
2929 $this->assertEquals( '1234', $this->lang->commafy( '1234' ) );
3030 }
 31+ /** @dataProvider providePluralFourForms */
 32+ function testPluralFourForms( $result, $value ) {
 33+ $forms = array( 'one', 'few', 'many', 'other' );
 34+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 35+ }
 36+
 37+ function providePluralFourForms() {
 38+ return array (
 39+ array( 'one', 1 ),
 40+ array( 'many', 11 ),
 41+ array( 'one', 91 ),
 42+ array( 'one', 121 ),
 43+ array( 'few', 2 ),
 44+ array( 'few', 3 ),
 45+ array( 'few', 4 ),
 46+ array( 'few', 334 ),
 47+ array( 'many', 5 ),
 48+ array( 'many', 15 ),
 49+ array( 'many', 120 ),
 50+ );
 51+ }
 52+ /** @dataProvider providePluralTwoForms */
 53+ function testPluralTwoForms( $result, $value ) {
 54+ $forms = array( 'one', 'several' );
 55+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 56+ }
 57+ function providePluralTwoForms() {
 58+ return array (
 59+ array( 'one', 1 ),
 60+ array( 'several', 11 ),
 61+ array( 'several', 91 ),
 62+ array( 'several', 121 ),
 63+ );
 64+ }
 65+
3166 }
Index: trunk/phase3/tests/phpunit/languages/LanguageAmTest.php
@@ -0,0 +1,33 @@
 2+<?php
 3+/**
 4+ * @author Santhosh Thottingal
 5+ * @copyright Copyright © 2012, Santhosh Thottingal
 6+ * @file
 7+ */
 8+
 9+/** Tests for MediaWiki languages/LanguageAm.php */
 10+class LanguageAmTest extends MediaWikiTestCase {
 11+ private $lang;
 12+
 13+ function setUp() {
 14+ $this->lang = Language::factory( 'Am' );
 15+ }
 16+ function tearDown() {
 17+ unset( $this->lang );
 18+ }
 19+
 20+ /** @dataProvider providePlural */
 21+ function testPlural( $result, $value ) {
 22+ $forms = array( 'one', 'other' );
 23+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 24+ }
 25+
 26+ function providePlural() {
 27+ return array (
 28+ array( 'one', 0 ),
 29+ array( 'one', 1 ),
 30+ array( 'other', 2 ),
 31+ array( 'other', 200 ),
 32+ );
 33+ }
 34+}
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageAmTest.php
___________________________________________________________________
Added: svn:eol-style
135 + native
Index: trunk/phase3/tests/phpunit/languages/LanguageHiTest.php
@@ -0,0 +1,34 @@
 2+<?php
 3+/**
 4+ * @author Santhosh Thottingal
 5+ * @copyright Copyright © 2012, Santhosh Thottingal
 6+ * @file
 7+ */
 8+
 9+/** Tests for MediaWiki languages/LanguageHi.php */
 10+class LanguageHiTest extends MediaWikiTestCase {
 11+ private $lang;
 12+
 13+ function setUp() {
 14+ $this->lang = Language::factory( 'Hi' );
 15+ }
 16+ function tearDown() {
 17+ unset( $this->lang );
 18+ }
 19+
 20+ /** @dataProvider providePlural */
 21+ function testPlural( $result, $value ) {
 22+ $forms = array( 'one', 'other' );
 23+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 24+ }
 25+
 26+ function providePlural() {
 27+ return array (
 28+ array( 'one', 0 ),
 29+ array( 'one', 1 ),
 30+ array( 'other', 2 ),
 31+ array( 'other', 200 ),
 32+ );
 33+ }
 34+
 35+}
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageHiTest.php
___________________________________________________________________
Added: svn:eol-style
136 + native

Comments

#Comment by Nikerabbit (talk | contribs)   08:00, 27 January 2012

We usually spell language codes in lower case.

Can't we reuse code instead of duplicating for cases like am & bh?

#Comment by Santhosh.thottingal (talk | contribs)   08:22, 27 January 2012

I thought about it. Reusing the test cases make sense if the languages/LanguageXYZ.php reused the code. Since each language class has their own code sometimes same as other language classes, we need separate test cases for each language classes, otherwise we cannot detect regressions happening in future code changes. Do you have any suggestions?

Status & tagging log