diff options
Diffstat (limited to 'www/wiki/tests/phpunit/languages')
61 files changed, 5630 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/languages/LanguageClassesTestCase.php b/www/wiki/tests/phpunit/languages/LanguageClassesTestCase.php new file mode 100644 index 00000000..2216ba40 --- /dev/null +++ b/www/wiki/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/', static::class, $m ); + if ( $found ) { + # Normalize language code since classes uses underscores + $m[1] = strtolower( str_replace( '_', '-', $m[1] ) ); + } else { + # Fallback to english language + $m[1] = 'en'; + wfDebug( + __METHOD__ . ' could not extract a language name ' + . 'out of ' . static::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/www/wiki/tests/phpunit/languages/LanguageCodeTest.php b/www/wiki/tests/phpunit/languages/LanguageCodeTest.php new file mode 100644 index 00000000..544a0635 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/LanguageCodeTest.php @@ -0,0 +1,161 @@ +<?php + +/** + * @covers LanguageCode + * @group Language + * + * @author Thiemo Kreuz + */ +class LanguageCodeTest extends PHPUnit\Framework\TestCase { + + use MediaWikiCoversValidator; + + public function testConstructor() { + $instance = new LanguageCode(); + + $this->assertInstanceOf( LanguageCode::class, $instance ); + } + + public function testGetDeprecatedCodeMapping() { + $map = LanguageCode::getDeprecatedCodeMapping(); + + $this->assertInternalType( 'array', $map ); + $this->assertContainsOnly( 'string', array_keys( $map ) ); + $this->assertArrayNotHasKey( '', $map ); + $this->assertContainsOnly( 'string', $map ); + $this->assertNotContains( '', $map ); + + // Codes special to MediaWiki should never appear in a map of "deprecated" codes + $this->assertArrayNotHasKey( 'qqq', $map, 'documentation' ); + $this->assertNotContains( 'qqq', $map, 'documentation' ); + $this->assertArrayNotHasKey( 'qqx', $map, 'debug code' ); + $this->assertNotContains( 'qqx', $map, 'debug code' ); + + // Valid language codes that are currently not "deprecated" + $this->assertArrayNotHasKey( 'bh', $map, 'family of Bihari languages' ); + $this->assertArrayNotHasKey( 'no', $map, 'family of Norwegian languages' ); + $this->assertArrayNotHasKey( 'simple', $map ); + } + + public function testReplaceDeprecatedCodes() { + $this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'als' ) ); + $this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'gsw' ) ); + $this->assertEquals( null, LanguageCode::replaceDeprecatedCodes( null ) ); + } + + /** + * test @see LanguageCode::bcp47(). + * Please note the BCP 47 explicitly state that language codes are case + * insensitive, there are some exceptions to the rule :) + * This test is used to verify our formatting against all lower and + * all upper cases language code. + * + * @see https://tools.ietf.org/html/bcp47 + * @dataProvider provideLanguageCodes() + */ + public function testBcp47( $code, $expected ) { + $code = strtolower( $code ); + $this->assertEquals( $expected, LanguageCode::bcp47( $code ), + "Applying BCP47 standard to lower case '$code'" + ); + + $code = strtoupper( $code ); + $this->assertEquals( $expected, LanguageCode::bcp47( $code ), + "Applying BCP47 standard to upper case '$code'" + ); + } + + /** + * Array format is ($code, $expected) + */ + public static function provideLanguageCodes() { + return [ + // Extracted from BCP 47 (list not exhaustive) + # 2.1.1 + [ 'en-ca-x-ca', 'en-CA-x-ca' ], + [ 'sgn-be-fr', 'sgn-BE-FR' ], + [ 'az-latn-x-latn', 'az-Latn-x-latn' ], + # 2.2 + [ 'sr-Latn-RS', 'sr-Latn-RS' ], + [ 'az-arab-ir', 'az-Arab-IR' ], + + # 2.2.5 + [ 'sl-nedis', 'sl-nedis' ], + [ 'de-ch-1996', 'de-CH-1996' ], + + # 2.2.6 + [ + 'en-latn-gb-boont-r-extended-sequence-x-private', + 'en-Latn-GB-boont-r-extended-sequence-x-private' + ], + + // Examples from BCP 47 Appendix A + # Simple language subtag: + [ 'DE', 'de' ], + [ 'fR', 'fr' ], + [ 'ja', 'ja' ], + + # Language subtag plus script subtag: + [ 'zh-hans', 'zh-Hans' ], + [ 'sr-cyrl', 'sr-Cyrl' ], + [ 'sr-latn', 'sr-Latn' ], + + # Extended language subtags and their primary language subtag + # counterparts: + [ 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ], + [ 'cmn-hans-cn', 'cmn-Hans-CN' ], + [ 'zh-yue-hk', 'zh-yue-HK' ], + [ 'yue-hk', 'yue-HK' ], + + # Language-Script-Region: + [ 'zh-hans-cn', 'zh-Hans-CN' ], + [ 'sr-latn-RS', 'sr-Latn-RS' ], + + # Language-Variant: + [ 'sl-rozaj', 'sl-rozaj' ], + [ 'sl-rozaj-biske', 'sl-rozaj-biske' ], + [ 'sl-nedis', 'sl-nedis' ], + + # Language-Region-Variant: + [ 'de-ch-1901', 'de-CH-1901' ], + [ 'sl-it-nedis', 'sl-IT-nedis' ], + + # Language-Script-Region-Variant: + [ 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ], + + # Language-Region: + [ 'de-de', 'de-DE' ], + [ 'en-us', 'en-US' ], + [ 'es-419', 'es-419' ], + + # Private use subtags: + [ 'de-ch-x-phonebk', 'de-CH-x-phonebk' ], + [ 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ], + /** + * Previous test does not reflect the BCP 47 which states: + * az-Arab-x-AZE-derbend + * AZE being private, it should be lower case, hence the test above + * should probably be: + * [ 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ], + */ + + # Private use registry values: + [ 'x-whatever', 'x-whatever' ], + [ 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ], + [ 'de-qaaa', 'de-Qaaa' ], + [ 'sr-latn-qm', 'sr-Latn-QM' ], + [ 'sr-qaaa-rs', 'sr-Qaaa-RS' ], + + # Tags that use extensions + [ 'en-us-u-islamcal', 'en-US-u-islamcal' ], + [ 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ], + [ 'en-a-myext-b-another', 'en-a-myext-b-another' ], + + # Invalid: + // de-419-DE + // a-DE + // ar-a-aaa-b-bbb-a-ccc + ]; + } + +} diff --git a/www/wiki/tests/phpunit/languages/LanguageConverterTest.php b/www/wiki/tests/phpunit/languages/LanguageConverterTest.php new file mode 100644 index 00000000..82ab7def --- /dev/null +++ b/www/wiki/tests/phpunit/languages/LanguageConverterTest.php @@ -0,0 +1,207 @@ +<?php + +class LanguageConverterTest extends MediaWikiLangTestCase { + /** @var LanguageToTest */ + protected $lang = null; + /** @var TestConverter */ + protected $lc = null; + + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( [ + 'wgContLang' => Language::factory( 'tg' ), + 'wgLanguageCode' => 'tg', + 'wgDefaultLanguageVariant' => false, + 'wgRequest' => new FauxRequest( [] ), + 'wgUser' => new User, + ] ); + + $this->lang = new LanguageToTest(); + $this->lc = new TestConverter( + $this->lang, 'tg', + [ 'tg', 'tg-latn' ] + ); + } + + protected function tearDown() { + unset( $this->lc ); + unset( $this->lang ); + + parent::tearDown(); + } + + /** + * @covers LanguageConverter::getPreferredVariant + */ + public function testGetPreferredVariantDefaults() { + $this->assertEquals( 'tg', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + * @covers LanguageConverter::getHeaderVariant + */ + public function testGetPreferredVariantHeaders() { + global $wgRequest; + $wgRequest->setHeader( 'Accept-Language', 'tg-latn' ); + + $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + * @covers LanguageConverter::getHeaderVariant + */ + public function testGetPreferredVariantHeaderWeight() { + global $wgRequest; + $wgRequest->setHeader( 'Accept-Language', 'tg;q=1' ); + + $this->assertEquals( 'tg', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + * @covers LanguageConverter::getHeaderVariant + */ + public function testGetPreferredVariantHeaderWeight2() { + global $wgRequest; + $wgRequest->setHeader( 'Accept-Language', 'tg-latn;q=1' ); + + $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + * @covers LanguageConverter::getHeaderVariant + */ + public function testGetPreferredVariantHeaderMulti() { + global $wgRequest; + $wgRequest->setHeader( 'Accept-Language', 'en, tg-latn;q=1' ); + + $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + */ + public function testGetPreferredVariantUserOption() { + global $wgUser; + + $wgUser = new User; + $wgUser->load(); // from 'defaults' + $wgUser->mId = 1; + $wgUser->mDataLoaded = true; + $wgUser->mOptionsLoaded = true; + $wgUser->setOption( 'variant', 'tg-latn' ); + + $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + * @covers LanguageConverter::getUserVariant + */ + public function testGetPreferredVariantUserOptionForForeignLanguage() { + global $wgContLang, $wgUser; + + $wgContLang = Language::factory( 'en' ); + $wgUser = new User; + $wgUser->load(); // from 'defaults' + $wgUser->mId = 1; + $wgUser->mDataLoaded = true; + $wgUser->mOptionsLoaded = true; + $wgUser->setOption( 'variant-tg', 'tg-latn' ); + + $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + * @covers LanguageConverter::getUserVariant + * @covers LanguageConverter::getURLVariant + */ + public function testGetPreferredVariantHeaderUserVsUrl() { + global $wgContLang, $wgRequest, $wgUser; + + $wgContLang = Language::factory( 'tg-latn' ); + $wgRequest->setVal( 'variant', 'tg' ); + $wgUser = User::newFromId( "admin" ); + $wgUser->setId( 1 ); + $wgUser->mFrom = 'defaults'; + $wgUser->mOptionsLoaded = true; + // The user's data is ignored because the variant is set in the URL. + $wgUser->setOption( 'variant', 'tg-latn' ); + $this->assertEquals( 'tg', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + */ + public function testGetPreferredVariantDefaultLanguageVariant() { + global $wgDefaultLanguageVariant; + + $wgDefaultLanguageVariant = 'tg-latn'; + $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() ); + } + + /** + * @covers LanguageConverter::getPreferredVariant + * @covers LanguageConverter::getURLVariant + */ + public function testGetPreferredVariantDefaultLanguageVsUrlVariant() { + global $wgDefaultLanguageVariant, $wgRequest, $wgContLang; + + $wgContLang = Language::factory( 'tg-latn' ); + $wgDefaultLanguageVariant = 'tg'; + $wgRequest->setVal( 'variant', null ); + $this->assertEquals( 'tg', $this->lc->getPreferredVariant() ); + } + + /** + * Test exhausting pcre.backtrack_limit + * + * @covers LanguageConverter::autoConvert + */ + public function testAutoConvertT124404() { + $testString = ''; + for ( $i = 0; $i < 1000; $i++ ) { + $testString .= 'xxx xxx xxx'; + } + $testString .= "\n<big id='в'></big>"; + $old = ini_set( 'pcre.backtrack_limit', 200 ); + $result = $this->lc->autoConvert( $testString, 'tg-latn' ); + ini_set( 'pcre.backtrack_limit', $old ); + // The в in the id attribute should not get converted to a v + $this->assertFalse( + strpos( $result, 'v' ), + "в converted to v despite being in attribue" + ); + } +} + +/** + * Test converter (from Tajiki to latin orthography) + */ +class TestConverter extends LanguageConverter { + private $table = [ + 'б' => 'b', + 'в' => 'v', + 'г' => 'g', + ]; + + function loadDefaultTables() { + $this->mTables = [ + 'tg-latn' => new ReplacementArray( $this->table ), + 'tg' => new ReplacementArray() + ]; + } +} + +class LanguageToTest extends Language { + function __construct() { + parent::__construct(); + $variants = [ 'tg', 'tg-latn' ]; + $this->mConverter = new TestConverter( $this, 'tg', $variants ); + } +} diff --git a/www/wiki/tests/phpunit/languages/LanguageTest.php b/www/wiki/tests/phpunit/languages/LanguageTest.php new file mode 100644 index 00000000..66bd76df --- /dev/null +++ b/www/wiki/tests/phpunit/languages/LanguageTest.php @@ -0,0 +1,1869 @@ +<?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 [ + [ + 9.45, + [], + '9.5 s', + 'formatTimePeriod() rounding (<10s)' + ], + [ + 9.45, + [ 'noabbrevs' => true ], + '9.5 seconds', + 'formatTimePeriod() rounding (<10s)' + ], + [ + 9.95, + [], + '10 s', + 'formatTimePeriod() rounding (<10s)' + ], + [ + 9.95, + [ 'noabbrevs' => true ], + '10 seconds', + 'formatTimePeriod() rounding (<10s)' + ], + [ + 59.55, + [], + '1 min 0 s', + 'formatTimePeriod() rounding (<60s)' + ], + [ + 59.55, + [ 'noabbrevs' => true ], + '1 minute 0 seconds', + 'formatTimePeriod() rounding (<60s)' + ], + [ + 119.55, + [], + '2 min 0 s', + 'formatTimePeriod() rounding (<1h)' + ], + [ + 119.55, + [ 'noabbrevs' => true ], + '2 minutes 0 seconds', + 'formatTimePeriod() rounding (<1h)' + ], + [ + 3599.55, + [], + '1 h 0 min 0 s', + 'formatTimePeriod() rounding (<1h)' + ], + [ + 3599.55, + [ 'noabbrevs' => true ], + '1 hour 0 minutes 0 seconds', + 'formatTimePeriod() rounding (<1h)' + ], + [ + 7199.55, + [], + '2 h 0 min 0 s', + 'formatTimePeriod() rounding (>=1h)' + ], + [ + 7199.55, + [ 'noabbrevs' => true ], + '2 hours 0 minutes 0 seconds', + 'formatTimePeriod() rounding (>=1h)' + ], + [ + 7199.55, + 'avoidseconds', + '2 h 0 min', + 'formatTimePeriod() rounding (>=1h), avoidseconds' + ], + [ + 7199.55, + [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ], + '2 hours 0 minutes', + 'formatTimePeriod() rounding (>=1h), avoidseconds' + ], + [ + 7199.55, + 'avoidminutes', + '2 h 0 min', + 'formatTimePeriod() rounding (>=1h), avoidminutes' + ], + [ + 7199.55, + [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ], + '2 hours 0 minutes', + 'formatTimePeriod() rounding (>=1h), avoidminutes' + ], + [ + 172799.55, + 'avoidseconds', + '48 h 0 min', + 'formatTimePeriod() rounding (=48h), avoidseconds' + ], + [ + 172799.55, + [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ], + '48 hours 0 minutes', + 'formatTimePeriod() rounding (=48h), avoidseconds' + ], + [ + 259199.55, + 'avoidminutes', + '3 d 0 h', + 'formatTimePeriod() rounding (>48h), avoidminutes' + ], + [ + 259199.55, + [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ], + '3 days 0 hours', + 'formatTimePeriod() rounding (>48h), avoidminutes' + ], + [ + 176399.55, + 'avoidseconds', + '2 d 1 h 0 min', + 'formatTimePeriod() rounding (>48h), avoidseconds' + ], + [ + 176399.55, + [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ], + '2 days 1 hour 0 minutes', + 'formatTimePeriod() rounding (>48h), avoidseconds' + ], + [ + 176399.55, + 'avoidminutes', + '2 d 1 h', + 'formatTimePeriod() rounding (>48h), avoidminutes' + ], + [ + 176399.55, + [ 'avoid' => 'avoidminutes', 'noabbrevs' => true ], + '2 days 1 hour', + 'formatTimePeriod() rounding (>48h), avoidminutes' + ], + [ + 259199.55, + 'avoidseconds', + '3 d 0 h 0 min', + 'formatTimePeriod() rounding (>48h), avoidseconds' + ], + [ + 259199.55, + [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ], + '3 days 0 hours 0 minutes', + 'formatTimePeriod() rounding (>48h), avoidseconds' + ], + [ + 172801.55, + 'avoidseconds', + '2 d 0 h 0 min', + 'formatTimePeriod() rounding, (>48h), avoidseconds' + ], + [ + 172801.55, + [ 'avoid' => 'avoidseconds', 'noabbrevs' => true ], + '2 days 0 hours 0 minutes', + 'formatTimePeriod() rounding, (>48h), avoidseconds' + ], + [ + 176460.55, + [], + '2 d 1 h 1 min 1 s', + 'formatTimePeriod() rounding, recursion, (>48h)' + ], + [ + 176460.55, + [ 'noabbrevs' => true ], + '2 days 1 hour 1 minute 1 second', + 'formatTimePeriod() rounding, recursion, (>48h)' + ], + ]; + } + + /** + * @covers Language::truncateForDatabase + * @covers Language::truncateInternal + */ + public function testTruncateForDatabase() { + $this->assertEquals( + "XXX", + $this->getLang()->truncateForDatabase( "1234567890", 0, 'XXX' ), + 'truncate prefix, len 0, small ellipsis' + ); + + $this->assertEquals( + "12345XXX", + $this->getLang()->truncateForDatabase( "1234567890", 8, 'XXX' ), + 'truncate prefix, small ellipsis' + ); + + $this->assertEquals( + "123456789", + $this->getLang()->truncateForDatabase( "123456789", 5, 'XXXXXXXXXXXXXXX' ), + 'truncate prefix, large ellipsis' + ); + + $this->assertEquals( + "XXX67890", + $this->getLang()->truncateForDatabase( "1234567890", -8, 'XXX' ), + 'truncate suffix, small ellipsis' + ); + + $this->assertEquals( + "123456789", + $this->getLang()->truncateForDatabase( "123456789", -5, 'XXXXXXXXXXXXXXX' ), + 'truncate suffix, large ellipsis' + ); + $this->assertEquals( + "123XXX", + $this->getLang()->truncateForDatabase( "123 ", 9, 'XXX' ), + 'truncate prefix, with spaces' + ); + $this->assertEquals( + "12345XXX", + $this->getLang()->truncateForDatabase( "12345 8", 11, 'XXX' ), + 'truncate prefix, with spaces and non-space ending' + ); + $this->assertEquals( + "XXX234", + $this->getLang()->truncateForDatabase( "1 234", -8, 'XXX' ), + 'truncate suffix, with spaces' + ); + $this->assertEquals( + "12345XXX", + $this->getLang()->truncateForDatabase( "1234567890", 5, 'XXX', false ), + 'truncate without adjustment' + ); + $this->assertEquals( + "泰乐菌...", + $this->getLang()->truncateForDatabase( "泰乐菌素123456789", 11, '...', false ), + 'truncate does not chop Unicode characters in half' + ); + $this->assertEquals( + "\n泰乐菌...", + $this->getLang()->truncateForDatabase( "\n泰乐菌素123456789", 12, '...', false ), + 'truncate does not chop Unicode characters in half if there is a preceding newline' + ); + } + + /** + * @dataProvider provideTruncateData + * @covers Language::truncateForVisual + * @covers Language::truncateInternal + */ + public function testTruncateForVisual( + $expected, $string, $length, $ellipsis = '...', $adjustLength = true + ) { + $this->assertEquals( + $expected, + $this->getLang()->truncateForVisual( $string, $length, $ellipsis, $adjustLength ) + ); + } + + /** + * @return array Format is ($expected, $string, $length, $ellipsis, $adjustLength) + */ + public static function provideTruncateData() { + return [ + [ "XXX", "тестирам да ли ради", 0, "XXX" ], + [ "testnXXX", "testni scenarij", 8, "XXX" ], + [ "حالة اختبار", "حالة اختبار", 5, "XXXXXXXXXXXXXXX" ], + [ "XXXедент", "прецедент", -8, "XXX" ], + [ "XXപിൾ", "ആപ്പിൾ", -5, "XX" ], + [ "神秘XXX", "神秘 ", 9, "XXX" ], + [ "ΔημιουργXXX", "Δημιουργία Σύμπαντος", 11, "XXX" ], + [ "XXXの家です", "地球は私たちの唯 の家です", -8, "XXX" ], + [ "زندگیXXX", "زندگی زیباست", 6, "XXX", false ], + [ "ცხოვრება...", "ცხოვრება არის საოცარი", 8, "...", false ], + [ "\nທ່ານ...", "\nທ່ານບໍ່ຮູ້ຫນັງສື", 5, "...", false ], + ]; + } + + /** + * @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 [ + [ 0, 'XXX', "1234567890", "XXX" ], + [ 8, 'XXX', "1234567890", "12345XXX" ], + [ 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ], + [ 2, '***', + '<p><span style="font-weight:bold;"></span></p>', + '<p><span style="font-weight:bold;"></span></p>', + ], + [ 2, '***', + '<p><span style="font-weight:bold;">123456789</span></p>', + '<p><span style="font-weight:bold;">***</span></p>', + ], + [ 2, '***', + '<p><span style="font-weight:bold;"> 23456789</span></p>', + '<p><span style="font-weight:bold;">***</span></p>', + ], + [ 3, '***', + '<p><span style="font-weight:bold;">123456789</span></p>', + '<p><span style="font-weight:bold;">***</span></p>', + ], + [ 4, '***', + '<p><span style="font-weight:bold;">123456789</span></p>', + '<p><span style="font-weight:bold;">1***</span></p>', + ], + [ 5, '***', + '<tt><span style="font-weight:bold;">123456789</span></tt>', + '<tt><span style="font-weight:bold;">12***</span></tt>', + ], + [ 6, '***', + '<p><a href="www.mediawiki.org">123456789</a></p>', + '<p><a href="www.mediawiki.org">123***</a></p>', + ], + [ 6, '***', + '<p><a href="www.mediawiki.org">12 456789</a></p>', + '<p><a href="www.mediawiki.org">12 ***</a></p>', + ], + [ 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>', + ], + [ 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>', + ], + [ 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>', + ], + [ 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 [ + [ 'fr', 'two-letter code' ], + [ 'fr-latn', 'two-letter code with lower case script code' ], + [ 'fr-Latn-FR', 'two-letter code with title case script code and uppercase country code' ], + [ 'fr-Latn-419', 'two-letter code with title case script code and region number' ], + [ 'fr-FR', 'two-letter code with uppercase' ], + [ 'ax-TZ', 'Not in the registry, but well-formed' ], + [ 'fr-shadok', 'two-letter code with variant' ], + [ 'fr-y-myext-myext2', 'non-x singleton' ], + [ 'fra-Latn', 'ISO 639 can be 3-letters' ], + [ 'fra', 'three-letter language code' ], + [ 'fra-FX', 'three-letter language code with country code' ], + [ 'i-klingon', 'grandfathered with singleton' ], + [ 'I-kLINgon', 'tags are case-insensitive...' ], + [ 'no-bok', 'grandfathered without singleton' ], + [ 'i-enochian', 'Grandfathered' ], + [ 'x-fr-CH', 'private use' ], + [ 'es-419', 'two-letter code with region number' ], + [ 'en-Latn-GB-boont-r-extended-sequence-x-private', 'weird, but well-formed' ], + [ 'ab-x-abc-x-abc', 'anything goes after x' ], + [ 'ab-x-abc-a-a', 'anything goes after x, including several non-x singletons' ], + [ 'i-default', 'grandfathered' ], + [ 'abcd-Latn', 'Language of 4 chars reserved for future use' ], + [ 'AaBbCcDd-x-y-any-x', 'Language of 5-8 chars, registered' ], + [ 'de-CH-1901', 'with country and year' ], + [ 'en-US-x-twain', 'with country and singleton' ], + [ 'zh-cmn', 'three-letter variant' ], + [ 'zh-cmn-Hant', 'three-letter variant and script' ], + [ 'zh-cmn-Hant-HK', 'three-letter variant, script and country' ], + [ '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 [ + [ 'f', 'language too short' ], + [ 'f-Latn', 'language too short with script' ], + [ 'xr-lxs-qut', 'variants too short' ], # extlangS + [ 'fr-Latn-F', 'region too short' ], + [ 'a-value', 'language too short with region' ], + [ 'tlh-a-b-foo', 'valid three-letter with wrong variant' ], + [ + 'i-notexist', + 'grandfathered but not registered: invalid, even if we only test well-formedness' + ], + [ 'abcdefghi-012345678', 'numbers too long' ], + [ 'ab-abc-abc-abc-abc', 'invalid extensions' ], + [ 'ab-abcd-abc', 'invalid extensions' ], + [ 'ab-ab-abc', 'invalid extensions' ], + [ 'ab-123-abc', 'invalid extensions' ], + [ 'a-Hant-ZH', 'short language with valid extensions' ], + [ 'a1-Hant-ZH', 'invalid character in language' ], + [ 'ab-abcde-abc', 'invalid extensions' ], + [ 'ab-1abc-abc', 'invalid characters in extensions' ], + [ 'ab-ab-abcd', 'invalid order of extensions' ], + [ 'ab-123-abcd', 'invalid order of extensions' ], + [ 'ab-abcde-abcd', 'invalid extensions' ], + [ 'ab-1abc-abcd', 'invalid characters in extensions' ], + [ 'ab-a-b', 'extensions too short' ], + [ 'ab-a-x', 'extensions too short, even with singleton' ], + [ 'ab--ab', 'two separators' ], + [ 'ab-abc-', 'separator in the end' ], + [ '-ab-abc', 'separator in the beginning' ], + [ 'abcd-efg', 'language too long' ], + [ 'aabbccddE', 'tag too long' ], + [ 'pa_guru', 'A tag with underscore is invalid in strict mode' ], + [ '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, $expected, $message = '' ) { + $this->assertEquals( $expected, + (bool)Language::isValidBuiltInCode( $code ), + "validating code $code $message" + ); + } + + public static function provideLanguageCodes() { + return [ + [ 'fr', true, 'Two letters, minor case' ], + [ 'EN', false, 'Two letters, upper case' ], + [ 'tyv', true, 'Three letters' ], + [ 'be-tarask', true, 'With dash' ], + [ 'be-x-old', true, 'With extension (two dashes)' ], + [ 'be_tarask', false, 'Reject underscores' ], + ]; + } + + /** + * 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 [ + [ 'fr', 'simple code' ], + [ 'bat-smg', 'an MW legacy tag' ], + [ '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 [ + [ 'mw', 'non-existent two-letter code' ], + [ '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 ) { + $ttl = null; + $this->assertEquals( + $expected, + $this->getLang()->sprintfDate( $format, $ts, null, $ttl ), + "sprintfDate('$format', '$ts'): $msg" + ); + if ( $ttl ) { + $dt = new DateTime( $ts ); + $lastValidTS = $dt->add( new DateInterval( 'PT' . ( $ttl - 1 ) . 'S' ) )->format( 'YmdHis' ); + $this->assertEquals( + $expected, + $this->getLang()->sprintfDate( $format, $lastValidTS, null ), + "sprintfDate('$format', '$ts'): TTL $ttl too high (output was different at $lastValidTS)" + ); + } else { + // advance the time enough to make all of the possible outputs different (except possibly L) + $dt = new DateTime( $ts ); + $newTS = $dt->add( new DateInterval( 'P1Y1M8DT13H1M1S' ) )->format( 'YmdHis' ); + $this->assertEquals( + $expected, + $this->getLang()->sprintfDate( $format, $newTS, null ), + "sprintfDate('$format', '$ts'): Missing TTL (output was different at $newTS)" + ); + } + } + + /** + * 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" + ); + } + + /** + * sprintfDate should only calculate a TTL if the caller is going to use it. + * @covers Language::sprintfDate + */ + public function testSprintfDateNoTtlIfNotNeeded() { + $noTtl = 'unused'; // Value used to represent that the caller didn't pass a variable in. + $ttl = null; + $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $noTtl ); + $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $ttl ); + + $this->assertSame( + 'unused', + $noTtl, + 'If the caller does not set the $ttl variable, do not compute it.' + ); + $this->assertInternalType( 'int', $ttl, 'TTL should have been computed.' ); + } + + public static function provideSprintfDateSamples() { + return [ + [ + 'xiY', + '20111212000000', + '1390', // note because we're testing English locale we get Latin-standard digits + '1390', + 'Iranian calendar full year' + ], + [ + 'xiy', + '20111212000000', + '90', + '90', + 'Iranian calendar short year' + ], + [ + 'o', + '20120101235000', + '2011', + '2011', + 'ISO 8601 (week) year' + ], + [ + 'W', + '20120101235000', + '52', + '52', + 'Week number' + ], + [ + 'W', + '20120102235000', + '1', + '1', + 'Week number' + ], + [ + 'o-\\WW-N', + '20091231235000', + '2009-W53-4', + '2009-W53-4', + 'leap week' + ], + // What follows is mostly copied from + // https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time + [ + 'Y', + '20120102090705', + '2012', + '2012', + 'Full year' + ], + [ + 'y', + '20120102090705', + '12', + '12', + '2 digit year' + ], + [ + 'L', + '20120102090705', + '1', + '1', + 'Leap year' + ], + [ + 'n', + '20120102090705', + '1', + '1', + 'Month index, not zero pad' + ], + [ + 'N', + '20120102090705', + '01', + '01', + 'Month index. Zero pad' + ], + [ + 'M', + '20120102090705', + 'Jan', + 'Jan', + 'Month abbrev' + ], + [ + 'F', + '20120102090705', + 'January', + 'January', + 'Full month' + ], + [ + 'xg', + '20120102090705', + 'January', + 'January', + 'Genitive month name (same in EN)' + ], + [ + 'j', + '20120102090705', + '2', + '2', + 'Day of month (not zero pad)' + ], + [ + 'd', + '20120102090705', + '02', + '02', + 'Day of month (zero-pad)' + ], + [ + 'z', + '20120102090705', + '1', + '1', + 'Day of year (zero-indexed)' + ], + [ + 'D', + '20120102090705', + 'Mon', + 'Mon', + 'Day of week (abbrev)' + ], + [ + 'l', + '20120102090705', + 'Monday', + 'Monday', + 'Full day of week' + ], + [ + 'N', + '20120101090705', + '7', + '7', + 'Day of week (Mon=1, Sun=7)' + ], + [ + 'w', + '20120101090705', + '0', + '0', + 'Day of week (Sun=0, Sat=6)' + ], + [ + 'N', + '20120102090705', + '1', + '1', + 'Day of week' + ], + [ + 'a', + '20120102090705', + 'am', + 'am', + 'am vs pm' + ], + [ + 'A', + '20120102120000', + 'PM', + 'PM', + 'AM vs PM' + ], + [ + 'a', + '20120102000000', + 'am', + 'am', + 'AM vs PM' + ], + [ + 'g', + '20120102090705', + '9', + '9', + '12 hour, not Zero' + ], + [ + 'h', + '20120102090705', + '09', + '09', + '12 hour, zero padded' + ], + [ + 'G', + '20120102090705', + '9', + '9', + '24 hour, not zero' + ], + [ + 'H', + '20120102090705', + '09', + '09', + '24 hour, zero' + ], + [ + 'H', + '20120102110705', + '11', + '11', + '24 hour, zero' + ], + [ + 'i', + '20120102090705', + '07', + '07', + 'Minutes' + ], + [ + 's', + '20120102090705', + '05', + '05', + 'seconds' + ], + [ + 'U', + '20120102090705', + '1325495225', + '1325462825', + 'unix time' + ], + [ + 't', + '20120102090705', + '31', + '31', + 'Days in current month' + ], + [ + 'c', + '20120102090705', + '2012-01-02T09:07:05+00:00', + '2012-01-02T09:07:05+09:00', + 'ISO 8601 timestamp' + ], + [ + 'r', + '20120102090705', + 'Mon, 02 Jan 2012 09:07:05 +0000', + 'Mon, 02 Jan 2012 09:07:05 +0900', + 'RFC 5322' + ], + [ + 'e', + '20120102090705', + 'UTC', + 'Asia/Seoul', + 'Timezone identifier' + ], + [ + 'I', + '19880602090705', + '0', + '1', + 'DST indicator' + ], + [ + 'O', + '20120102090705', + '+0000', + '+0900', + 'Timezone offset' + ], + [ + 'P', + '20120102090705', + '+00:00', + '+09:00', + 'Timezone offset with colon' + ], + [ + 'T', + '20120102090705', + 'UTC', + 'KST', + 'Timezone abbreviation' + ], + [ + 'Z', + '20120102090705', + '0', + '32400', + 'Timezone offset in seconds' + ], + [ + 'xmj xmF xmn xmY', + '20120102090705', + '7 Safar 2 1433', + '7 Safar 2 1433', + 'Islamic' + ], + [ + 'xij xiF xin xiY', + '20120102090705', + '12 Dey 10 1390', + '12 Dey 10 1390', + 'Iranian' + ], + [ + 'xjj xjF xjn xjY', + '20120102090705', + '7 Tevet 4 5772', + '7 Tevet 4 5772', + 'Hebrew' + ], + [ + 'xjt', + '20120102090705', + '29', + '29', + 'Hebrew number of days in month' + ], + [ + 'xjx', + '20120102090705', + 'Tevet', + 'Tevet', + 'Hebrew genitive month name (No difference in EN)' + ], + [ + 'xkY', + '20120102090705', + '2555', + '2555', + 'Thai year' + ], + [ + 'xoY', + '20120102090705', + '101', + '101', + 'Minguo' + ], + [ + 'xtY', + '20120102090705', + '平成24', + '平成24', + 'nengo' + ], + [ + 'xtY', + '20190430235959', + '平成31', + '平成31', + 'nengo - last day of heisei' + ], + [ + 'xtY', + '20190501000000', + '令和元', + '令和元', + 'nengo - first day of reiwa' + ], + [ + 'xtY', + '20200501000000', + '令和2', + '令和2', + 'nengo - second year of reiwa' + ], + [ + 'xrxkYY', + '20120102090705', + 'MMDLV2012', + 'MMDLV2012', + 'Roman numerals' + ], + [ + 'xhxjYY', + '20120102090705', + 'ה\'תשע"ב2012', + 'ה\'תשע"ב2012', + 'Hebrew numberals' + ], + [ + 'xnY', + '20120102090705', + '2012', + '2012', + 'Raw numerals (doesn\'t mean much in EN)' + ], + [ + '[[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 [ + [ + 0, + "0 bytes", + "Zero bytes" + ], + [ + 1024, + "1 KB", + "1 kilobyte" + ], + [ + 1024 * 1024, + "1 MB", + "1,024 megabytes" + ], + [ + 1024 * 1024 * 1024, + "1 GB", + "1 gigabyte" + ], + [ + pow( 1024, 4 ), + "1 TB", + "1 terabyte" + ], + [ + pow( 1024, 5 ), + "1 PB", + "1 petabyte" + ], + [ + pow( 1024, 6 ), + "1 EB", + "1,024 exabyte" + ], + [ + pow( 1024, 7 ), + "1 ZB", + "1 zetabyte" + ], + [ + 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 [ + [ + 0, + "0 bps", + "0 bits per second" + ], + [ + 999, + "999 bps", + "999 bits per second" + ], + [ + 1000, + "1 kbps", + "1 kilobit per second" + ], + [ + 1000 * 1000, + "1 Mbps", + "1 megabit per second" + ], + [ + pow( 10, 9 ), + "1 Gbps", + "1 gigabit per second" + ], + [ + pow( 10, 12 ), + "1 Tbps", + "1 terabit per second" + ], + [ + pow( 10, 15 ), + "1 Pbps", + "1 petabit per second" + ], + [ + pow( 10, 18 ), + "1 Ebps", + "1 exabit per second" + ], + [ + pow( 10, 21 ), + "1 Zbps", + "1 zetabit per second" + ], + [ + pow( 10, 24 ), + "1 Ybps", + "1 yottabit per second" + ], + [ + pow( 10, 27 ), + "1,000 Ybps", + "1,000 yottabits per second" + ], + ]; + } + + /** + * @dataProvider provideFormatDuration + * @covers Language::formatDuration + */ + public function testFormatDuration( $duration, $expected, $intervals = [] ) { + $this->assertEquals( + $expected, + $this->getLang()->formatDuration( $duration, $intervals ), + "formatDuration('$duration'): $expected" + ); + } + + public static function provideFormatDuration() { + return [ + [ + 0, + '0 seconds', + ], + [ + 1, + '1 second', + ], + [ + 2, + '2 seconds', + ], + [ + 60, + '1 minute', + ], + [ + 2 * 60, + '2 minutes', + ], + [ + 3600, + '1 hour', + ], + [ + 2 * 3600, + '2 hours', + ], + [ + 24 * 3600, + '1 day', + ], + [ + 2 * 86400, + '2 days', + ], + [ + // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952 + ( 365 + ( 24 * 3 + 25 ) / 400.0 ) * 86400, + '1 year', + ], + [ + 2 * 31556952, + '2 years', + ], + [ + 10 * 31556952, + '1 decade', + ], + [ + 20 * 31556952, + '2 decades', + ], + [ + 100 * 31556952, + '1 century', + ], + [ + 200 * 31556952, + '2 centuries', + ], + [ + 1000 * 31556952, + '1 millennium', + ], + [ + 2000 * 31556952, + '2 millennia', + ], + [ + 9001, + '2 hours, 30 minutes and 1 second' + ], + [ + 3601, + '1 hour and 1 second' + ], + [ + 31556952 + 2 * 86400 + 9000, + '1 year, 2 days, 2 hours and 30 minutes' + ], + [ + 42 * 1000 * 31556952 + 42, + '42 millennia and 42 seconds' + ], + [ + 60, + '60 seconds', + [ 'seconds' ], + ], + [ + 61, + '61 seconds', + [ 'seconds' ], + ], + [ + 1, + '1 second', + [ 'seconds' ], + ], + [ + 31556952 + 2 * 86400 + 9000, + '1 year, 2 days and 150 minutes', + [ 'years', 'days', 'minutes' ], + ], + [ + 42, + '0 days', + [ 'years', 'days' ], + ], + [ + 31556952 + 2 * 86400 + 9000, + '1 year, 2 days and 150 minutes', + [ 'minutes', 'days', 'years' ], + ], + [ + 42, + '0 days', + [ 'days', 'years' ], + ], + ]; + } + + /** + * @dataProvider provideCheckTitleEncodingData + * @covers Language::checkTitleEncoding + */ + public function testCheckTitleEncoding( $s ) { + $this->assertEquals( + $s, + $this->getLang()->checkTitleEncoding( $s ), + "checkTitleEncoding('$s')" + ); + } + + public static function provideCheckTitleEncodingData() { + // phpcs:disable Generic.Files.LineLength + return [ + [ "" ], + [ "United States of America" ], // 7bit ASCII + [ rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ], + [ + rawurldecode( + "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn" + ) + ], + // The following two data sets come from T38839. 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. + [ + 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" + ), + ], + [ + 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" + ) + ] + ]; + // phpcs:enable + } + + /** + * @dataProvider provideRomanNumeralsData + * @covers Language::romanNumeral + */ + public function testRomanNumerals( $num, $numerals ) { + $this->assertEquals( + $numerals, + Language::romanNumeral( $num ), + "romanNumeral('$num')" + ); + } + + public static function provideRomanNumeralsData() { + return [ + [ 1, 'I' ], + [ 2, 'II' ], + [ 3, 'III' ], + [ 4, 'IV' ], + [ 5, 'V' ], + [ 6, 'VI' ], + [ 7, 'VII' ], + [ 8, 'VIII' ], + [ 9, 'IX' ], + [ 10, 'X' ], + [ 20, 'XX' ], + [ 30, 'XXX' ], + [ 40, 'XL' ], + [ 49, 'XLIX' ], + [ 50, 'L' ], + [ 60, 'LX' ], + [ 70, 'LXX' ], + [ 80, 'LXXX' ], + [ 90, 'XC' ], + [ 99, 'XCIX' ], + [ 100, 'C' ], + [ 200, 'CC' ], + [ 300, 'CCC' ], + [ 400, 'CD' ], + [ 500, 'D' ], + [ 600, 'DC' ], + [ 700, 'DCC' ], + [ 800, 'DCCC' ], + [ 900, 'CM' ], + [ 999, 'CMXCIX' ], + [ 1000, 'M' ], + [ 1989, 'MCMLXXXIX' ], + [ 2000, 'MM' ], + [ 3000, 'MMM' ], + [ 4000, 'MMMM' ], + [ 5000, 'MMMMM' ], + [ 6000, 'MMMMMM' ], + [ 7000, 'MMMMMMM' ], + [ 8000, 'MMMMMMMM' ], + [ 9000, 'MMMMMMMMM' ], + [ 9999, 'MMMMMMMMMCMXCIX' ], + [ 10000, 'MMMMMMMMMM' ], + ]; + } + + /** + * @dataProvider provideHebrewNumeralsData + * @covers Language::hebrewNumeral + */ + public function testHebrewNumeral( $num, $numerals ) { + $this->assertEquals( + $numerals, + Language::hebrewNumeral( $num ), + "hebrewNumeral('$num')" + ); + } + + public static function provideHebrewNumeralsData() { + return [ + [ -1, -1 ], + [ 0, 0 ], + [ 1, "א'" ], + [ 2, "ב'" ], + [ 3, "ג'" ], + [ 4, "ד'" ], + [ 5, "ה'" ], + [ 6, "ו'" ], + [ 7, "ז'" ], + [ 8, "ח'" ], + [ 9, "ט'" ], + [ 10, "י'" ], + [ 11, 'י"א' ], + [ 14, 'י"ד' ], + [ 15, 'ט"ו' ], + [ 16, 'ט"ז' ], + [ 17, 'י"ז' ], + [ 20, "כ'" ], + [ 21, 'כ"א' ], + [ 30, "ל'" ], + [ 40, "מ'" ], + [ 50, "נ'" ], + [ 60, "ס'" ], + [ 70, "ע'" ], + [ 80, "פ'" ], + [ 90, "צ'" ], + [ 99, 'צ"ט' ], + [ 100, "ק'" ], + [ 101, 'ק"א' ], + [ 110, 'ק"י' ], + [ 200, "ר'" ], + [ 300, "ש'" ], + [ 400, "ת'" ], + [ 500, 'ת"ק' ], + [ 800, 'ת"ת' ], + [ 1000, "א' אלף" ], + [ 1001, "א'א'" ], + [ 1012, "א'י\"ב" ], + [ 1020, "א'ך'" ], + [ 1030, "א'ל'" ], + [ 1081, "א'פ\"א" ], + [ 2000, "ב' אלפים" ], + [ 2016, "ב'ט\"ז" ], + [ 3000, "ג' אלפים" ], + [ 4000, "ד' אלפים" ], + [ 4904, "ד'תתק\"ד" ], + [ 5000, "ה' אלפים" ], + [ 5680, "ה'תר\"ף" ], + [ 5690, "ה'תר\"ץ" ], + [ 5708, "ה'תש\"ח" ], + [ 5720, "ה'תש\"ך" ], + [ 5740, "ה'תש\"ם" ], + [ 5750, "ה'תש\"ן" ], + [ 5775, "ה'תשע\"ה" ], + ]; + } + + /** + * @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 [ + [ 'plural', 0, [ + 'singular', 'plural' + ] ], + [ 'explicit zero', 0, [ + '0=explicit zero', 'singular', 'plural' + ] ], + [ 'explicit one', 1, [ + 'singular', 'plural', '1=explicit one', + ] ], + [ 'singular', 1, [ + 'singular', 'plural', '0=explicit zero', + ] ], + [ 'plural', 3, [ + '0=explicit zero', '1=explicit one', 'singular', 'plural' + ] ], + [ 'explicit eleven', 11, [ + 'singular', 'plural', '11=explicit eleven', + ] ], + [ 'plural', 12, [ + 'singular', 'plural', '11=explicit twelve', + ] ], + [ 'plural', 12, [ + 'singular', 'plural', '=explicit form', + ] ], + [ 'other', 2, [ + 'kissa=kala', '1=2=3', 'other', + ] ], + [ '', 2, [ + '0=explicit zero', '1=explicit one', + ] ], + ]; + } + + /** + * @covers Language::embedBidi() + */ + public function testEmbedBidi() { + $lre = "\xE2\x80\xAA"; // U+202A LEFT-TO-RIGHT EMBEDDING + $rle = "\xE2\x80\xAB"; // U+202B RIGHT-TO-LEFT EMBEDDING + $pdf = "\xE2\x80\xAC"; // U+202C POP DIRECTIONAL FORMATTING + $lang = $this->getLang(); + $this->assertEquals( + '123', + $lang->embedBidi( '123' ), + 'embedBidi with neutral argument' + ); + $this->assertEquals( + $lre . 'Ben_(WMF)' . $pdf, + $lang->embedBidi( 'Ben_(WMF)' ), + 'embedBidi with LTR argument' + ); + $this->assertEquals( + $rle . 'יהודי (מנוחין)' . $pdf, + $lang->embedBidi( 'יהודי (מנוחין)' ), + 'embedBidi with RTL argument' + ); + } + + /** + * @covers Language::translateBlockExpiry() + * @dataProvider provideTranslateBlockExpiry + */ + public function testTranslateBlockExpiry( $expectedData, $str, $now, $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, null, $now ), $desc ); + } + + public static function provideTranslateBlockExpiry() { + return [ + [ '2 hours', '2 hours', 0, 'simple data from ipboptions' ], + [ 'indefinite', 'infinite', 0, 'infinite from ipboptions' ], + [ 'indefinite', 'infinity', 0, 'alternative infinite from ipboptions' ], + [ 'indefinite', 'indefinite', 0, 'another alternative infinite from ipboptions' ], + [ [ 'formatDuration', 1023 * 60 * 60 ], '1023 hours', 0, 'relative' ], + [ [ 'formatDuration', -1023 ], '-1023 seconds', 0, 'negative relative' ], + [ + [ 'formatDuration', 1023 * 60 * 60 ], + '1023 hours', + wfTimestamp( TS_UNIX, '19910203040506' ), + 'relative with initial timestamp' + ], + [ [ 'formatDuration', 0 ], 'now', 0, 'now' ], + [ + [ 'timeanddate', '20120102070000' ], + '2012-1-1 7:00 +1 day', + 0, + 'mixed, handled as absolute' + ], + [ [ 'timeanddate', '19910203040506' ], '1991-2-3 4:05:06', 0, 'absolute' ], + [ [ 'timeanddate', '19700101000000' ], '1970-1-1 0:00:00', 0, 'absolute at epoch' ], + [ [ 'timeanddate', '19691231235959' ], '1969-12-31 23:59:59', 0, 'time before epoch' ], + [ + [ 'timeanddate', '19910910000000' ], + '10 september', + wfTimestamp( TS_UNIX, '19910203040506' ), + 'partial' + ], + [ 'dummy', 'dummy', 0, 'return garbage as is' ], + ]; + } + + /** + * @dataProvider provideFormatNum + * @covers Language::formatNum + */ + public function testFormatNum( + $translateNumerals, $langCode, $number, $nocommafy, $expected + ) { + $this->setMwGlobals( [ 'wgTranslateNumerals' => $translateNumerals ] ); + $lang = Language::factory( $langCode ); + $formattedNum = $lang->formatNum( $number, $nocommafy ); + $this->assertType( 'string', $formattedNum ); + $this->assertEquals( $expected, $formattedNum ); + } + + public function provideFormatNum() { + return [ + [ true, 'en', 100, false, '100' ], + [ true, 'en', 101, true, '101' ], + [ false, 'en', 103, false, '103' ], + [ false, 'en', 104, true, '104' ], + [ true, 'en', '105', false, '105' ], + [ true, 'en', '106', true, '106' ], + [ false, 'en', '107', false, '107' ], + [ false, 'en', '108', true, '108' ], + ]; + } + + /** + * @covers Language::parseFormattedNumber + * @dataProvider parseFormattedNumberProvider + */ + public function testParseFormattedNumber( $langCode, $number ) { + $lang = Language::factory( $langCode ); + + $localisedNum = $lang->formatNum( $number ); + $normalisedNum = $lang->parseFormattedNumber( $localisedNum ); + + $this->assertEquals( $number, $normalisedNum ); + } + + public function parseFormattedNumberProvider() { + return [ + [ 'de', 377.01 ], + [ 'fa', 334 ], + [ 'fa', 382.772 ], + [ 'ar', 1844 ], + [ 'lzh', 3731 ], + [ 'zh-classical', 7432 ] + ]; + } + + /** + * @covers Language::commafy() + * @dataProvider provideCommafyData + */ + public function testCommafy( $number, $numbersWithCommas ) { + $this->assertEquals( + $numbersWithCommas, + $this->getLang()->commafy( $number ), + "commafy('$number')" + ); + } + + public static function provideCommafyData() { + return [ + [ -1, '-1' ], + [ 10, '10' ], + [ 100, '100' ], + [ 1000, '1,000' ], + [ 10000, '10,000' ], + [ 100000, '100,000' ], + [ 1000000, '1,000,000' ], + [ -1.0001, '-1.0001' ], + [ 1.0001, '1.0001' ], + [ 10.0001, '10.0001' ], + [ 100.0001, '100.0001' ], + [ 1000.0001, '1,000.0001' ], + [ 10000.0001, '10,000.0001' ], + [ 100000.0001, '100,000.0001' ], + [ 1000000.0001, '1,000,000.0001' ], + [ '200000000000000000000', '200,000,000,000,000,000,000' ], + [ '-200000000000000000000', '-200,000,000,000,000,000,000' ], + ]; + } + + /** + * @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( [] ) ); + $this->assertEquals( 'a', $lang->listToText( [ 'a' ] ) ); + $this->assertEquals( "a{$and}{$s}b", $lang->listToText( [ 'a', 'b' ] ) ); + $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( [ 'a', 'b', 'c' ] ) ); + $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( [ '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 [ + [ 'en', true, 'is supported language' ], + [ 'fi', true, 'is supported language' ], + [ 'bunny', false, 'is not supported language' ], + [ '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 [ + [ 'zh-cn', 'zh', 'zh is the parent language of zh-cn' ], + [ 'zh', 'zh', 'zh is defined as the parent language of zh, ' + . 'because zh converter can convert zh-cn to zh' ], + [ 'zh-invalid', null, 'do not be fooled by arbitrarily composed language codes' ], + [ 'de-formal', null, 'de does not have converter' ], + [ 'de', null, 'de does not have converter' ], + ]; + } + + /** + * @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 [ + [ + 'zh', + [ + '文件' => NS_FILE, + '檔案' => NS_FILE, + ], + ], + ]; + } + + /** + * @covers Language::equals + */ + public function testEquals() { + $en1 = new Language(); + $en1->setCode( 'en' ); + + $en2 = Language::factory( 'en' ); + $en2->setCode( 'en' ); + + $this->assertTrue( $en1->equals( $en2 ), 'en equals en' ); + + $fr = Language::factory( 'fr' ); + $this->assertFalse( $en1->equals( $fr ), 'en not equals fr' ); + } +} diff --git a/www/wiki/tests/phpunit/languages/SpecialPageAliasTest.php b/www/wiki/tests/phpunit/languages/SpecialPageAliasTest.php new file mode 100644 index 00000000..0bb6a4d2 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/SpecialPageAliasTest.php @@ -0,0 +1,62 @@ +<?php + +/** + * Verifies that special page aliases are valid, with no slashes. + * + * @group Language + * @group SpecialPageAliases + * @group SystemTest + * @group medium + * + * @author Katie Filbert < aude.wiki@gmail.com > + */ +class SpecialPageAliasTest extends MediaWikiTestCase { + + /** + * @dataProvider validSpecialPageAliasesProvider + */ + public function testValidSpecialPageAliases( $code, $specialPageAliases ) { + foreach ( $specialPageAliases as $specialPage => $aliases ) { + foreach ( $aliases as $alias ) { + $msg = "$specialPage alias '$alias' in $code is valid with no slashes"; + $this->assertRegExp( '/^[^\/]*$/', $msg ); + } + } + } + + public function validSpecialPageAliasesProvider() { + $codes = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) ); + + $data = []; + + foreach ( $codes as $code ) { + $specialPageAliases = $this->getSpecialPageAliases( $code ); + + if ( $specialPageAliases !== [] ) { + $data[] = [ $code, $specialPageAliases ]; + } + } + + return $data; + } + + /** + * @param string $code + * + * @return array + */ + protected function getSpecialPageAliases( $code ) { + $file = Language::getMessagesFileName( $code ); + + if ( is_readable( $file ) ) { + include $file; + + if ( isset( $specialPageAliases ) && $specialPageAliases !== null ) { + return $specialPageAliases; + } + } + + return []; + } + +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageAmTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageAmTest.php new file mode 100644 index 00000000..a44cace4 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageArTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageArTest.php new file mode 100644 index 00000000..f3f5a3f1 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageArTest.php @@ -0,0 +1,89 @@ +<?php +/** + * Based on LanguagMlTest + * @file + */ + +/** + * @covers LanguageAr + */ +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 [ + [ + 'xg "vs" g', + '20120102030410', + 'يناير vs ٣' + ], + [ + 'xmY', + '20120102030410', + '١٤٣٣' + ], + [ + 'xnxmY', + '20120102030410', + '1433' + ], + [ + 'xN xmj xmn xN xmY', + '20120102030410', + ' 7 2 ١٤٣٣' + ], + ]; + } + + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'zero', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'few', 3 ], + [ 'few', 9 ], + [ 'few', 110 ], + [ 'many', 11 ], + [ 'many', 15 ], + [ 'many', 99 ], + [ 'many', 9999 ], + [ 'other', 100 ], + [ 'other', 102 ], + [ 'other', 1000 ], + [ 'other', 1.7 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageArqTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageArqTest.php new file mode 100644 index 00000000..e6692d17 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageArqTest.php @@ -0,0 +1,26 @@ +<?php +/** + * Based on LanguageMlTest + * @author Joel Sahleen + * @copyright Copyright © 2014, Joel Sahleen + * @file + */ + +/** Tests for MediaWiki languages/LanguageArq.php */ +class LanguageArqTest extends LanguageClassesTestCase { + /** + * @dataProvider provideNumber + * @covers Language::formatNum + */ + public function testFormatNum( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->formatNum( $value ) ); + } + + public static function provideNumber() { + return [ + [ '1.234.567', '1234567' ], + [ '-12,89', -12.89 ], + ]; + } + +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageBeTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageBeTest.php new file mode 100644 index 00000000..de1adb7d --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 1 ], + [ 'many', 11 ], + [ 'one', 91 ], + [ 'one', 121 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'few', 334 ], + [ 'many', 5 ], + [ 'many', 15 ], + [ 'many', 120 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageBe_taraskTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageBe_taraskTest.php new file mode 100644 index 00000000..4f049cd1 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageBe_taraskTest.php @@ -0,0 +1,100 @@ +<?php + +// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps +/** + * @covers LanguageBe_tarask + */ +class LanguageBe_taraskTest extends LanguageClassesTestCase { + // phpcs:enable + /** + * 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 T25156 & r64981 + * @covers Language::commafy + */ + public function testSearchRightSingleQuotationMarkAsApostroph() { + $this->assertEquals( + "'", + $this->getLang()->normalizeForSearch( '’' ), + 'T25156: U+2019 conversion to U+0027' + ); + } + + /** + * @see T25156 & 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 T25156 & 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 = [ '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 [ + [ 'one', 1 ], + [ 'many', 11 ], + [ 'one', 91 ], + [ 'one', 121 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'few', 334 ], + [ 'many', 5 ], + [ 'many', 15 ], + [ 'many', 120 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ '1=one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'other', 11 ], + [ 'other', 91 ], + [ 'other', 121 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageBhoTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageBhoTest.php new file mode 100644 index 00000000..a9aba202 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageBsTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageBsTest.php new file mode 100644 index 00000000..29b2ccf3 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageBsTest.php @@ -0,0 +1,46 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** + * Tests for Croatian (hrvatski) + * + * @covers LanguageBs + */ +class LanguageBsTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 4 ], + [ 'other', 5 ], + [ 'other', 11 ], + [ 'other', 20 ], + [ 'one', 21 ], + [ 'few', 24 ], + [ 'other', 25 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageCrhTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageCrhTest.php new file mode 100644 index 00000000..7c99614e --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageCrhTest.php @@ -0,0 +1,92 @@ +<?php + +/** + * @covers LanguageCrh + * @covers CrhConverter + */ +class LanguageCrhTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + [ // general words, covering more of the alphabet + [ + 'crh' => 'рузгярнынъ ruzgârnıñ Париж Parij', + 'crh-cyrl' => 'рузгярнынъ рузгярнынъ Париж Париж', + 'crh-latn' => 'ruzgârnıñ ruzgârnıñ Parij Parij', + ], + 'рузгярнынъ ruzgârnıñ Париж Parij' + ], + [ // general words, covering more of the alphabet + [ + 'crh' => 'чёкюч çöküç элифбени elifbeni полициясы politsiyası', + 'crh-cyrl' => 'чёкюч чёкюч элифбени элифбени полициясы полициясы', + 'crh-latn' => 'çöküç çöküç elifbeni elifbeni politsiyası politsiyası', + ], + 'чёкюч çöküç элифбени elifbeni полициясы politsiyası' + ], + [ // general words, covering more of the alphabet + [ + 'crh' => 'хусусында hususında акъшамларны aqşamlarnı опькеленюв öpkelenüv', + 'crh-cyrl' => 'хусусында хусусында акъшамларны акъшамларны опькеленюв опькеленюв', + 'crh-latn' => 'hususında hususında aqşamlarnı aqşamlarnı öpkelenüv öpkelenüv', + ], + 'хусусында hususında акъшамларны aqşamlarnı опькеленюв öpkelenüv' + ], + [ // general words, covering more of the alphabet + [ + 'crh' => 'кулюмсиреди külümsiredi айтмайджагъым aytmaycağım козьяшсыз közyaşsız', + 'crh-cyrl' => 'кулюмсиреди кулюмсиреди айтмайджагъым айтмайджагъым козьяшсыз козьяшсыз', + 'crh-latn' => 'külümsiredi külümsiredi aytmaycağım aytmaycağım közyaşsız közyaşsız', + ], + 'кулюмсиреди külümsiredi айтмайджагъым aytmaycağım козьяшсыз közyaşsız' + ], + [ // exception words + [ + 'crh' => 'инструменталь instrumental гургуль gürgül тюшюнмемек tüşünmemek', + 'crh-cyrl' => 'инструменталь инструменталь гургуль гургуль тюшюнмемек тюшюнмемек', + 'crh-latn' => 'instrumental instrumental gürgül gürgül tüşünmemek tüşünmemek', + ], + 'инструменталь instrumental гургуль gürgül тюшюнмемек tüşünmemek' + ], + [ // recent problem words, part 1 + [ + 'crh' => 'künü куню sürgünligi сюргюнлиги özü озю etti этти', + 'crh-cyrl' => 'куню куню сюргюнлиги сюргюнлиги озю озю этти этти', + 'crh-latn' => 'künü künü sürgünligi sürgünligi özü özü etti etti', + ], + 'künü куню sürgünligi сюргюнлиги özü озю etti этти' + ], + [ // recent problem words, part 2 + [ + 'crh' => 'esas эсас dört дёрт keldi кельди', + 'crh-cyrl' => 'эсас эсас дёрт дёрт кельди кельди', + 'crh-latn' => 'esas esas dört dört keldi keldi', + ], + 'esas эсас dört дёрт keldi кельди' + ], + [ // multi part words + [ + 'crh' => 'эки юз eki yüz', + 'crh-cyrl' => 'эки юз эки юз', + 'crh-latn' => 'eki yüz eki yüz', + ], + 'эки юз eki yüz' + ], + [ // ALL CAPS, made up acronyms (not 100% sure these are correct) + [ + 'crh' => 'ÑAB QIC ĞUK COT НЪАБ КЪЫДж ГЪУК ДЖОТ CA ДЖА', + 'crh-cyrl' => 'НЪАБ КЪЫДж ГЪУК ДЖОТ НЪАБ КЪЫДж ГЪУК ДЖОТ ДЖА ДЖА', + 'crh-latn' => 'ÑAB QIC ĞUK COT ÑAB QIC ĞUK COT CA CA', + ], + 'ÑAB QIC ĞUK COT НЪАБ КЪЫДж ГЪУК ДЖОТ CA ДЖА' + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageCsTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageCsTest.php new file mode 100644 index 00000000..2d38ee8d --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'other', 5 ], + [ 'other', 11 ], + [ 'other', 20 ], + [ 'other', 25 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageCuTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageCuTest.php new file mode 100644 index 00000000..565a8856 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageCuTest.php @@ -0,0 +1,44 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** + * @covers LanguageCu + */ +class LanguageCuTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'other', 5 ], + [ 'one', 11 ], + [ 'other', 20 ], + [ 'two', 22 ], + [ 'few', 223 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageCyTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageCyTest.php new file mode 100644 index 00000000..bd078722 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'zero', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'few', 3 ], + [ 'many', 6 ], + [ 'other', 4 ], + [ 'other', 5 ], + [ 'other', 11 ], + [ 'other', 20 ], + [ 'other', 22 ], + [ 'other', 223 ], + [ 'other', 200.00 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageDsbTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageDsbTest.php new file mode 100644 index 00000000..877a70cd --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageDsbTest.php @@ -0,0 +1,43 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** + * @covers LanguageDsb + */ +class LanguageDsbTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'one', 101 ], + [ 'one', 90001 ], + [ 'two', 2 ], + [ 'few', 3 ], + [ 'few', 203 ], + [ 'few', 4 ], + [ 'other', 99 ], + [ 'other', 555 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageFrTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageFrTest.php new file mode 100644 index 00000000..af6893ae --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageGaTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageGaTest.php new file mode 100644 index 00000000..2ef5edb2 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageGanTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageGanTest.php new file mode 100644 index 00000000..c5d9e5e6 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageGanTest.php @@ -0,0 +1,38 @@ +<?php + +/** + * @covers LanguageGan + * @covers GanConverter + */ +class LanguageGanTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + // zh2Hans + [ + [ + 'gan' => '㑯', + 'gan-hans' => '㑔', + 'gan-hant' => '㑯', + ], + '㑯' + ], + // zh2Hant + [ + [ + 'gan' => '㐷', + 'gan-hans' => '㐷', + 'gan-hant' => '傌', + ], + '㐷' + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageGdTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageGdTest.php new file mode 100644 index 00000000..4be4fded --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ 'one', 'two', 'few', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providerPlural() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'one', 11 ], + [ 'two', 12 ], + [ 'few', 3 ], + [ 'few', 19 ], + [ 'other', 200 ], + ]; + } + + /** + * @dataProvider providerPluralExplicit + * @covers Language::convertPlural + */ + public function testExplicitPlural( $result, $value ) { + $forms = [ 'one', 'two', 'few', 'other', '11=Form11', '12=Form12' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providerPluralExplicit() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'Form11', 11 ], + [ 'Form12', 12 ], + [ 'few', 3 ], + [ 'few', 19 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageGvTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageGvTest.php new file mode 100644 index 00000000..20e47867 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'few', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'other', 3 ], + [ 'few', 20 ], + [ 'one', 21 ], + [ 'two', 22 ], + [ 'other', 23 ], + [ 'other', 50 ], + [ 'few', 60 ], + [ 'few', 80 ], + [ 'few', 100 ] + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageHeTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageHeTest.php new file mode 100644 index 00000000..c1b774af --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageHeTest.php @@ -0,0 +1,132 @@ +<?php +/** + * @author Amir E. Aharoni + * @copyright Copyright © 2012, Amir E. Aharoni + * @file + */ + +/** Tests for MediaWiki Hebrew grammar transformation handling */ +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 = [ 'one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + /** + * @dataProvider provideThreePluralForms + * @covers Language::convertPlural + */ + public function testThreePluralForms( $result, $value ) { + $forms = [ 'one', 'two', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + /** + * @dataProvider provideFourPluralForms + * @covers Language::convertPlural + */ + public function testFourPluralForms( $result, $value ) { + $forms = [ '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 [ + [ 'other', 0 ], // Zero - plural + [ 'one', 1 ], // Singular + [ 'other', 2 ], // No third form provided, use it as plural + [ 'other', 3 ], // Plural - other + [ 'other', 10 ], // No fourth form provided, use it as plural + [ 'other', 20 ], // No fourth form provided, use it as plural + ]; + } + + public static function provideThreePluralForms() { + return [ + [ 'other', 0 ], // Zero - plural + [ 'one', 1 ], // Singular + [ 'two', 2 ], // Dual + [ 'other', 3 ], // Plural - other + [ 'other', 10 ], // No fourth form provided, use it as plural + [ 'other', 20 ], // No fourth form provided, use it as plural + ]; + } + + public static function provideFourPluralForms() { + return [ + [ 'other', 0 ], // Zero - plural + [ 'one', 1 ], // Singular + [ 'two', 2 ], // Dual + [ 'other', 3 ], // Plural - other + [ 'other', 10 ], // 10 is supposed to be plural (other), not "many" + [ '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 [ + [ + /* result */'וויקיפדיה', + /* word */'ויקיפדיה', + /* case */'תחילית', + ], + [ + /* result */'וולפגנג', + /* word */'וולפגנג', + /* case */'prefixed', + ], + [ + /* result */'קובץ', + /* word */'הקובץ', + /* case */'תחילית', + ], + [ + /* result */'־Wikipedia', + /* word */'Wikipedia', + /* case */'תחילית', + ], + [ + /* result */'־1995', + /* word */'1995', + /* case */'תחילית', + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageHiTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageHiTest.php new file mode 100644 index 00000000..72c75757 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageHrTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageHrTest.php new file mode 100644 index 00000000..746e713e --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 4 ], + [ 'other', 5 ], + [ 'other', 11 ], + [ 'other', 20 ], + [ 'one', 21 ], + [ 'few', 24 ], + [ 'other', 25 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageHsbTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageHsbTest.php new file mode 100644 index 00000000..0841f6f9 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageHsbTest.php @@ -0,0 +1,43 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** + * @covers LanguageHsb + */ +class LanguageHsbTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'one', 101 ], + [ 'one', 90001 ], + [ 'two', 2 ], + [ 'few', 3 ], + [ 'few', 203 ], + [ 'few', 4 ], + [ 'other', 99 ], + [ 'other', 555 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageHuTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageHuTest.php new file mode 100644 index 00000000..a1925bdf --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageHuTest.php @@ -0,0 +1,37 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** + * @covers LanguageHu + */ +class LanguageHuTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageHyTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageHyTest.php new file mode 100644 index 00000000..b4936154 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageHyTest.php @@ -0,0 +1,39 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** + * Tests for Armenian (Հայերեն) + * + * @covers LanguageHy + */ +class LanguageHyTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageIuTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageIuTest.php new file mode 100644 index 00000000..01d97fc0 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageIuTest.php @@ -0,0 +1,38 @@ +<?php + +/** + * @covers LanguageIu + * @covers IuConverter + */ +class LanguageIuTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + // ike-cans + [ + [ + 'ike-cans' => 'ᐴ', + 'ike-latn' => 'PUU', + 'iu' => 'PUU', + ], + 'PUU' + ], + // ike-latn + [ + [ + 'ike-cans' => 'ᐴ', + 'ike-latn' => 'puu', + 'iu' => 'ᐴ', + ], + 'ᐴ' + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageKkTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageKkTest.php new file mode 100644 index 00000000..f21950e0 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageKkTest.php @@ -0,0 +1,33 @@ +<?php + +/** + * @covers LanguageKk + * @covers LanguageKk_cyrl + * @covers KkConverter + */ +class LanguageKkTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + [ + [ + 'kk' => 'Адамдарға ақыл-парасат, ар-ождан берілген', + 'kk-cyrl' => 'Адамдарға ақыл-парасат, ар-ождан берілген', + 'kk-latn' => 'Adamdarğa aqıl-parasat, ar-ojdan berilgen', + 'kk-arab' => 'ادامدارعا اقىل-پاراسات، ار-وجدان بەرىلگەن', + 'kk-kz' => 'Адамдарға ақыл-парасат, ар-ождан берілген', + 'kk-tr' => 'Adamdarğa aqıl-parasat, ar-ojdan berilgen', + 'kk-cn' => 'ادامدارعا اقىل-پاراسات، ار-وجدان بەرىلگەن' + ], + 'Адамдарға ақыл-парасат, ар-ождан берілген' + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageKshTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageKshTest.php new file mode 100644 index 00000000..6419e281 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageKshTest.php @@ -0,0 +1,37 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Santhosh Thottingal + * @file + */ + +/** + * @covers LanguageKsh + */ +class LanguageKshTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'zero', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageKuTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageKuTest.php new file mode 100644 index 00000000..db693088 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageKuTest.php @@ -0,0 +1,44 @@ +<?php + +/** + * @covers LanguageKu + * @covers KuConverter + */ +class LanguageKuTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + [ + [ + 'ku' => '١', + 'ku-arab' => '١', + 'ku-latn' => '1', + ], + '١' + ], + [ + [ + 'ku' => 'Wîkîpediya ensîklopediyeke azad bi rengê wîkî ye.', + 'ku-arab' => 'ویکیپەدیائە نسیکلۆپەدیەکەئا زاد ب رەنگێ ویکی یە.', + 'ku-latn' => 'Wîkîpediya ensîklopediyeke azad bi rengê wîkî ye.', + ], + 'Wîkîpediya ensîklopediyeke azad bi rengê wîkî ye.' + ], + [ + [ + 'ku' => 'ویکیپەدیا ەنسیکلۆپەدیەکەئا زاد ب رەنگێ ویکی یە.', + 'ku-arab' => 'ویکیپەدیا ەنسیکلۆپەدیەکەئا زاد ب رەنگێ ویکی یە.', + 'ku-latn' => 'wîkîpedîa ensîklopedîekea zad b rengê wîkî îe.', + ], + 'ویکیپەدیا ەنسیکلۆپەدیەکەئا زاد ب رەنگێ ویکی یە.' + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageLnTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageLnTest.php new file mode 100644 index 00000000..34bd1791 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageLtTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageLtTest.php new file mode 100644 index 00000000..dc7ef454 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 9 ], + [ 'other', 10 ], + [ 'other', 11 ], + [ 'other', 20 ], + [ 'one', 21 ], + [ 'few', 32 ], + [ 'one', 41 ], + [ 'one', 40001 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testOneFewPlural( $result, $value ) { + $forms = [ 'one', 'other' ]; + // This fails for 21, but not sure why. + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 15 ], + [ 'other', 20 ], + [ 'one', 21 ], + [ 'other', 22 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageLvTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageLvTest.php new file mode 100644 index 00000000..9827c68b --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'zero', 0 ], + [ 'one', 1 ], + [ 'zero', 11 ], + [ 'one', 21 ], + [ 'zero', 411 ], + [ 'other', 2 ], + [ 'other', 9 ], + [ 'zero', 12 ], + [ 'other', 12.345 ], + [ 'zero', 20 ], + [ 'other', 22 ], + [ 'one', 31 ], + [ 'zero', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageMgTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageMgTest.php new file mode 100644 index 00000000..7a84c071 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 200 ], + [ 'other', 123.3434 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageMkTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageMkTest.php new file mode 100644 index 00000000..6469a063 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'one', 11 ], + [ 'one', 21 ], + [ 'one', 411 ], + [ 'other', 12.345 ], + [ 'other', 20 ], + [ 'one', 31 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageMlTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageMlTest.php new file mode 100644 index 00000000..673b5c77 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageMlTest.php @@ -0,0 +1,40 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2011, Santhosh Thottingal + * @file + */ + +/** + * @covers LanguageMl + */ +class LanguageMlTest extends LanguageClassesTestCase { + + /** + * @dataProvider providerFormatNum + * T31495 + * @covers Language::formatNum + */ + public function testFormatNum( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->formatNum( $value ) ); + } + + public static function providerFormatNum() { + return [ + [ '12,34,567', '1234567' ], + [ '12,345', '12345' ], + [ '1', '1' ], + [ '123', '123' ], + [ '1,234', '1234' ], + [ '12,345.56', '12345.56' ], + [ '12,34,56,79,81,23,45,678', '12345679812345678' ], + [ '.12345', '.12345' ], + [ '-12,00,000', '-1200000' ], + [ '-98', '-98' ], + [ '-98', -98 ], + [ '-1,23,45,678', -12345678 ], + [ '', '' ], + [ '', null ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageMoTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageMoTest.php new file mode 100644 index 00000000..d11bad2f --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'few', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 19 ], + [ 'other', 20 ], + [ 'other', 99 ], + [ 'other', 100 ], + [ 'few', 101 ], + [ 'few', 119 ], + [ 'other', 120 ], + [ 'other', 200 ], + [ 'few', 201 ], + [ 'few', 219 ], + [ 'other', 220 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageMtTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageMtTest.php new file mode 100644 index 00000000..d8a0d7a1 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'few', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 10 ], + [ 'many', 11 ], + [ 'many', 19 ], + [ 'other', 20 ], + [ 'other', 99 ], + [ 'other', 100 ], + [ 'other', 101 ], + [ 'few', 102 ], + [ 'few', 110 ], + [ 'many', 111 ], + [ 'many', 119 ], + [ 'other', 120 ], + [ 'other', 201 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ 'one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 10 ], + [ 'other', 11 ], + [ 'other', 19 ], + [ 'other', 20 ], + [ 'other', 99 ], + [ 'other', 100 ], + [ 'other', 101 ], + [ 'other', 102 ], + [ 'other', 110 ], + [ 'other', 111 ], + [ 'other', 119 ], + [ 'other', 120 ], + [ 'other', 201 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageNlTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageNlTest.php new file mode 100644 index 00000000..26bd691a --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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/www/wiki/tests/phpunit/languages/classes/LanguageNsoTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageNsoTest.php new file mode 100644 index 00000000..f1783431 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguagePlTest.php b/www/wiki/tests/phpunit/languages/classes/LanguagePlTest.php new file mode 100644 index 00000000..14877290 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguagePlTest.php @@ -0,0 +1,104 @@ +<?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 = [ '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 [ + [ 'many', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'many', 5 ], + [ 'many', 9 ], + [ 'many', 10 ], + [ 'many', 11 ], + [ 'many', 21 ], + [ 'few', 22 ], + [ 'few', 23 ], + [ 'few', 24 ], + [ 'many', 25 ], + [ 'many', 200 ], + [ 'many', 201 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ 'one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 3 ], + [ 'other', 4 ], + [ 'other', 5 ], + [ 'other', 9 ], + [ 'other', 10 ], + [ 'other', 11 ], + [ 'other', 21 ], + [ 'other', 22 ], + [ 'other', 23 ], + [ 'other', 24 ], + [ 'other', 25 ], + [ 'other', 200 ], + [ 'other', 201 ], + ]; + } + + /** + * @covers Language::commafy() + * @dataProvider provideCommafyData + */ + public function testCommafy( $number, $numbersWithCommas ) { + $this->assertEquals( + $numbersWithCommas, + $this->getLang()->commafy( $number ), + "commafy('$number')" + ); + } + + public static function provideCommafyData() { + // Note that commafy() always uses English separators (',' and '.') instead of + // Polish (' ' and ','). There is another function that converts them later. + return [ + [ 1000, '1000' ], + [ 10000, '10,000' ], + [ 1000.0001, '1000.0001' ], + [ 10000.0001, '10,000.0001' ], + [ -1000, '-1000' ], + [ -10000, '-10,000' ], + [ -1000.0001, '-1000.0001' ], + [ -10000.0001, '-10,000.0001' ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageRoTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageRoTest.php new file mode 100644 index 00000000..bbe26f63 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'few', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 19 ], + [ 'other', 20 ], + [ 'other', 99 ], + [ 'other', 100 ], + [ 'few', 101 ], + [ 'few', 119 ], + [ 'other', 120 ], + [ 'other', 200 ], + [ 'few', 201 ], + [ 'few', 219 ], + [ 'other', 220 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageRuTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageRuTest.php new file mode 100644 index 00000000..a34c03fd --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageRuTest.php @@ -0,0 +1,189 @@ +<?php +/** + * @author Amir E. Aharoni + * based on LanguageBe_tarask.php + * @copyright Copyright © 2012, Amir E. Aharoni + * @file + */ + +class LanguageRuTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 = [ 'one', 'few', 'many', 'other', '12=dozen' ]; + $this->assertEquals( 'dozen', $this->getLang()->convertPlural( 12, $forms ) ); + $forms = [ '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 [ + [ 'one', 1 ], + [ 'many', 11 ], + [ 'one', 91 ], + [ 'one', 121 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'few', 334 ], + [ 'many', 5 ], + [ 'many', 15 ], + [ 'many', 120 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ '1=one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'one', 1 ], + [ 'other', 11 ], + [ 'other', 91 ], + [ '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 [ + [ + 'Википедии', + 'Википедия', + 'genitive', + ], + [ + 'Викитеки', + 'Викитека', + 'genitive', + ], + [ + 'Викитеке', + 'Викитека', + 'prepositional', + ], + [ + 'Викисклада', + 'Викисклад', + 'genitive', + ], + [ + 'Викиверситета', + 'Викиверситет', + 'genitive', + ], + [ + 'Викискладе', + 'Викисклад', + 'prepositional', + ], + [ + 'Викиданных', + 'Викиданные', + 'prepositional', + ], + [ + 'Викиверситете', + 'Викиверситет', + 'prepositional', + ], + [ + 'русского', + 'русский', + 'languagegen', + ], + [ + 'немецкого', + 'немецкий', + 'languagegen', + ], + [ + 'иврита', + 'иврит', + 'languagegen', + ], + [ + 'эсперанто', + 'эсперанто', + 'languagegen', + ], + [ + 'русском', + 'русский', + 'languageprep', + ], + [ + 'немецком', + 'немецкий', + 'languageprep', + ], + [ + 'идише', + 'идиш', + 'languageprep', + ], + [ + 'эсперанто', + 'эсперанто', + 'languageprep', + ], + [ + 'по-русски', + 'русский', + 'languageadverb', + ], + [ + 'по-немецки', + 'немецкий', + 'languageadverb', + ], + [ + 'на иврите', + 'иврит', + 'languageadverb', + ], + [ + 'на эсперанто', + 'эсперанто', + 'languageadverb', + ], + [ + 'на языке гуарани', + 'гуарани', + 'languageadverb', + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageSeTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageSeTest.php new file mode 100644 index 00000000..b0da3983 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'other', 3 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ 'one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 3 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageSgsTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageSgsTest.php new file mode 100644 index 00000000..7721433d --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'few', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'other', 3 ], + [ 'few', 10 ], + [ 'few', 11 ], + [ 'few', 12 ], + [ 'few', 19 ], + [ 'other', 20 ], + [ 'few', 100 ], + [ 'one', 101 ], + [ 'few', 111 ], + [ 'few', 112 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ 'one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 3 ], + [ 'other', 10 ], + [ 'other', 11 ], + [ 'other', 12 ], + [ 'other', 19 ], + [ 'other', 20 ], + [ 'other', 100 ], + [ 'one', 101 ], + [ 'other', 111 ], + [ 'other', 112 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageShTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageShTest.php new file mode 100644 index 00000000..2a669178 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 4 ], + [ 'other', 5 ], + [ 'other', 10 ], + [ 'other', 11 ], + [ 'other', 12 ], + [ 'one', 101 ], + [ 'few', 102 ], + [ 'other', 111 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageShiTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageShiTest.php new file mode 100644 index 00000000..1d0f8635 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageShiTest.php @@ -0,0 +1,36 @@ +<?php + +/** + * @covers LanguageShi + * @covers ShiConverter + */ +class LanguageShiTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + [ + [ + 'shi' => 'AƔ', + 'shi-tfng' => 'ⴰⵖ', + 'shi-latn' => 'AƔ', + ], + 'AƔ' + ], + [ + [ + 'shi' => 'ⴰⵖ', + 'shi-tfng' => 'ⴰⵖ', + 'shi-latn' => 'aɣ', + ], + 'ⴰⵖ' + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageSkTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageSkTest.php new file mode 100644 index 00000000..dd9a9ab1 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'other', 5 ], + [ 'other', 11 ], + [ 'other', 20 ], + [ 'other', 25 ], + [ 'other', 200 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageSlTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageSlTest.php new file mode 100644 index 00000000..50100ce7 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageSlTest.php @@ -0,0 +1,46 @@ +<?php +/** + * @author Santhosh Thottingal + * @copyright Copyright © 2012, Amir E. Aharoni + * based on LanguageSkTest.php + * @file + */ + +/** + * @covers LanguageSl + */ +class LanguageSlTest extends LanguageClassesTestCase { + /** + * @dataProvider providerPlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'other', 5 ], + [ 'other', 99 ], + [ 'other', 100 ], + [ 'one', 101 ], + [ 'two', 102 ], + [ 'few', 103 ], + [ 'one', 201 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageSmaTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageSmaTest.php new file mode 100644 index 00000000..6b859943 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'two', 2 ], + [ 'other', 3 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ 'one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'other', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + [ 'other', 3 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageSrTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageSrTest.php new file mode 100644 index 00000000..e81d5370 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageSrTest.php @@ -0,0 +1,252 @@ +<?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.. + */ + +/** + * @covers LanguageSr + * @covers SrConverter + */ +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 = [ '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 [ + [ 'one', 1 ], + [ 'other', 11 ], + [ 'one', 91 ], + [ 'one', 121 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'few', 334 ], + [ 'other', 5 ], + [ 'other', 15 ], + [ 'other', 120 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ 'one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'one', 1 ], + [ 'other', 11 ], + [ 'other', 4 ], + [ 'one', 91 ], + [ 'one', 121 ], + ]; + } + + # #### HELPERS ##################################################### + /** + *Wrapper to verify text stay the same after applying conversion + * @param string $text Text to convert + * @param string $variant Language variant 'sr-ec' or 'sr-el' + * @param string $msg 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 string $text Text to convert + * @param string $variant Language variant 'sr-ec' or 'sr-el' + * @param string $msg 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. + * @param string $text Text to convert + * @param string $msg Optional message + */ + 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. + * @param string $text Text to convert + * @param string $msg Optional message + */ + 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/www/wiki/tests/phpunit/languages/classes/LanguageTgTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageTgTest.php new file mode 100644 index 00000000..89697675 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageTgTest.php @@ -0,0 +1,34 @@ +<?php + +/** + * @covers LanguageTg + * @covers TgConverter + */ +class LanguageTgTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + [ + [ + 'tg' => 'г', + 'tg-latn' => 'g', + ], + 'г' + ], + [ + [ + 'tg' => 'g', + 'tg-latn' => 'g', + ], + 'g' + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageTiTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageTiTest.php new file mode 100644 index 00000000..66f11848 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageTlTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageTlTest.php new file mode 100644 index 00000000..09fef2da --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageTlTest.php @@ -0,0 +1,36 @@ +<?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 = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'one', 2 ], + [ 'other', 4 ], + [ 'other', 6 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageTrTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageTrTest.php new file mode 100644 index 00000000..3ddf2d03 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageTrTest.php @@ -0,0 +1,63 @@ +<?php +/** + * @author Antoine Musso + * @copyright Copyright © 2011, Antoine Musso + * @file + */ + +/** + * @covers LanguageTr + */ +class LanguageTrTest extends LanguageClassesTestCase { + + /** + * See T30040 + * Credits to irc://irc.freenode.net/wikipedia-tr users: + * - berm + * - []LuCkY[] + * - Emperyan + * @see https://en.wikipedia.org/wiki/Dotted_and_dotless_I + * @dataProvider provideDottedAndDotlessI + * @covers Language::ucfirst + * @covers Language::lcfirst + */ + 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 [ + # function, input, input case, expected + # Case changed: + [ 'ucfirst', 'ı', 'lower', 'I' ], + [ 'ucfirst', 'i', 'lower', 'İ' ], + [ 'lcfirst', 'I', 'upper', 'ı' ], + [ 'lcfirst', 'İ', 'upper', 'i' ], + + # Already using the correct case + [ 'ucfirst', 'I', 'upper', 'I' ], + [ 'ucfirst', 'İ', 'upper', 'İ' ], + [ 'lcfirst', 'ı', 'lower', 'ı' ], + [ 'lcfirst', 'i', 'lower', 'i' ], + + # A real example taken from T30040 using + # https://tr.wikipedia.org/wiki/%C4%B0Phone + [ 'lcfirst', 'iPhone', 'lower', 'iPhone' ], + + # next case is valid in Turkish but are different words if we + # consider IPhone is English! + [ 'lcfirst', 'IPhone', 'upper', 'ıPhone' ], + + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageUkTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageUkTest.php new file mode 100644 index 00000000..0ccebbe2 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageUkTest.php @@ -0,0 +1,109 @@ +<?php +/** + * @author Amir E. Aharoni + * based on LanguageBe_tarask.php + * @copyright Copyright © 2012, Amir E. Aharoni + * @file + */ + +class LanguageUkTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 = [ 'one', 'few', 'many', 'other', '12=dozen' ]; + $this->assertEquals( 'dozen', $this->getLang()->convertPlural( 12, $forms ) ); + $forms = [ '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 [ + [ 'one', 1 ], + [ 'many', 11 ], + [ 'one', 91 ], + [ 'one', 121 ], + [ 'few', 2 ], + [ 'few', 3 ], + [ 'few', 4 ], + [ 'few', 334 ], + [ 'many', 5 ], + [ 'many', 15 ], + [ 'many', 120 ], + ]; + } + + /** + * @dataProvider providePluralTwoForms + * @covers Language::convertPlural + */ + public function testPluralTwoForms( $result, $value ) { + $forms = [ '1=one', 'other' ]; + $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) ); + } + + public static function providePluralTwoForms() { + return [ + [ 'one', 1 ], + [ 'other', 11 ], + [ 'other', 91 ], + [ '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 [ + [ + 'Вікіпедії', + 'Вікіпедія', + 'genitive', + ], + [ + 'Віківидів', + 'Віківиди', + 'genitive', + ], + [ + 'Вікіцитат', + 'Вікіцитати', + 'genitive', + ], + [ + 'Вікіпідручника', + 'Вікіпідручник', + 'genitive', + ], + [ + 'Вікіпедію', + 'Вікіпедія', + 'accusative', + ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageUzTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageUzTest.php new file mode 100644 index 00000000..367226d7 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageUzTest.php @@ -0,0 +1,127 @@ +<?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.. + */ + +/** + * @covers LanguageUz + * @covers UzConverter + */ +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 string $text Text to convert + * @param string $variant Language variant 'uz-cyrl' or 'uz-latn' + * @param string $msg 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 string $text Text to convert + * @param string $variant Language variant 'uz-cyrl' or 'uz-latn' + * @param string $msg 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. + * @param string $text Text to convert + * @param string $msg Optional message + */ + 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. + * @param string $text Text to convert + * @param string $msg Optional message + */ + 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/www/wiki/tests/phpunit/languages/classes/LanguageWaTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageWaTest.php new file mode 100644 index 00000000..80c98603 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageWaTest.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Amir E. Aharoni + * @copyright Copyright © 2012, Amir E. Aharoni + * @file + */ + +/** + * @covers LanguageWa + */ +class LanguageWaTest extends LanguageClassesTestCase { + /** + * @dataProvider providePlural + * @covers Language::convertPlural + */ + public function testPlural( $result, $value ) { + $forms = [ '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 [ + [ 'one', 0 ], + [ 'one', 1 ], + [ 'other', 2 ], + ]; + } +} diff --git a/www/wiki/tests/phpunit/languages/classes/LanguageZhTest.php b/www/wiki/tests/phpunit/languages/classes/LanguageZhTest.php new file mode 100644 index 00000000..2e73ac51 --- /dev/null +++ b/www/wiki/tests/phpunit/languages/classes/LanguageZhTest.php @@ -0,0 +1,126 @@ +<?php + +/** + * @covers LanguageZh + * @covers LanguageZh_hans + * @covers ZhConverter + */ +class LanguageZhTest extends LanguageClassesTestCase { + /** + * @dataProvider provideAutoConvertToAllVariants + * @covers Language::autoConvertToAllVariants + */ + public function testAutoConvertToAllVariants( $result, $value ) { + $this->assertEquals( $result, $this->getLang()->autoConvertToAllVariants( $value ) ); + } + + public static function provideAutoConvertToAllVariants() { + return [ + // Plain hant -> hans + [ + [ + 'zh' => '㑯', + 'zh-hans' => '㑔', + 'zh-hant' => '㑯', + 'zh-cn' => '㑔', + 'zh-hk' => '㑯', + 'zh-mo' => '㑯', + 'zh-my' => '㑔', + 'zh-sg' => '㑔', + 'zh-tw' => '㑯', + ], + '㑯' + ], + // Plain hans -> hant + [ + [ + 'zh' => '㐷', + 'zh-hans' => '㐷', + 'zh-hant' => '傌', + 'zh-cn' => '㐷', + 'zh-hk' => '傌', + 'zh-mo' => '傌', + 'zh-my' => '㐷', + 'zh-sg' => '㐷', + 'zh-tw' => '傌', + ], + '㐷' + ], + // zh-cn specific + [ + [ + 'zh' => '仲介', + 'zh-hans' => '仲介', + 'zh-hant' => '仲介', + 'zh-cn' => '中介', + 'zh-hk' => '仲介', + 'zh-mo' => '仲介', + 'zh-my' => '中介', + 'zh-sg' => '中介', + 'zh-tw' => '仲介', + ], + '仲介' + ], + // zh-hk specific + [ + [ + 'zh' => '中文里', + 'zh-hans' => '中文里', + 'zh-hant' => '中文裡', + 'zh-cn' => '中文里', + 'zh-hk' => '中文裏', + 'zh-mo' => '中文裏', + 'zh-my' => '中文里', + 'zh-sg' => '中文里', + 'zh-tw' => '中文裡', + ], + '中文里' + ], + // zh-tw specific + [ + [ + 'zh' => '甲肝', + 'zh-hans' => '甲肝', + 'zh-hant' => '甲肝', + 'zh-cn' => '甲肝', + 'zh-hk' => '甲肝', + 'zh-mo' => '甲肝', + 'zh-my' => '甲肝', + 'zh-sg' => '甲肝', + 'zh-tw' => 'A肝', + ], + '甲肝' + ], + // zh-tw overrides zh-hant + [ + [ + 'zh' => '账', + 'zh-hans' => '账', + 'zh-hant' => '賬', + 'zh-cn' => '账', + 'zh-hk' => '賬', + 'zh-mo' => '賬', + 'zh-my' => '账', + 'zh-sg' => '账', + 'zh-tw' => '帳', + ], + '账' + ], + // zh-hk overrides zh-hant + [ + [ + 'zh' => '一地里', + 'zh-hans' => '一地里', + 'zh-hant' => '一地裡', + 'zh-cn' => '一地里', + 'zh-hk' => '一地裏', + 'zh-mo' => '一地裏', + 'zh-my' => '一地里', + 'zh-sg' => '一地里', + 'zh-tw' => '一地裡', + ], + '一地里' + ], + ]; + } +} |