Merge "Slight improvements to FormSpecialPage behavior."
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageTest.php
index 7647144..54f7753 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
 class LanguageTest extends LanguageClassesTestCase {
-
        function testLanguageConvertDoubleWidthToSingleWidth() {
                $this->assertEquals(
                        "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
@@ -19,7 +18,7 @@ class LanguageTest extends LanguageClassesTestCase {
                $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc );
        }
 
-       function provideFormattableTimes() {
+       public static function provideFormattableTimes() {
                return array(
                        array(
                                9.45,
@@ -202,7 +201,6 @@ class LanguageTest extends LanguageClassesTestCase {
                                'formatTimePeriod() rounding, recursion, (>48h)'
                        ),
                );
-
        }
 
        function testTruncate() {
@@ -251,7 +249,7 @@ class LanguageTest extends LanguageClassesTestCase {
        /**
         * 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" ),
@@ -324,7 +322,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' ),
@@ -375,7 +373,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' ),
@@ -437,7 +435,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideLanguageCodes() {
+       public static function provideLanguageCodes() {
                return array(
                        array( 'fr', 'Two letters, minor case' ),
                        array( 'EN', 'Two letters, upper case' ),
@@ -460,7 +458,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideKnownLanguageTags() {
+       public static function provideKnownLanguageTags() {
                return array(
                        array( 'fr', 'simple code' ),
                        array( 'bat-smg', 'an MW legacy tag' ),
@@ -493,12 +491,36 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideUnknownLanguageTags() {
+       public static function provideUnknownLanguageTags() {
                return array(
                        array( 'mw', 'non-existent two-letter code' ),
                );
        }
 
+       /**
+        * Test too short timestamp
+        * @expectedException MWException
+        */
+       function testSprintfDateTooShortTimestamp() {
+               $this->getLang()->sprintfDate( 'xiY', '1234567890123' );
+       }
+
+       /**
+        * Test too long timestamp
+        * @expectedException MWException
+        */
+       function testSprintfDateTooLongTimestamp() {
+               $this->getLang()->sprintfDate( 'xiY', '123456789012345' );
+       }
+
+       /**
+        * Test too short timestamp
+        * @expectedException MWException
+        */
+       function testSprintfDateNotAllDigitTimestamp() {
+               $this->getLang()->sprintfDate( 'xiY', '-1234567890123' );
+       }
+
        /**
         * @dataProvider provideSprintfDateSamples
         */
@@ -511,10 +533,10 @@ class LanguageTest extends LanguageClassesTestCase {
        }
 
        /**
-        * bug 33454. sprintfDate should always use UTC.
+        * sprintfDate should always use UTC when no zone is given.
         * @dataProvider provideSprintfDateSamples
         */
-       function testSprintfDateTZ( $format, $ts, $expected, $msg ) {
+       function testSprintfDateNoZone( $format, $ts, $expected, $ignore, $msg ) {
                $oldTZ = date_default_timezone_get();
                $res = date_default_timezone_set( 'Asia/Seoul' );
                if ( !$res ) {
@@ -530,42 +552,65 @@ class LanguageTest extends LanguageClassesTestCase {
                date_default_timezone_set( $oldTZ );
        }
 
-       function provideSprintfDateSamples() {
+       /**
+        * sprintfDate should use passed timezone
+        * @dataProvider provideSprintfDateSamples
+        */
+       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 +618,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'
                        ),
 
@@ -836,7 +965,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideFormatSizes() {
+       public static function provideFormatSizes() {
                return array(
                        array(
                                0,
@@ -898,7 +1027,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideFormatBitrate() {
+       public static function provideFormatBitrate() {
                return array(
                        array(
                                0,
@@ -970,7 +1099,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideFormatDuration() {
+       public static function provideFormatDuration() {
                return array(
                        array(
                                0,
@@ -1106,7 +1235,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideCheckTitleEncodingData() {
+       public static function provideCheckTitleEncodingData() {
                return array(
                        array( "" ),
                        array( "United States of America" ), // 7bit ASCII
@@ -1170,7 +1299,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideRomanNumeralsData() {
+       public static function provideRomanNumeralsData() {
                return array(
                        array( 1, 'I' ),
                        array( 2, 'II' ),
@@ -1225,7 +1354,7 @@ class LanguageTest extends LanguageClassesTestCase {
                $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(
@@ -1273,7 +1402,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' ),
@@ -1302,7 +1431,7 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 
-       function provideCommafyData() {
+       public static function provideCommafyData() {
                return array(
                        array( 1, '1' ),
                        array( 10, '10' ),
@@ -1341,7 +1470,7 @@ class LanguageTest extends LanguageClassesTestCase {
                $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' ),