MediaWiki  REL1_31
LanguageCodeTest.php
Go to the documentation of this file.
1 <?php
2 
9 class 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() {
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\replaceDeprecatedCodes
static replaceDeprecatedCodes( $code)
Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date,...
Definition: LanguageCode.php:77
LanguageCode\getDeprecatedCodeMapping
static getDeprecatedCodeMapping()
Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up...
Definition: LanguageCode.php:63
LanguageCodeTest
LanguageCode Language.
Definition: LanguageCodeTest.php:9
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
LanguageCodeTest\testReplaceDeprecatedCodes
testReplaceDeprecatedCodes()
Definition: LanguageCodeTest.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
LanguageCodeTest\testGetDeprecatedCodeMapping
testGetDeprecatedCodeMapping()
Definition: LanguageCodeTest.php:19
LanguageCodeTest\provideLanguageCodes
static provideLanguageCodes()
Array format is ($code, $expected)
Definition: LanguageCodeTest.php:71
LanguageCodeTest\testBcp47
testBcp47( $code, $expected)
test
Definition: LanguageCodeTest.php:56
$code
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
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:94
LanguageCodeTest\testConstructor
testConstructor()
Definition: LanguageCodeTest.php:13
LanguageCode
Methods for dealing with language codes.
Definition: LanguageCode.php:29
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56