diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /tests/phpunit/languages/LanguageTest.php | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'tests/phpunit/languages/LanguageTest.php')
-rw-r--r-- | tests/phpunit/languages/LanguageTest.php | 311 |
1 files changed, 263 insertions, 48 deletions
diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index 76471445..78929e23 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -1,8 +1,11 @@ <?php class LanguageTest extends LanguageClassesTestCase { - - function testLanguageConvertDoubleWidthToSingleWidth() { + /** + * @covers Language::convertDoubleWidth + * @covers Language::normalizeForSearch + */ + public function testLanguageConvertDoubleWidthToSingleWidth() { $this->assertEquals( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", $this->getLang()->normalizeForSearch( @@ -13,13 +16,14 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * @dataProvider provideFormattableTimes + * @dataProvider provideFormattableTimes# + * @covers Language::formatTimePeriod */ - function testFormatTimePeriod( $seconds, $format, $expected, $desc ) { + public function testFormatTimePeriod( $seconds, $format, $expected, $desc ) { $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc ); } - function provideFormattableTimes() { + public static function provideFormattableTimes() { return array( array( 9.45, @@ -202,10 +206,12 @@ class LanguageTest extends LanguageClassesTestCase { 'formatTimePeriod() rounding, recursion, (>48h)' ), ); - } - function testTruncate() { + /** + * @covers Language::truncate + */ + public function testTruncate() { $this->assertEquals( "XXX", $this->getLang()->truncate( "1234567890", 0, 'XXX' ), @@ -238,9 +244,10 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * @dataProvider provideHTMLTruncateData() + * @dataProvider provideHTMLTruncateData + * @covers Language::truncateHTML */ - function testTruncateHtml( $len, $ellipsis, $input, $expected ) { + public function testTruncateHtml( $len, $ellipsis, $input, $expected ) { // Actual HTML... $this->assertEquals( $expected, @@ -249,9 +256,9 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * Array format is ($len, $ellipsis, $input, $expected) + * @return array format is ($len, $ellipsis, $input, $expected) */ - function provideHTMLTruncateData() { + public static function provideHTMLTruncateData() { return array( array( 0, 'XXX', "1234567890", "XXX" ), array( 8, 'XXX', "1234567890", "12345XXX" ), @@ -310,8 +317,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * Test Language::isWellFormedLanguageTag() * @dataProvider provideWellFormedLanguageTags + * @covers Language::isWellFormedLanguageTag */ - function testWellFormedLanguageTag( $code, $message = '' ) { + public function testWellFormedLanguageTag( $code, $message = '' ) { $this->assertTrue( Language::isWellFormedLanguageTag( $code ), "validating code $code $message" @@ -324,7 +332,7 @@ class LanguageTest extends LanguageClassesTestCase { * and distributed as free software, under the GNU General Public Licence. * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html */ - function provideWellFormedLanguageTags() { + public static function provideWellFormedLanguageTags() { return array( array( 'fr', 'two-letter code' ), array( 'fr-latn', 'two-letter code with lower case script code' ), @@ -361,8 +369,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * Negative test for Language::isWellFormedLanguageTag() * @dataProvider provideMalformedLanguageTags + * @covers Language::isWellFormedLanguageTag */ - function testMalformedLanguageTag( $code, $message = '' ) { + public function testMalformedLanguageTag( $code, $message = '' ) { $this->assertFalse( Language::isWellFormedLanguageTag( $code ), "validating that code $code is a malformed language tag - $message" @@ -375,7 +384,7 @@ class LanguageTest extends LanguageClassesTestCase { * and distributed as free software, under the GNU General Public Licence. * http://www.bortzmeyer.org/gabuzomeu-parsing-language-tags.html */ - function provideMalformedLanguageTags() { + public static function provideMalformedLanguageTags() { return array( array( 'f', 'language too short' ), array( 'f-Latn', 'language too short with script' ), @@ -411,8 +420,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * Negative test for Language::isWellFormedLanguageTag() + * @covers Language::isWellFormedLanguageTag */ - function testLenientLanguageTag() { + public function testLenientLanguageTag() { $this->assertTrue( Language::isWellFormedLanguageTag( 'pa_guru', true ), 'pa_guru is a well-formed language tag in lenient mode' @@ -422,22 +432,26 @@ class LanguageTest extends LanguageClassesTestCase { /** * Test Language::isValidBuiltInCode() * @dataProvider provideLanguageCodes + * @covers Language::isValidBuiltInCode */ - function testBuiltInCodeValidation( $code, $message = '' ) { + public function testBuiltInCodeValidation( $code, $message = '' ) { $this->assertTrue( (bool)Language::isValidBuiltInCode( $code ), "validating code $code $message" ); } - function testBuiltInCodeValidationRejectUnderscore() { + /** + * @covers Language::isValidBuiltInCode + */ + public function testBuiltInCodeValidationRejectUnderscore() { $this->assertFalse( (bool)Language::isValidBuiltInCode( 'be_tarask' ), "reject underscore in language code" ); } - function provideLanguageCodes() { + public static function provideLanguageCodes() { return array( array( 'fr', 'Two letters, minor case' ), array( 'EN', 'Two letters, upper case' ), @@ -452,15 +466,16 @@ class LanguageTest extends LanguageClassesTestCase { /** * Test Language::isKnownLanguageTag() * @dataProvider provideKnownLanguageTags + * @covers Language::isKnownLanguageTag */ - function testKnownLanguageTag( $code, $message = '' ) { + public function testKnownLanguageTag( $code, $message = '' ) { $this->assertTrue( (bool)Language::isKnownLanguageTag( $code ), "validating code $code - $message" ); } - function provideKnownLanguageTags() { + public static function provideKnownLanguageTags() { return array( array( 'fr', 'simple code' ), array( 'bat-smg', 'an MW legacy tag' ), @@ -469,9 +484,9 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * Test Language::isKnownLanguageTag() + * @covers Language::isKnownLanguageTag */ - function testKnownCldrLanguageTag() { + public function testKnownCldrLanguageTag() { if ( !class_exists( 'LanguageNames' ) ) { $this->markTestSkipped( 'The LanguageNames class is not available. The cldr extension is probably not installed.' ); } @@ -485,24 +500,54 @@ class LanguageTest extends LanguageClassesTestCase { /** * Negative tests for Language::isKnownLanguageTag() * @dataProvider provideUnKnownLanguageTags + * @covers Language::isKnownLanguageTag */ - function testUnknownLanguageTag( $code, $message = '' ) { + public function testUnknownLanguageTag( $code, $message = '' ) { $this->assertFalse( (bool)Language::isKnownLanguageTag( $code ), "checking that code $code is invalid - $message" ); } - function provideUnknownLanguageTags() { + public static function provideUnknownLanguageTags() { return array( array( 'mw', 'non-existent two-letter code' ), + array( '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 */ - function testSprintfDate( $format, $ts, $expected, $msg ) { + public function testSprintfDate( $format, $ts, $expected, $msg ) { $this->assertEquals( $expected, $this->getLang()->sprintfDate( $format, $ts ), @@ -511,10 +556,11 @@ class LanguageTest extends LanguageClassesTestCase { } /** - * bug 33454. sprintfDate should always use UTC. + * sprintfDate should always use UTC when no zone is given. * @dataProvider provideSprintfDateSamples + * @covers Language::sprintfDate */ - function testSprintfDateTZ( $format, $ts, $expected, $msg ) { + public function testSprintfDateNoZone( $format, $ts, $expected, $ignore, $msg ) { $oldTZ = date_default_timezone_get(); $res = date_default_timezone_set( 'Asia/Seoul' ); if ( !$res ) { @@ -530,42 +576,66 @@ class LanguageTest extends LanguageClassesTestCase { date_default_timezone_set( $oldTZ ); } - function provideSprintfDateSamples() { + /** + * 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" + ); + } + + public static function provideSprintfDateSamples() { return array( array( 'xiY', '20111212000000', '1390', // note because we're testing English locale we get Latin-standard digits + '1390', 'Iranian calendar full year' ), array( 'xiy', '20111212000000', '90', + '90', 'Iranian calendar short year' ), array( 'o', '20120101235000', '2011', + '2011', 'ISO 8601 (week) year' ), array( 'W', '20120101235000', '52', + '52', 'Week number' ), array( 'W', '20120102235000', '1', + '1', 'Week number' ), array( 'o-\\WW-N', '20091231235000', '2009-W53-4', + '2009-W53-4', 'leap week' ), // What follows is mostly copied from http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time @@ -573,252 +643,336 @@ class LanguageTest extends LanguageClassesTestCase { 'Y', '20120102090705', '2012', + '2012', 'Full year' ), array( 'y', '20120102090705', '12', + '12', '2 digit year' ), array( 'L', '20120102090705', '1', + '1', 'Leap year' ), array( 'n', '20120102090705', '1', + '1', 'Month index, not zero pad' ), array( 'N', '20120102090705', '01', + '01', 'Month index. Zero pad' ), array( 'M', '20120102090705', 'Jan', + 'Jan', 'Month abbrev' ), array( 'F', '20120102090705', 'January', + 'January', 'Full month' ), array( 'xg', '20120102090705', 'January', + 'January', 'Genitive month name (same in EN)' ), array( 'j', '20120102090705', '2', + '2', 'Day of month (not zero pad)' ), array( 'd', '20120102090705', '02', + '02', 'Day of month (zero-pad)' ), array( 'z', '20120102090705', '1', + '1', 'Day of year (zero-indexed)' ), array( 'D', '20120102090705', 'Mon', + 'Mon', 'Day of week (abbrev)' ), array( 'l', '20120102090705', 'Monday', + 'Monday', 'Full day of week' ), array( 'N', '20120101090705', '7', + '7', 'Day of week (Mon=1, Sun=7)' ), array( 'w', '20120101090705', '0', + '0', 'Day of week (Sun=0, Sat=6)' ), array( 'N', '20120102090705', '1', + '1', 'Day of week' ), array( 'a', '20120102090705', 'am', + 'am', 'am vs pm' ), array( 'A', '20120102120000', 'PM', + 'PM', 'AM vs PM' ), array( 'a', '20120102000000', 'am', + 'am', 'AM vs PM' ), array( 'g', '20120102090705', '9', + '9', '12 hour, not Zero' ), array( 'h', '20120102090705', '09', + '09', '12 hour, zero padded' ), array( 'G', '20120102090705', '9', + '9', '24 hour, not zero' ), array( 'H', '20120102090705', '09', + '09', '24 hour, zero' ), array( 'H', '20120102110705', '11', + '11', '24 hour, zero' ), array( 'i', '20120102090705', '07', + '07', 'Minutes' ), array( 's', '20120102090705', '05', + '05', 'seconds' ), array( 'U', '20120102090705', '1325495225', + '1325462825', 'unix time' ), array( 't', '20120102090705', '31', + '31', 'Days in current month' ), array( 'c', '20120102090705', '2012-01-02T09:07:05+00:00', + '2012-01-02T09:07:05+09:00', 'ISO 8601 timestamp' ), array( 'r', '20120102090705', 'Mon, 02 Jan 2012 09:07:05 +0000', + 'Mon, 02 Jan 2012 09:07:05 +0900', 'RFC 5322' ), array( + 'e', + '20120102090705', + 'UTC', + 'Asia/Seoul', + 'Timezone identifier' + ), + array( + 'I', + '19880602090705', + '0', + '1', + 'DST indicator' + ), + array( + 'O', + '20120102090705', + '+0000', + '+0900', + 'Timezone offset' + ), + array( + 'P', + '20120102090705', + '+00:00', + '+09:00', + 'Timezone offset with colon' + ), + array( + 'T', + '20120102090705', + 'UTC', + 'KST', + 'Timezone abbreviation' + ), + array( + 'Z', + '20120102090705', + '0', + '32400', + 'Timezone offset in seconds' + ), + array( 'xmj xmF xmn xmY', '20120102090705', '7 Safar 2 1433', + '7 Safar 2 1433', 'Islamic' ), array( 'xij xiF xin xiY', '20120102090705', '12 Dey 10 1390', + '12 Dey 10 1390', 'Iranian' ), array( 'xjj xjF xjn xjY', '20120102090705', '7 Tevet 4 5772', + '7 Tevet 4 5772', 'Hebrew' ), array( 'xjt', '20120102090705', '29', + '29', 'Hebrew number of days in month' ), array( 'xjx', '20120102090705', 'Tevet', + 'Tevet', 'Hebrew genitive month name (No difference in EN)' ), array( 'xkY', '20120102090705', '2555', + '2555', 'Thai year' ), array( 'xoY', '20120102090705', '101', + '101', 'Minguo' ), array( 'xtY', '20120102090705', '平成24', + '平成24', 'nengo' ), array( 'xrxkYY', '20120102090705', 'MMDLV2012', + 'MMDLV2012', 'Roman numerals' ), array( 'xhxjYY', '20120102090705', 'ה\'תשע"ב2012', + 'ה\'תשע"ב2012', 'Hebrew numberals' ), array( 'xnY', '20120102090705', '2012', + '2012', 'Raw numerals (doesn\'t mean much in EN)' ), array( '[[Y "(yea"\\r)]] \\"xx\\"', '20120102090705', '[[2012 (year)]] "x"', + '[[2012 (year)]] "x"', 'Various escaping' ), @@ -827,8 +981,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideFormatSizes + * @covers Language::formatSize */ - function testFormatSize( $size, $expected, $msg ) { + public function testFormatSize( $size, $expected, $msg ) { $this->assertEquals( $expected, $this->getLang()->formatSize( $size ), @@ -836,7 +991,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideFormatSizes() { + public static function provideFormatSizes() { return array( array( 0, @@ -889,8 +1044,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideFormatBitrate + * @covers Language::formatBitrate */ - function testFormatBitrate( $bps, $expected, $msg ) { + public function testFormatBitrate( $bps, $expected, $msg ) { $this->assertEquals( $expected, $this->getLang()->formatBitrate( $bps ), @@ -898,7 +1054,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideFormatBitrate() { + public static function provideFormatBitrate() { return array( array( 0, @@ -961,8 +1117,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideFormatDuration + * @covers Language::formatDuration */ - function testFormatDuration( $duration, $expected, $intervals = array() ) { + public function testFormatDuration( $duration, $expected, $intervals = array() ) { $this->assertEquals( $expected, $this->getLang()->formatDuration( $duration, $intervals ), @@ -970,7 +1127,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideFormatDuration() { + public static function provideFormatDuration() { return array( array( 0, @@ -1097,8 +1254,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideCheckTitleEncodingData + * @covers Language::checkTitleEncoding */ - function testCheckTitleEncoding( $s ) { + public function testCheckTitleEncoding( $s ) { $this->assertEquals( $s, $this->getLang()->checkTitleEncoding( $s ), @@ -1106,7 +1264,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideCheckTitleEncodingData() { + public static function provideCheckTitleEncodingData() { return array( array( "" ), array( "United States of America" ), // 7bit ASCII @@ -1161,8 +1319,9 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideRomanNumeralsData + * @covers Language::romanNumeral */ - function testRomanNumerals( $num, $numerals ) { + public function testRomanNumerals( $num, $numerals ) { $this->assertEquals( $numerals, Language::romanNumeral( $num ), @@ -1170,7 +1329,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideRomanNumeralsData() { + public static function provideRomanNumeralsData() { return array( array( 1, 'I' ), array( 2, 'II' ), @@ -1219,13 +1378,14 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider providePluralData + * @covers Language::convertPlural */ - function testConvertPlural( $expected, $number, $forms ) { + public function testConvertPlural( $expected, $number, $forms ) { $chosen = $this->getLang()->convertPlural( $number, $forms ); $this->assertEquals( $expected, $chosen ); } - function providePluralData() { + public static function providePluralData() { // Params are: [expected text, number given, [the plural forms]] return array( array( 'plural', 0, array( @@ -1255,6 +1415,9 @@ class LanguageTest extends LanguageClassesTestCase { array( 'other', 2, array( 'kissa=kala', '1=2=3', 'other', ) ), + array( '', 2, array( + '0=explicit zero', '1=explicit one', + ) ), ); } @@ -1262,7 +1425,7 @@ class LanguageTest extends LanguageClassesTestCase { * @covers Language::translateBlockExpiry() * @dataProvider provideTranslateBlockExpiry */ - function testTranslateBlockExpiry( $expectedData, $str, $desc ) { + public function testTranslateBlockExpiry( $expectedData, $str, $desc ) { $lang = $this->getLang(); if ( is_array( $expectedData ) ) { list( $func, $arg ) = $expectedData; @@ -1273,7 +1436,7 @@ class LanguageTest extends LanguageClassesTestCase { $this->assertEquals( $expected, $lang->translateBlockExpiry( $str ), $desc ); } - function provideTranslateBlockExpiry() { + public static function provideTranslateBlockExpiry() { return array( array( '2 hours', '2 hours', 'simple data from ipboptions' ), array( 'indefinite', 'infinite', 'infinite from ipboptions' ), @@ -1294,7 +1457,7 @@ class LanguageTest extends LanguageClassesTestCase { * @covers Language::commafy() * @dataProvider provideCommafyData */ - function testCommafy( $number, $numbersWithCommas ) { + public function testCommafy( $number, $numbersWithCommas ) { $this->assertEquals( $numbersWithCommas, $this->getLang()->commafy( $number ), @@ -1302,7 +1465,7 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function provideCommafyData() { + public static function provideCommafyData() { return array( array( 1, '1' ), array( 10, '10' ), @@ -1321,7 +1484,10 @@ class LanguageTest extends LanguageClassesTestCase { ); } - function testListToText() { + /** + * @covers Language::listToText + */ + public function testListToText() { $lang = $this->getLang(); $and = $lang->getMessageFromDB( 'and' ); $s = $lang->getMessageFromDB( 'word-separator' ); @@ -1336,12 +1502,13 @@ class LanguageTest extends LanguageClassesTestCase { /** * @dataProvider provideIsSupportedLanguage + * @covers Language::isSupportedLanguage */ - function testIsSupportedLanguage( $code, $expected, $comment ) { + public function testIsSupportedLanguage( $code, $expected, $comment ) { $this->assertEquals( $expected, Language::isSupportedLanguage( $code ), $comment ); } - static function provideIsSupportedLanguage() { + public static function provideIsSupportedLanguage() { return array( array( 'en', true, 'is supported language' ), array( 'fi', true, 'is supported language' ), @@ -1349,4 +1516,52 @@ class LanguageTest extends LanguageClassesTestCase { array( '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 array( + array( 'zh-cn', 'zh', 'zh is the parent language of zh-cn' ), + array( 'zh', 'zh', 'zh is defined as the parent language of zh, because zh converter can convert zh-cn to zh' ), + array( 'zh-invalid', null, 'do not be fooled by arbitrarily composed language codes' ), + array( 'en-gb', null, 'en does not have converter' ), + array( 'en', null, 'en does not have converter. Although FakeConverter handles en -> en conversion but it is useless' ), + ); + } + + /** + * @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 array( + array( + 'zh', + array( + '文件' => NS_FILE, + '檔案' => NS_FILE, + ), + ), + ); + } } |