Update comments about language codes
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfBCP47Test.php
1 <?php
2 /**
3 * @group GlobalFunctions
4 * @covers ::wfBCP47
5 */
6 class WfBCP47Test extends MediaWikiTestCase {
7 /**
8 * test @see wfBCP47().
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.
13 *
14 * @see http://tools.ietf.org/html/bcp47
15 * @dataProvider provideLanguageCodes()
16 */
17 public function testBCP47( $code, $expected ) {
18 $code = strtolower( $code );
19 $this->assertEquals( $expected, wfBCP47( $code ),
20 "Applying BCP47 standard to lower case '$code'"
21 );
22
23 $code = strtoupper( $code );
24 $this->assertEquals( $expected, wfBCP47( $code ),
25 "Applying BCP47 standard to upper case '$code'"
26 );
27 }
28
29 /**
30 * Array format is ($code, $expected)
31 */
32 public static function provideLanguageCodes() {
33 return [
34 // Extracted from BCP 47 (list not exhaustive)
35 # 2.1.1
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' ],
39 # 2.2
40 [ 'sr-Latn-RS', 'sr-Latn-RS' ],
41 [ 'az-arab-ir', 'az-Arab-IR' ],
42
43 # 2.2.5
44 [ 'sl-nedis', 'sl-nedis' ],
45 [ 'de-ch-1996', 'de-CH-1996' ],
46
47 # 2.2.6
48 [
49 'en-latn-gb-boont-r-extended-sequence-x-private',
50 'en-Latn-GB-boont-r-extended-sequence-x-private'
51 ],
52
53 // Examples from BCP 47 Appendix A
54 # Simple language subtag:
55 [ 'DE', 'de' ],
56 [ 'fR', 'fr' ],
57 [ 'ja', 'ja' ],
58
59 # Language subtag plus script subtag:
60 [ 'zh-hans', 'zh-Hans' ],
61 [ 'sr-cyrl', 'sr-Cyrl' ],
62 [ 'sr-latn', 'sr-Latn' ],
63
64 # Extended language subtags and their primary language subtag
65 # counterparts:
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' ],
70
71 # Language-Script-Region:
72 [ 'zh-hans-cn', 'zh-Hans-CN' ],
73 [ 'sr-latn-RS', 'sr-Latn-RS' ],
74
75 # Language-Variant:
76 [ 'sl-rozaj', 'sl-rozaj' ],
77 [ 'sl-rozaj-biske', 'sl-rozaj-biske' ],
78 [ 'sl-nedis', 'sl-nedis' ],
79
80 # Language-Region-Variant:
81 [ 'de-ch-1901', 'de-CH-1901' ],
82 [ 'sl-it-nedis', 'sl-IT-nedis' ],
83
84 # Language-Script-Region-Variant:
85 [ 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ],
86
87 # Language-Region:
88 [ 'de-de', 'de-DE' ],
89 [ 'en-us', 'en-US' ],
90 [ 'es-419', 'es-419' ],
91
92 # Private use subtags:
93 [ 'de-ch-x-phonebk', 'de-CH-x-phonebk' ],
94 [ 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ],
95 /**
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
99 * should probably be:
100 * array( 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ),
101 */
102
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' ],
109
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' ],
114
115 # Invalid:
116 // de-419-DE
117 // a-DE
118 // ar-a-aaa-b-bbb-a-ccc
119 ];
120 }
121 }