3 class ExtensionProcessorTest
extends MediaWikiTestCase
{
7 public function setUp() {
9 $this->dir
= __DIR__
. '/FooBar/extension.json';
13 * 'name' is absolutely required
17 static $default = array(
22 * @covers ExtensionProcessor::extractInfo
24 public function testExtractInfo() {
25 // Test that attributes that begin with @ are ignored
26 $processor = new ExtensionProcessor();
27 $processor->extractInfo( $this->dir
, self
::$default +
array(
28 '@metadata' => array( 'foobarbaz' ),
29 'AnAttribute' => array( 'omg' ),
32 $extracted = $processor->getExtractedInfo();
33 $attributes = $extracted['attributes'];
34 $this->assertArrayHasKey( 'AnAttribute', $attributes );
35 $this->assertArrayNotHasKey( '@metadata', $attributes );
38 public static function provideRegisterHooks() {
41 // Content in extension.json
42 // Expected value of $wgHooks
50 // No current hooks, adding one for "FooBaz"
53 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
54 array( 'FooBaz' => array( 'FooBazCallback' ) ),
56 // Hook for "FooBaz", adding another one
58 array( 'FooBaz' => array( 'PriorCallback' ) ),
59 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
60 array( 'FooBaz' => array( 'PriorCallback', 'FooBazCallback' ) ),
62 // Hook for "BarBaz", adding one for "FooBaz"
64 array( 'BarBaz' => array( 'BarBazCallback' ) ),
65 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
67 'BarBaz' => array( 'BarBazCallback' ),
68 'FooBaz' => array( 'FooBazCallback' ),
71 // Callbacks for FooBaz wrapped in an array
74 array( 'Hooks' => array( 'FooBaz' => array( 'Callback1' ) ) ) + self
::$default,
76 'FooBaz' => array( 'Callback1' ),
79 // Multiple callbacks for FooBaz hook
82 array( 'Hooks' => array( 'FooBaz' => array( 'Callback1', 'Callback2' ) ) ) + self
::$default,
84 'FooBaz' => array( 'Callback1', 'Callback2' ),
91 * @covers ExtensionProcessor::extractHooks
92 * @dataProvider provideRegisterHooks
94 public function testRegisterHooks( $pre, $info, $expected ) {
95 $processor = new MockExtensionProcessor( array( 'wgHooks' => $pre ) );
96 $processor->extractInfo( $this->dir
, $info );
97 $extracted = $processor->getExtractedInfo();
98 $this->assertEquals( $expected, $extracted['globals']['wgHooks'] );
102 * @covers ExtensionProcessor::extractConfig
104 public function testExtractConfig() {
105 $processor = new ExtensionProcessor
;
108 'Bar' => 'somevalue',
113 $processor->extractInfo( $this->dir
, $info );
114 $extracted = $processor->getExtractedInfo();
115 $this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] );
116 $this->assertEquals( 10, $extracted['globals']['wgFoo'] );
117 $this->assertArrayNotHasKey( 'wg@IGNORED', $extracted['globals'] );
120 public static function provideExtracttExtensionMessagesFiles() {
121 $dir = __DIR__
. '/FooBar/';
124 array( 'ExtensionMessagesFiles' => array( 'FooBarAlias' => 'FooBar.alias.php' ) ),
125 array( 'wgExtensionMessagesFiles' => array( 'FooBarAlias' => $dir . 'FooBar.alias.php' ) )
129 'ExtensionMessagesFiles' => array(
130 'FooBarAlias' => 'FooBar.alias.php',
131 'FooBarMagic' => 'FooBar.magic.i18n.php',
135 'wgExtensionMessagesFiles' => array(
136 'FooBarAlias' => $dir . 'FooBar.alias.php',
137 'FooBarMagic' => $dir . 'FooBar.magic.i18n.php',
145 * @covers ExtensionProcessor::extracttExtensionMessagesFiles
146 * @dataProvider provideExtracttExtensionMessagesFiles
148 public function testExtracttExtensionMessagesFiles( $input, $expected ) {
149 $processor = new ExtensionProcessor();
150 $processor->extractInfo( $this->dir
, $input + self
::$default );
151 $out = $processor->getExtractedInfo();
152 foreach ( $expected as $key => $value ) {
153 $this->assertEquals( $value, $out['globals'][$key] );
158 public static function provideExtractMessagesDirs() {
159 $dir = __DIR__
. '/FooBar/';
162 array( 'MessagesDirs' => array( 'VisualEditor' => 'i18n' ) ),
163 array( 'wgMessagesDirs' => array( 'VisualEditor' => array( $dir . 'i18n' ) ) )
166 array( 'MessagesDirs' => array( 'VisualEditor' => array( 'i18n', 'foobar' ) ) ),
167 array( 'wgMessagesDirs' => array( 'VisualEditor' => array( $dir . 'i18n', $dir . 'foobar' ) ) )
173 * @covers ExtensionProcessor::extractMessagesDirs
174 * @dataProvider provideExtractMessagesDirs
176 public function testExtractMessagesDirs( $input, $expected ) {
177 $processor = new ExtensionProcessor();
178 $processor->extractInfo( $this->dir
, $input + self
::$default );
179 $out = $processor->getExtractedInfo();
180 foreach ( $expected as $key => $value ) {
181 $this->assertEquals( $value, $out['globals'][$key] );
186 * @covers ExtensionProcessor::extractResourceLoaderModules
187 * @dataProvider provideExtractResourceLoaderModules
189 public function testExtractResourceLoaderModules( $input, $expected ) {
190 $processor = new ExtensionProcessor();
191 $processor->extractInfo( $this->dir
, $input + self
::$default );
192 $out = $processor->getExtractedInfo();
193 foreach ( $expected as $key => $value ) {
194 $this->assertEquals( $value, $out['globals'][$key] );
198 public static function provideExtractResourceLoaderModules() {
199 $dir = __DIR__
. '/FooBar/';
201 // Generic module with localBasePath/remoteExtPath specified
205 'ResourceModules' => array(
207 'styles' => 'foobar.js',
208 'localBasePath' => '',
209 'remoteExtPath' => 'FooBar',
215 'wgResourceModules' => array(
217 'styles' => 'foobar.js',
218 'localBasePath' => $dir,
219 'remoteExtPath' => 'FooBar',
224 // ResourceFileModulePaths specified:
228 'ResourceFileModulePaths' => array(
229 'localBasePath' => '',
230 'remoteExtPath' => 'FooBar',
232 'ResourceModules' => array(
235 'styles' => 'foo.js',
237 // Different paths set
239 'styles' => 'bar.js',
240 'localBasePath' => 'subdir',
241 'remoteExtPath' => 'FooBar/subdir',
243 // Custom class with no paths set
244 'test.class' => array(
245 'class' => 'FooBarModule',
246 'extra' => 'argument',
248 // Custom class with a localBasePath
249 'test.class.with.path' => array(
250 'class' => 'FooBarPathModule',
251 'extra' => 'argument',
252 'localBasePath' => '',
258 'wgResourceModules' => array(
260 'styles' => 'foo.js',
261 'localBasePath' => $dir,
262 'remoteExtPath' => 'FooBar',
265 'styles' => 'bar.js',
266 'localBasePath' => $dir . 'subdir',
267 'remoteExtPath' => 'FooBar/subdir',
269 'test.class' => array(
270 'class' => 'FooBarModule',
271 'extra' => 'argument',
272 'localBasePath' => $dir,
273 'remoteExtPath' => 'FooBar',
275 'test.class.with.path' => array(
276 'class' => 'FooBarPathModule',
277 'extra' => 'argument',
278 'localBasePath' => $dir,
279 'remoteExtPath' => 'FooBar',
284 // ResourceModuleSkinStyles with file module paths
288 'ResourceFileModulePaths' => array(
289 'localBasePath' => '',
290 'remoteSkinPath' => 'FooBar',
292 'ResourceModuleSkinStyles' => array(
294 'test.foo' => 'foo.css',
300 'wgResourceModuleSkinStyles' => array(
302 'test.foo' => 'foo.css',
303 'localBasePath' => $dir,
304 'remoteSkinPath' => 'FooBar',
309 // ResourceModuleSkinStyles with file module paths and an override
313 'ResourceFileModulePaths' => array(
314 'localBasePath' => '',
315 'remoteSkinPath' => 'FooBar',
317 'ResourceModuleSkinStyles' => array(
319 'test.foo' => 'foo.css',
320 'remoteSkinPath' => 'BarFoo'
326 'wgResourceModuleSkinStyles' => array(
328 'test.foo' => 'foo.css',
329 'localBasePath' => $dir,
330 'remoteSkinPath' => 'BarFoo',
338 public static function provideSetToGlobal() {
341 array( 'wgAPIModules', 'wgAvailableRights' ),
344 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
345 'AvailableRights' => array( 'foobar', 'unfoobar' ),
348 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
349 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
353 array( 'wgAPIModules', 'wgAvailableRights' ),
355 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
356 'wgAvailableRights' => array( 'barbaz' )
359 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
360 'AvailableRights' => array( 'foobar', 'unfoobar' ),
363 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
364 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
368 array( 'wgGroupPermissions' ),
370 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
373 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
376 'wgGroupPermissions' => array( 'sysop' => array( 'delete', 'undelete' ), 'user' => array( 'edit' ) ),
385 * Allow overriding the default value of $this->globals
386 * so we can test merging
388 class MockExtensionProcessor
extends ExtensionProcessor
{
389 public function __construct( $globals = array() ) {
390 $this->globals
= $globals +
$this->globals
;