languages: Add coverage for 'ar' and 'ml' normalize()
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 1 Aug 2018 18:49:22 +0000 (19:49 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 14 Aug 2018 23:19:35 +0000 (23:19 +0000)
* Exclude the data files from PHPUnit coverage.
* Add tests covering the normalize() implementations.
* Fix a small todo about using data providers.
* Set explicit visibility.

Change-Id: Ib104cc3215a36901cff853ad5969d92a6e0cf6a0

languages/Language.php
languages/classes/LanguageAr.php
languages/classes/LanguageMl.php
tests/phpunit/languages/classes/LanguageArTest.php
tests/phpunit/languages/classes/LanguageMlTest.php
tests/phpunit/suite.xml

index dfbacfc..eab09a1 100644 (file)
@@ -3014,7 +3014,7 @@ class Language {
         *
         * @return string
         */
-       function normalize( $s ) {
+       public function normalize( $s ) {
                global $wgAllUnicodeFixes;
                $s = UtfNormal\Validator::cleanUp( $s );
                if ( $wgAllUnicodeFixes ) {
index efdf5a2..f2ce178 100644 (file)
@@ -40,7 +40,7 @@ class LanguageAr extends Language {
         *
         * @return string
         */
-       function normalize( $s ) {
+       public function normalize( $s ) {
                global $wgFixArabicUnicode;
                $s = parent::normalize( $s );
                if ( $wgFixArabicUnicode ) {
index cf45762..176c64c 100644 (file)
@@ -41,7 +41,7 @@ class LanguageMl extends Language {
         *
         * @return string
         */
-       function normalize( $s ) {
+       public function normalize( $s ) {
                global $wgFixMalayalamUnicode;
                $s = parent::normalize( $s );
                if ( $wgFixMalayalamUnicode ) {
index f3f5a3f..296ee60 100644 (file)
@@ -1,32 +1,61 @@
 <?php
-/**
- * Based on LanguagMlTest
- * @file
- */
 
 /**
  * @covers LanguageAr
  */
 class LanguageArTest extends LanguageClassesTestCase {
+
        /**
         * @covers Language::formatNum
-        * @todo split into a test and a dataprovider
+        * @dataProvider provideFormatNum
         */
-       public function testFormatNum() {
-               $this->assertEquals( '١٬٢٣٤٬٥٦٧', $this->getLang()->formatNum( '1234567' ) );
-               $this->assertEquals( '-١٢٫٨٩', $this->getLang()->formatNum( -12.89 ) );
+       public function testFormatNum( $num, $formatted ) {
+               $this->assertEquals( $formatted, $this->getLang()->formatNum( $num ) );
+       }
+
+       public static function provideFormatNum() {
+               return [
+                       [ '1234567', '١٬٢٣٤٬٥٦٧' ],
+                       [ -12.89, '-١٢٫٨٩' ],
+               ];
+       }
+
+       /**
+        * @covers LanguageAr::normalize
+        * @covers Language::normalize
+        * @dataProvider provideNormalize
+        */
+       public function testNormalize( $input, $expected ) {
+               if ( $input === $expected ) {
+                       throw new Exception( 'Expected output must differ.' );
+               }
+
+               $this->setMwGlobals( 'wgFixArabicUnicode', true );
+               $this->assertSame( $expected, $this->getLang()->normalize( $input ), 'ar-normalised form' );
+
+               $this->setMwGlobals( 'wgFixArabicUnicode', false );
+               $this->assertSame( $input, $this->getLang()->normalize( $input ), 'regular normalised form' );
+       }
+
+       public static function provideNormalize() {
+               return [
+                       [
+                               'ﷅ',
+                               'صمم',
+                       ],
+               ];
        }
 
        /**
         * Mostly to test the raw ascii feature.
-        * @dataProvider providerSprintfDate
+        * @dataProvider provideSprintfDate
         * @covers Language::sprintfDate
         */
        public function testSprintfDate( $format, $date, $expected ) {
                $this->assertEquals( $expected, $this->getLang()->sprintfDate( $format, $date ) );
        }
 
-       public static function providerSprintfDate() {
+       public static function provideSprintfDate() {
                return [
                        [
                                'xg "vs" g',
index 673b5c7..59b7ba8 100644 (file)
 class LanguageMlTest extends LanguageClassesTestCase {
 
        /**
-        * @dataProvider providerFormatNum
-        * T31495
+        * @dataProvider provideFormatNum
         * @covers Language::formatNum
         */
        public function testFormatNum( $result, $value ) {
+               // For T31495
                $this->assertEquals( $result, $this->getLang()->formatNum( $value ) );
        }
 
-       public static function providerFormatNum() {
+       public static function provideFormatNum() {
                return [
                        [ '12,34,567', '1234567' ],
                        [ '12,345', '12345' ],
@@ -37,4 +37,30 @@ class LanguageMlTest extends LanguageClassesTestCase {
                        [ '', null ],
                ];
        }
+
+       /**
+        * @covers LanguageMl::normalize
+        * @covers Language::normalize
+        * @dataProvider provideNormalize
+        */
+       public function testNormalize( $input, $expected ) {
+               if ( $input === $expected ) {
+                       throw new Exception( 'Expected output must differ.' );
+               }
+
+               $this->setMwGlobals( 'wgFixMalayalamUnicode', true );
+               $this->assertSame( $expected, $this->getLang()->normalize( $input ), 'ml-normalised form' );
+
+               $this->setMwGlobals( 'wgFixMalayalamUnicode', false );
+               $this->assertSame( $input, $this->getLang()->normalize( $input ), 'regular normalised form' );
+       }
+
+       public static function provideNormalize() {
+               return [
+                       [
+                               'ല്‍',
+                               'ൽ',
+                       ],
+               ];
+       }
 }
index e125b8a..1917674 100644 (file)
@@ -73,6 +73,8 @@
                        <directory suffix=".php">../../maintenance</directory>
                        <exclude>
                                <directory suffix=".php">../../languages/messages</directory>
+                               <file>../../languages/data/normalize-ar.php</file>
+                               <file>../../languages/data/normalize-ml.php</file>
                        </exclude>
                </whitelist>
        </filter>