Merge "Consistency tweaks: xml -> XML, Href -> href"
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / ExtensionRegistryTest.php
1 <?php
2
3 class ExtensionRegistryTest extends MediaWikiTestCase {
4
5 /**
6 * @covers ExtensionRegistry::exportExtractedData
7 * @dataProvider provideExportExtractedDataGlobals
8 */
9 public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {
10 // Set globals for test
11 if ( $before ) {
12 foreach ( $before as $key => $value ) {
13 // mw prefixed globals does not exist normally
14 if ( substr( $key, 0, 2 ) == 'mw' ) {
15 $GLOBALS[$key] = $value;
16 } else {
17 $this->setMwGlobals( $key, $value );
18 }
19 }
20 }
21
22 $info = array(
23 'globals' => $globals,
24 'callbacks' => array(),
25 'defines' => array(),
26 'credits' => array(),
27 'attributes' => array(),
28 );
29 $registry = new ExtensionRegistry();
30 $class = new ReflectionClass( 'ExtensionRegistry' );
31 $method = $class->getMethod( 'exportExtractedData' );
32 $method->setAccessible( true );
33 $method->invokeArgs( $registry, array( $info ) );
34 foreach ( $expected as $name => $value ) {
35 $this->assertArrayHasKey( $name, $GLOBALS, $desc );
36 $this->assertEquals( $value, $GLOBALS[$name], $desc );
37 }
38
39 // Remove mw prefixed globals
40 if ( $before ) {
41 foreach ( $before as $key => $value ) {
42 if ( substr( $key, 0, 2 ) == 'mw' ) {
43 unset( $GLOBALS[$key] );
44 }
45 }
46 }
47 }
48
49 public static function provideExportExtractedDataGlobals() {
50 // "mwtest" prefix used instead of "$wg" to avoid potential conflicts
51 return array(
52 array(
53 'Simple non-array values',
54 array(
55 'mwtestFooBarConfig' => true,
56 'mwtestFooBarConfig2' => 'string',
57 ),
58 array(
59 'mwtestFooBarDefault' => 1234,
60 'mwtestFooBarConfig' => false,
61 ),
62 array(
63 'mwtestFooBarConfig' => true,
64 'mwtestFooBarConfig2' => 'string',
65 'mwtestFooBarDefault' => 1234,
66 ),
67 ),
68 array(
69 'No global already set, simple array',
70 null,
71 array(
72 'mwtestDefaultOptions' => array(
73 'foobar' => true,
74 )
75 ),
76 array(
77 'mwtestDefaultOptions' => array(
78 'foobar' => true,
79 )
80 ),
81 ),
82 array(
83 'Global already set, simple array',
84 array(
85 'mwtestDefaultOptions' => array(
86 'foobar' => true,
87 'foo' => 'string'
88 ),
89 ),
90 array(
91 'mwtestDefaultOptions' => array(
92 'barbaz' => 12345,
93 'foobar' => false,
94 ),
95 ),
96 array(
97 'mwtestDefaultOptions' => array(
98 'barbaz' => 12345,
99 'foo' => 'string',
100 'foobar' => true,
101 ),
102 )
103 ),
104 array(
105 'No global already set, $wgHooks',
106 array(
107 'wgHooks' => array(),
108 ),
109 array(
110 'wgHooks' => array(
111 'FooBarEvent' => array(
112 'FooBarClass::onFooBarEvent'
113 ),
114 ),
115 ),
116 array(
117 'wgHooks' => array(
118 'FooBarEvent' => array(
119 'FooBarClass::onFooBarEvent'
120 ),
121 ),
122 ),
123 ),
124 array(
125 'Global already set, $wgHooks',
126 array(
127 'wgHooks' => array(
128 'FooBarEvent' => array(
129 'FooBarClass::onFooBarEvent'
130 ),
131 'BazBarEvent' => array(
132 'FooBarClass::onBazBarEvent',
133 ),
134 ),
135 ),
136 array(
137 'wgHooks' => array(
138 'FooBarEvent' => array(
139 'BazBarClass::onFooBarEvent',
140 ),
141 ),
142 ),
143 array(
144 'wgHooks' => array(
145 'FooBarEvent' => array(
146 'FooBarClass::onFooBarEvent',
147 'BazBarClass::onFooBarEvent',
148 ),
149 'BazBarEvent' => array(
150 'FooBarClass::onBazBarEvent',
151 ),
152 ),
153 ),
154 ),
155 array(
156 'Global already set, $wgGroupPermissions',
157 array(
158 'wgGroupPermissions' => array(
159 'sysop' => array(
160 'something' => true,
161 ),
162 'user' => array(
163 'somethingtwo' => true,
164 )
165 ),
166 ),
167 array(
168 'wgGroupPermissions' => array(
169 'customgroup' => array(
170 'right' => true,
171 ),
172 'user' => array(
173 'right' => true,
174 'somethingtwo' => false,
175 'nonduplicated' => true,
176 )
177 ),
178 ),
179 array(
180 'wgGroupPermissions' => array(
181 'customgroup' => array(
182 'right' => true,
183 ),
184 'sysop' => array(
185 'something' => true,
186 ),
187 'user' => array(
188 'somethingtwo' => true,
189 'right' => true,
190 'nonduplicated' => true,
191 )
192 ),
193 ),
194 ),
195 array(
196 'False local setting should not be overridden (T100767)',
197 array(
198 'mwtestT100767' => false,
199 ),
200 array(
201 'mwtestT100767' => true,
202 ),
203 array(
204 'mwtestT100767' => false,
205 ),
206 ),
207 );
208 }
209 }