MediaWiki REL1_31
LanguageCodeTest.php
Go to the documentation of this file.
1<?php
2
9class LanguageCodeTest extends PHPUnit\Framework\TestCase {
10
11 use MediaWikiCoversValidator;
12
13 public function testConstructor() {
14 $instance = new LanguageCode();
15
16 $this->assertInstanceOf( LanguageCode::class, $instance );
17 }
18
19 public function testGetDeprecatedCodeMapping() {
20 $map = LanguageCode::getDeprecatedCodeMapping();
21
22 $this->assertInternalType( 'array', $map );
23 $this->assertContainsOnly( 'string', array_keys( $map ) );
24 $this->assertArrayNotHasKey( '', $map );
25 $this->assertContainsOnly( 'string', $map );
26 $this->assertNotContains( '', $map );
27
28 // Codes special to MediaWiki should never appear in a map of "deprecated" codes
29 $this->assertArrayNotHasKey( 'qqq', $map, 'documentation' );
30 $this->assertNotContains( 'qqq', $map, 'documentation' );
31 $this->assertArrayNotHasKey( 'qqx', $map, 'debug code' );
32 $this->assertNotContains( 'qqx', $map, 'debug code' );
33
34 // Valid language codes that are currently not "deprecated"
35 $this->assertArrayNotHasKey( 'bh', $map, 'family of Bihari languages' );
36 $this->assertArrayNotHasKey( 'no', $map, 'family of Norwegian languages' );
37 $this->assertArrayNotHasKey( 'simple', $map );
38 }
39
40 public function testReplaceDeprecatedCodes() {
41 $this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'als' ) );
42 $this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'gsw' ) );
43 $this->assertEquals( null, LanguageCode::replaceDeprecatedCodes( null ) );
44 }
45
56 public function testBcp47( $code, $expected ) {
57 $code = strtolower( $code );
58 $this->assertEquals( $expected, LanguageCode::bcp47( $code ),
59 "Applying BCP47 standard to lower case '$code'"
60 );
61
62 $code = strtoupper( $code );
63 $this->assertEquals( $expected, LanguageCode::bcp47( $code ),
64 "Applying BCP47 standard to upper case '$code'"
65 );
66 }
67
71 public static function provideLanguageCodes() {
72 return [
73 // Extracted from BCP 47 (list not exhaustive)
74 # 2.1.1
75 [ 'en-ca-x-ca', 'en-CA-x-ca' ],
76 [ 'sgn-be-fr', 'sgn-BE-FR' ],
77 [ 'az-latn-x-latn', 'az-Latn-x-latn' ],
78 # 2.2
79 [ 'sr-Latn-RS', 'sr-Latn-RS' ],
80 [ 'az-arab-ir', 'az-Arab-IR' ],
81
82 # 2.2.5
83 [ 'sl-nedis', 'sl-nedis' ],
84 [ 'de-ch-1996', 'de-CH-1996' ],
85
86 # 2.2.6
87 [
88 'en-latn-gb-boont-r-extended-sequence-x-private',
89 'en-Latn-GB-boont-r-extended-sequence-x-private'
90 ],
91
92 // Examples from BCP 47 Appendix A
93 # Simple language subtag:
94 [ 'DE', 'de' ],
95 [ 'fR', 'fr' ],
96 [ 'ja', 'ja' ],
97
98 # Language subtag plus script subtag:
99 [ 'zh-hans', 'zh-Hans' ],
100 [ 'sr-cyrl', 'sr-Cyrl' ],
101 [ 'sr-latn', 'sr-Latn' ],
102
103 # Extended language subtags and their primary language subtag
104 # counterparts:
105 [ 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ],
106 [ 'cmn-hans-cn', 'cmn-Hans-CN' ],
107 [ 'zh-yue-hk', 'zh-yue-HK' ],
108 [ 'yue-hk', 'yue-HK' ],
109
110 # Language-Script-Region:
111 [ 'zh-hans-cn', 'zh-Hans-CN' ],
112 [ 'sr-latn-RS', 'sr-Latn-RS' ],
113
114 # Language-Variant:
115 [ 'sl-rozaj', 'sl-rozaj' ],
116 [ 'sl-rozaj-biske', 'sl-rozaj-biske' ],
117 [ 'sl-nedis', 'sl-nedis' ],
118
119 # Language-Region-Variant:
120 [ 'de-ch-1901', 'de-CH-1901' ],
121 [ 'sl-it-nedis', 'sl-IT-nedis' ],
122
123 # Language-Script-Region-Variant:
124 [ 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ],
125
126 # Language-Region:
127 [ 'de-de', 'de-DE' ],
128 [ 'en-us', 'en-US' ],
129 [ 'es-419', 'es-419' ],
130
131 # Private use subtags:
132 [ 'de-ch-x-phonebk', 'de-CH-x-phonebk' ],
133 [ 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ],
142 # Private use registry values:
143 [ 'x-whatever', 'x-whatever' ],
144 [ 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ],
145 [ 'de-qaaa', 'de-Qaaa' ],
146 [ 'sr-latn-qm', 'sr-Latn-QM' ],
147 [ 'sr-qaaa-rs', 'sr-Qaaa-RS' ],
148
149 # Tags that use extensions
150 [ 'en-us-u-islamcal', 'en-US-u-islamcal' ],
151 [ 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ],
152 [ 'en-a-myext-b-another', 'en-a-myext-b-another' ],
153
154 # Invalid:
155 // de-419-DE
156 // a-DE
157 // ar-a-aaa-b-bbb-a-ccc
158 ];
159 }
160
161}
LanguageCode Language.
testBcp47( $code, $expected)
test
static provideLanguageCodes()
Array format is ($code, $expected)
Methods for dealing with language codes.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:865