3 * @group GlobalFunctions
6 class WfBCP47Test
extends MediaWikiTestCase
{
9 * Please note the BCP 47 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 https://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 BCP 47 (list not exhaustive)
36 [ 'en-ca-x-ca', 'en-CA-x-ca' ],
37 [ 'sgn-be-fr', 'sgn-BE-FR' ],
38 [ 'az-latn-x-latn', 'az-Latn-x-latn' ],
40 [ 'sr-Latn-RS', 'sr-Latn-RS' ],
41 [ 'az-arab-ir', 'az-Arab-IR' ],
44 [ 'sl-nedis', 'sl-nedis' ],
45 [ '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 BCP 47 Appendix A
54 # Simple language subtag:
59 # Language subtag plus script subtag:
60 [ 'zh-hans', 'zh-Hans' ],
61 [ 'sr-cyrl', 'sr-Cyrl' ],
62 [ 'sr-latn', 'sr-Latn' ],
64 # Extended language subtags and their primary language subtag
66 [ 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ],
67 [ 'cmn-hans-cn', 'cmn-Hans-CN' ],
68 [ 'zh-yue-hk', 'zh-yue-HK' ],
69 [ 'yue-hk', 'yue-HK' ],
71 # Language-Script-Region:
72 [ 'zh-hans-cn', 'zh-Hans-CN' ],
73 [ 'sr-latn-RS', 'sr-Latn-RS' ],
76 [ 'sl-rozaj', 'sl-rozaj' ],
77 [ 'sl-rozaj-biske', 'sl-rozaj-biske' ],
78 [ 'sl-nedis', 'sl-nedis' ],
80 # Language-Region-Variant:
81 [ 'de-ch-1901', 'de-CH-1901' ],
82 [ 'sl-it-nedis', 'sl-IT-nedis' ],
84 # Language-Script-Region-Variant:
85 [ 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ],
90 [ 'es-419', 'es-419' ],
92 # Private use subtags:
93 [ 'de-ch-x-phonebk', 'de-CH-x-phonebk' ],
94 [ 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ],
96 * Previous test does not reflect the BCP 47 which states:
97 * az-Arab-x-AZE-derbend
98 * AZE being private, it should be lower case, hence the test above
100 * [ 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ],
103 # Private use registry values:
104 [ 'x-whatever', 'x-whatever' ],
105 [ 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ],
106 [ 'de-qaaa', 'de-Qaaa' ],
107 [ 'sr-latn-qm', 'sr-Latn-QM' ],
108 [ 'sr-qaaa-rs', 'sr-Qaaa-RS' ],
110 # Tags that use extensions
111 [ 'en-us-u-islamcal', 'en-US-u-islamcal' ],
112 [ 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ],
113 [ 'en-a-myext-b-another', 'en-a-myext-b-another' ],
118 // ar-a-aaa-b-bbb-a-ccc