1 | <?php |
||
17 | class LocalizerTest extends \PHPUnit_Framework_TestCase { |
||
18 | |||
19 | public function testCanConstruct() { |
||
20 | |||
21 | $language = $this->getMockBuilder( '\Language' ) |
||
22 | ->disableOriginalConstructor() |
||
23 | ->getMock(); |
||
24 | |||
25 | $this->assertInstanceOf( |
||
26 | '\SMW\Localizer', |
||
27 | new Localizer( $language ) |
||
28 | ); |
||
29 | |||
30 | $this->assertInstanceOf( |
||
31 | '\SMW\Localizer', |
||
32 | Localizer::getInstance() |
||
33 | ); |
||
34 | } |
||
35 | |||
36 | public function testGetContentLanguage() { |
||
|
|||
37 | |||
38 | $language = $this->getMockBuilder( '\Language' ) |
||
39 | ->disableOriginalConstructor() |
||
40 | ->getMock(); |
||
41 | |||
42 | $instance = new Localizer( $language ); |
||
43 | |||
44 | $this->assertSame( |
||
45 | $language, |
||
46 | $instance->getContentLanguage() |
||
47 | ); |
||
48 | |||
49 | $this->assertSame( |
||
50 | $GLOBALS['wgContLang'], |
||
51 | Localizer::getInstance()->getContentLanguage() |
||
52 | ); |
||
53 | |||
54 | Localizer::clear(); |
||
55 | } |
||
56 | |||
57 | public function testNamespaceTextById() { |
||
58 | |||
59 | $instance = new Localizer( Language::factory( 'en') ); |
||
60 | |||
61 | $this->assertEquals( |
||
62 | 'Property', |
||
63 | $instance->getNamespaceTextById( SMW_NS_PROPERTY ) |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | public function testNamespaceIndexByName() { |
||
68 | |||
69 | $instance = new Localizer( Language::factory( 'en') ); |
||
70 | |||
71 | $this->assertEquals( |
||
72 | SMW_NS_PROPERTY, |
||
73 | $instance->getNamespaceIndexByName( 'property' ) |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | public function testSupportedLanguageForLowerCaseLetter() { |
||
78 | |||
79 | if ( version_compare( $GLOBALS['wgVersion'], '1.20', '<' ) ) { |
||
80 | $this->markTestSkipped( 'Skipping because `Language::isSupportedLanguage` is not supported on 1.19' ); |
||
81 | } |
||
82 | |||
83 | $this->assertTrue( |
||
84 | Localizer::isSupportedLanguage( 'en' ) |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | public function testSupportedLanguageForUpperCaseLetter() { |
||
89 | |||
90 | if ( version_compare( $GLOBALS['wgVersion'], '1.20', '<' ) ) { |
||
91 | $this->markTestSkipped( 'Skipping because `Language::isSupportedLanguage` is not supported on 1.19' ); |
||
92 | } |
||
93 | |||
94 | $this->assertTrue( |
||
95 | Localizer::isSupportedLanguage( 'ZH-HANS' ) |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | public function testAsBCP47FormattedLanguageCode() { |
||
100 | $this->assertEquals( |
||
101 | 'zh-Hans', |
||
102 | Localizer::asBCP47FormattedLanguageCode( 'zh-hans' ) |
||
103 | ); |
||
104 | } |
||
105 | |||
106 | public function testCanGetLanguageCodeOnValidMarkedValue() { |
||
120 | |||
121 | public function testCanGetLanguageCodeOnDoubledMarker() { |
||
135 | |||
136 | public function testCanNotGetLanguageCodeOnNonMarkedValue() { |
||
149 | |||
150 | public function testCanNotGetLanguageCodeOnMissingLanguageCode() { |
||
163 | |||
164 | public function testExtraneousLanguage() { |
||
165 | |||
166 | $this->assertInstanceOf( |
||
167 | '\SMW\ExtraneousLanguage', |
||
168 | Localizer::getInstance()->getExtraneousLanguage() |
||
169 | ); |
||
170 | |||
178 | |||
179 | } |
||
180 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: