3 * @group GlobalFunctions
6 class WfBCP47Test
extends MediaWikiTestCase
{
9 * Please note the BCP explicitly state that language codes are case
10 * insensitive, there are some exceptions to the rule :)
11 * This test is used to verify our formatting against all lower and
12 * all upper cases language code.
14 * @see http://tools.ietf.org/html/bcp47
15 * @dataProvider provideLanguageCodes()
17 public function testBCP47( $code, $expected ) {
18 $code = strtolower( $code );
19 $this->assertEquals( $expected, wfBCP47( $code ),
20 "Applying BCP47 standard to lower case '$code'"
23 $code = strtoupper( $code );
24 $this->assertEquals( $expected, wfBCP47( $code ),
25 "Applying BCP47 standard to upper case '$code'"
30 * Array format is ($code, $expected)
32 public static function provideLanguageCodes() {
34 // Extracted from BCP47 (list not exhaustive)
36 array( 'en-ca-x-ca', 'en-CA-x-ca' ),
37 array( 'sgn-be-fr', 'sgn-BE-FR' ),
38 array( 'az-latn-x-latn', 'az-Latn-x-latn' ),
40 array( 'sr-Latn-RS', 'sr-Latn-RS' ),
41 array( 'az-arab-ir', 'az-Arab-IR' ),
44 array( 'sl-nedis', 'sl-nedis' ),
45 array( 'de-ch-1996', 'de-CH-1996' ),
49 'en-latn-gb-boont-r-extended-sequence-x-private',
50 'en-Latn-GB-boont-r-extended-sequence-x-private'
53 // Examples from BCP47 Appendix A
54 # Simple language subtag:
59 # Language subtag plus script subtag:
60 array( 'zh-hans', 'zh-Hans' ),
61 array( 'sr-cyrl', 'sr-Cyrl' ),
62 array( 'sr-latn', 'sr-Latn' ),
64 # Extended language subtags and their primary language subtag
66 array( 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ),
67 array( 'cmn-hans-cn', 'cmn-Hans-CN' ),
68 array( 'zh-yue-hk', 'zh-yue-HK' ),
69 array( 'yue-hk', 'yue-HK' ),
71 # Language-Script-Region:
72 array( 'zh-hans-cn', 'zh-Hans-CN' ),
73 array( 'sr-latn-RS', 'sr-Latn-RS' ),
76 array( 'sl-rozaj', 'sl-rozaj' ),
77 array( 'sl-rozaj-biske', 'sl-rozaj-biske' ),
78 array( 'sl-nedis', 'sl-nedis' ),
80 # Language-Region-Variant:
81 array( 'de-ch-1901', 'de-CH-1901' ),
82 array( 'sl-it-nedis', 'sl-IT-nedis' ),
84 # Language-Script-Region-Variant:
85 array( 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ),
88 array( 'de-de', 'de-DE' ),
89 array( 'en-us', 'en-US' ),
90 array( 'es-419', 'es-419' ),
92 # Private use subtags:
93 array( 'de-ch-x-phonebk', 'de-CH-x-phonebk' ),
94 array( 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ),
96 * Previous test does not reflect the BCP which states:
97 * az-Arab-x-AZE-derbend
98 * AZE being private, it should be lower case, hence the test above
100 * array( 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ),
103 # Private use registry values:
104 array( 'x-whatever', 'x-whatever' ),
105 array( 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ),
106 array( 'de-qaaa', 'de-Qaaa' ),
107 array( 'sr-latn-qm', 'sr-Latn-QM' ),
108 array( 'sr-qaaa-rs', 'sr-Qaaa-RS' ),
110 # Tags that use extensions
111 array( 'en-us-u-islamcal', 'en-US-u-islamcal' ),
112 array( 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ),
113 array( 'en-a-myext-b-another', 'en-a-myext-b-another' ),
118 // ar-a-aaa-b-bbb-a-ccc