Wrote proper skip reason
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageTest.php
index 5594670..3c9ca23 100644 (file)
@@ -425,30 +425,80 @@ class LanguageTest extends LanguageClassesTestCase {
         */
        function testBuiltInCodeValidation( $code, $message = '' ) {
                $this->assertTrue(
-                       (bool) Language::isValidBuiltInCode( $code ),
+                       (bool)Language::isValidBuiltInCode( $code ),
                        "validating code $code $message"
                );
        }
 
        function testBuiltInCodeValidationRejectUnderscore() {
                $this->assertFalse(
-                       (bool) Language::isValidBuiltInCode( 'be_tarask' ),
+                       (bool)Language::isValidBuiltInCode( 'be_tarask' ),
                        "reject underscore in language code"
                );
        }
 
        function provideLanguageCodes() {
                return array(
-                       array( 'fr'       , 'Two letters, minor case' ),
-                       array( 'EN'       , 'Two letters, upper case' ),
-                       array( 'tyv'      , 'Three letters' ),
-                       array( 'tokipona'   , 'long language code' ),
+                       array( 'fr', 'Two letters, minor case' ),
+                       array( 'EN', 'Two letters, upper case' ),
+                       array( 'tyv', 'Three letters' ),
+                       array( 'tokipona', 'long language code' ),
                        array( 'be-tarask', 'With dash' ),
                        array( 'Zh-classical', 'Begin with upper case, dash' ),
                        array( 'Be-x-old', 'With extension (two dashes)' ),
                );
        }
 
+       /**
+        * Test Language::isKnownLanguageTag()
+        * @dataProvider provideKnownLanguageTags
+        */
+       function testKnownLanguageTag( $code, $message = '' ) {
+               $this->assertTrue(
+                       (bool)Language::isKnownLanguageTag( $code ),
+                       "validating code $code - $message"
+               );
+       }
+
+       function provideKnownLanguageTags() {
+               return array(
+                       array( 'fr', 'simple code' ),
+                       array( 'bat-smg', 'an MW legacy tag' ),
+                       array( 'sgs', 'an internal standard MW name, for which a legacy tag is used externally' ),
+               );
+       }
+
+       /**
+        * Test Language::isKnownLanguageTag()
+        */
+       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
+        */
+       function testUnknownLanguageTag( $code, $message = '' ) {
+               $this->assertFalse(
+                       (bool)Language::isKnownLanguageTag( $code ),
+                       "checking that code $code is invalid - $message"
+               );
+       }
+
+       function provideUnknownLanguageTags() {
+               return array(
+                       array( 'mw', 'non-existent two-letter code' ),
+               );
+       }
+
        /**
         * @dataProvider provideSprintfDateSamples
         */
@@ -459,6 +509,7 @@ class LanguageTest extends LanguageClassesTestCase {
                        "sprintfDate('$format', '$ts'): $msg"
                );
        }
+
        /**
         * bug 33454. sprintfDate should always use UTC.
         * @dataProvider provideSprintfDateSamples
@@ -908,7 +959,6 @@ class LanguageTest extends LanguageClassesTestCase {
        }
 
 
-
        /**
         * @dataProvider provideFormatDuration
         */
@@ -1051,13 +1101,13 @@ class LanguageTest extends LanguageClassesTestCase {
        function testCheckTitleEncoding( $s ) {
                $this->assertEquals(
                        $s,
-                       $this->getLang()->checkTitleEncoding($s),
+                       $this->getLang()->checkTitleEncoding( $s ),
                        "checkTitleEncoding('$s')"
                );
        }
 
        function provideCheckTitleEncodingData() {
-               return array (
+               return array(
                        array( "" ),
                        array( "United States of America" ), // 7bit ASCII
                        array( rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ),
@@ -1162,7 +1212,7 @@ class LanguageTest extends LanguageClassesTestCase {
                        array( 7000, 'MMMMMMM' ),
                        array( 8000, 'MMMMMMMM' ),
                        array( 9000, 'MMMMMMMMM' ),
-                       array( 9999, 'MMMMMMMMMCMXCIX'),
+                       array( 9999, 'MMMMMMMMMCMXCIX' ),
                        array( 10000, 'MMMMMMMMMM' ),
                );
        }
@@ -1261,7 +1311,7 @@ class LanguageTest extends LanguageClassesTestCase {
                $s = $lang->getMessageFromDB( 'word-separator' );
                $c = $lang->getMessageFromDB( 'comma-separator' );
 
-               $this->assertEquals( '', $lang->listToText( array( ) ) );
+               $this->assertEquals( '', $lang->listToText( array() ) );
                $this->assertEquals( 'a', $lang->listToText( array( 'a' ) ) );
                $this->assertEquals( "a{$and}{$s}b", $lang->listToText( array( 'a', 'b' ) ) );
                $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( array( 'a', 'b', 'c' ) ) );
@@ -1284,4 +1334,3 @@ class LanguageTest extends LanguageClassesTestCase {
                );
        }
 }
-