Merge "OutputPageTest: Don't assume Vector is the default skin"
[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 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 array(
34 // Extracted from BCP47 (list not exhaustive)
35 # 2.1.1
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' ),
39 # 2.2
40 array( 'sr-Latn-RS', 'sr-Latn-RS' ),
41 array( 'az-arab-ir', 'az-Arab-IR' ),
42
43 # 2.2.5
44 array( 'sl-nedis', 'sl-nedis' ),
45 array( 'de-ch-1996', 'de-CH-1996' ),
46
47 # 2.2.6
48 array(
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 BCP47 Appendix A
54 # Simple language subtag:
55 array( 'DE', 'de' ),
56 array( 'fR', 'fr' ),
57 array( 'ja', 'ja' ),
58
59 # Language subtag plus script subtag:
60 array( 'zh-hans', 'zh-Hans' ),
61 array( 'sr-cyrl', 'sr-Cyrl' ),
62 array( 'sr-latn', 'sr-Latn' ),
63
64 # Extended language subtags and their primary language subtag
65 # counterparts:
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' ),
70
71 # Language-Script-Region:
72 array( 'zh-hans-cn', 'zh-Hans-CN' ),
73 array( 'sr-latn-RS', 'sr-Latn-RS' ),
74
75 # Language-Variant:
76 array( 'sl-rozaj', 'sl-rozaj' ),
77 array( 'sl-rozaj-biske', 'sl-rozaj-biske' ),
78 array( 'sl-nedis', 'sl-nedis' ),
79
80 # Language-Region-Variant:
81 array( 'de-ch-1901', 'de-CH-1901' ),
82 array( 'sl-it-nedis', 'sl-IT-nedis' ),
83
84 # Language-Script-Region-Variant:
85 array( 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ),
86
87 # Language-Region:
88 array( 'de-de', 'de-DE' ),
89 array( 'en-us', 'en-US' ),
90 array( 'es-419', 'es-419' ),
91
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' ),
95 /**
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
99 * should probably be:
100 * array( 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ),
101 */
102
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' ),
109
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' ),
114
115 # Invalid:
116 // de-419-DE
117 // a-DE
118 // ar-a-aaa-b-bbb-a-ccc
119 );
120 }
121 }