MediaWiki  REL1_19
wfBCP47Test.php
Go to the documentation of this file.
00001 <?php
00005 class wfBCP47 extends MediaWikiTestCase {
00016         function testBCP47( $code, $expected ) {
00017                 $code = strtolower( $code );
00018                 $this->assertEquals( $expected, wfBCP47($code),
00019                         "Applying BCP47 standard to lower case '$code'"
00020                 );
00021 
00022                 $code = strtoupper( $code );
00023                 $this->assertEquals( $expected, wfBCP47($code),
00024                         "Applying BCP47 standard to upper case '$code'"
00025                 );
00026         }
00027 
00031         function provideLanguageCodes() {
00032                 return array(
00033                         // Extracted from BCP47 (list not exhaustive)
00034                         # 2.1.1
00035                         array( 'en-ca-x-ca'    , 'en-CA-x-ca'     ),
00036                         array( 'sgn-be-fr'     , 'sgn-BE-FR'      ),
00037                         array( 'az-latn-x-latn', 'az-Latn-x-latn' ),
00038                         # 2.2
00039                         array( 'sr-Latn-RS', 'sr-Latn-RS' ),
00040                         array( 'az-arab-ir', 'az-Arab-IR' ),
00041 
00042                         # 2.2.5
00043                         array( 'sl-nedis'  , 'sl-nedis'   ),
00044                         array( 'de-ch-1996', 'de-CH-1996' ),
00045 
00046                         # 2.2.6
00047                         array(
00048                                 'en-latn-gb-boont-r-extended-sequence-x-private',
00049                                 'en-Latn-GB-boont-r-extended-sequence-x-private'
00050                         ),
00051 
00052                         // Examples from BCP47 Appendix A
00053                         # Simple language subtag:
00054                         array( 'DE', 'de' ),
00055                         array( 'fR', 'fr' ),
00056                         array( 'ja', 'ja' ),
00057 
00058                         # Language subtag plus script subtag:
00059                         array( 'zh-hans', 'zh-Hans'),
00060                         array( 'sr-cyrl', 'sr-Cyrl'),
00061                         array( 'sr-latn', 'sr-Latn'),
00062 
00063                         # Extended language subtags and their primary language subtag
00064                         # counterparts:
00065                         array( 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ),
00066                         array( 'cmn-hans-cn'   , 'cmn-Hans-CN'    ),
00067                         array( 'zh-yue-hk'     , 'zh-yue-HK'      ),
00068                         array( 'yue-hk'        , 'yue-HK'         ),
00069 
00070                         # Language-Script-Region:
00071                         array( 'zh-hans-cn', 'zh-Hans-CN' ),
00072                         array( 'sr-latn-RS', 'sr-Latn-RS' ),
00073 
00074                         # Language-Variant:
00075                         array( 'sl-rozaj'      , 'sl-rozaj'       ),
00076                         array( 'sl-rozaj-biske', 'sl-rozaj-biske' ),
00077                         array( 'sl-nedis'      , 'sl-nedis'       ),
00078 
00079                         # Language-Region-Variant:
00080                         array( 'de-ch-1901'  , 'de-CH-1901'  ),
00081                         array( 'sl-it-nedis' , 'sl-IT-nedis' ),
00082 
00083                         # Language-Script-Region-Variant:
00084                         array( 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ),
00085 
00086                         # Language-Region:
00087                         array( 'de-de' , 'de-DE' ),
00088                         array( 'en-us' , 'en-US' ),
00089                         array( 'es-419', 'es-419'),
00090 
00091                         # Private use subtags:
00092                         array( 'de-ch-x-phonebk'      , 'de-CH-x-phonebk' ),
00093                         array( 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ),
00102                         # Private use registry values:
00103                         array( 'x-whatever', 'x-whatever' ),
00104                         array( 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ),
00105                         array( 'de-qaaa'   , 'de-Qaaa'    ),
00106                         array( 'sr-latn-qm', 'sr-Latn-QM' ),
00107                         array( 'sr-qaaa-rs', 'sr-Qaaa-RS' ),
00108 
00109                         # Tags that use extensions
00110                         array( 'en-us-u-islamcal', 'en-US-u-islamcal' ),
00111                         array( 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ),
00112                         array( 'en-a-myext-b-another', 'en-a-myext-b-another' ),
00113 
00114                         # Invalid:
00115                         // de-419-DE
00116                         // a-DE
00117                         // ar-a-aaa-b-bbb-a-ccc
00118         
00119                 /*      
00120                         // ISO 15924 :
00121                         array( 'sr-Cyrl', 'sr-Cyrl' ),
00122                         # @todo FIXME: Fix our function?
00123                         array( 'SR-lATN', 'sr-Latn' ),
00124                         array( 'fr-latn', 'fr-Latn' ),
00125                         // Use lowercase for single segment
00126                         // ISO 3166-1-alpha-2 code
00127                         array( 'US', 'us' ),  # USA
00128                         array( 'uS', 'us' ),  # USA
00129                         array( 'Fr', 'fr' ),  # France
00130                         array( 'va', 'va' ),  # Holy See (Vatican City State)
00131                  */);
00132         }
00133 }