From dbe89abb9ee514c812bfa4e0a07a89c498bd26e0 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 1 Aug 2018 19:49:22 +0100 Subject: [PATCH] languages: Add coverage for 'ar' and 'ml' normalize() * 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 | 2 +- languages/classes/LanguageAr.php | 2 +- languages/classes/LanguageMl.php | 2 +- .../languages/classes/LanguageArTest.php | 49 +++++++++++++++---- .../languages/classes/LanguageMlTest.php | 32 ++++++++++-- tests/phpunit/suite.xml | 2 + 6 files changed, 73 insertions(+), 16 deletions(-) diff --git a/languages/Language.php b/languages/Language.php index dfbacfc0a7..eab09a1d1b 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3014,7 +3014,7 @@ class Language { * * @return string */ - function normalize( $s ) { + public function normalize( $s ) { global $wgAllUnicodeFixes; $s = UtfNormal\Validator::cleanUp( $s ); if ( $wgAllUnicodeFixes ) { diff --git a/languages/classes/LanguageAr.php b/languages/classes/LanguageAr.php index efdf5a2713..f2ce1788e3 100644 --- a/languages/classes/LanguageAr.php +++ b/languages/classes/LanguageAr.php @@ -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 ) { diff --git a/languages/classes/LanguageMl.php b/languages/classes/LanguageMl.php index cf45762ea8..176c64c135 100644 --- a/languages/classes/LanguageMl.php +++ b/languages/classes/LanguageMl.php @@ -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 ) { diff --git a/tests/phpunit/languages/classes/LanguageArTest.php b/tests/phpunit/languages/classes/LanguageArTest.php index f3f5a3f1f1..296ee60788 100644 --- a/tests/phpunit/languages/classes/LanguageArTest.php +++ b/tests/phpunit/languages/classes/LanguageArTest.php @@ -1,32 +1,61 @@ 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', diff --git a/tests/phpunit/languages/classes/LanguageMlTest.php b/tests/phpunit/languages/classes/LanguageMlTest.php index 673b5c775f..59b7ba8d98 100644 --- a/tests/phpunit/languages/classes/LanguageMlTest.php +++ b/tests/phpunit/languages/classes/LanguageMlTest.php @@ -11,15 +11,15 @@ 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 [ + [ + 'ല്‍', + 'ൽ', + ], + ]; + } } diff --git a/tests/phpunit/suite.xml b/tests/phpunit/suite.xml index e125b8a314..1917674f3e 100644 --- a/tests/phpunit/suite.xml +++ b/tests/phpunit/suite.xml @@ -73,6 +73,8 @@ ../../maintenance ../../languages/messages + ../../languages/data/normalize-ar.php + ../../languages/data/normalize-ml.php -- 2.20.1