3 use Wikimedia\TestingAccessWrapper;
11 $this->dir = __DIR__ .
'/FooBar/extension.json';
12 $this->dirname = dirname( $this->dir );
30 $processor->extractInfo( $this->dir, self::$default + [
31 '@metadata' => [
'foobarbaz' ],
32 'AnAttribute' => [
'omg' ],
33 'AutoloadClasses' => [
'FooBar' =>
'includes/FooBar.php' ],
36 $extracted = $processor->getExtractedInfo();
37 $attributes = $extracted[
'attributes'];
38 $this->assertArrayHasKey(
'AnAttribute', $attributes );
39 $this->assertArrayNotHasKey(
'@metadata', $attributes );
40 $this->assertArrayNotHasKey(
'AutoloadClasses', $attributes );
48 if ( !defined(
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X' ) ) {
49 define(
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X', 123456 );
53 $processor->extractInfo( $this->dir, self::$default + [
57 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
59 'content' =>
'TestModel'
63 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
65 'content' =>
'TestModel'
70 $extracted = $processor->getExtractedInfo();
72 $this->assertArrayHasKey(
73 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
76 $this->assertArrayNotHasKey(
77 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
82 $extracted[
'defines'][
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A'],
86 $this->assertArrayHasKey(
'ExtensionNamespaces', $extracted[
'attributes'] );
87 $this->assertArrayHasKey( 123456, $extracted[
'attributes'][
'ExtensionNamespaces'] );
88 $this->assertArrayHasKey( 332200, $extracted[
'attributes'][
'ExtensionNamespaces'] );
89 $this->assertArrayNotHasKey( 334400, $extracted[
'attributes'][
'ExtensionNamespaces'] );
91 $this->assertSame(
'Test_X', $extracted[
'attributes'][
'ExtensionNamespaces'][123456] );
92 $this->assertSame(
'Test_A', $extracted[
'attributes'][
'ExtensionNamespaces'][332200] );
112 [
'FooBaz' => [
'FooBazCallback' ] ] + $merge,
116 [
'FooBaz' => [
'PriorCallback' ] ],
118 [
'FooBaz' => [
'PriorCallback',
'FooBazCallback' ] ] + $merge,
123 [
'Hooks' => [
'FooBaz' => [
'FooBazCallback' ] ] ] +
self::$default,
124 [
'FooBaz' => [
'FooBazCallback' ] ] + $merge,
128 [
'BarBaz' => [
'BarBazCallback' ] ],
131 'BarBaz' => [
'BarBazCallback' ],
132 'FooBaz' => [
'FooBazCallback' ],
140 'FooBaz' => [
'Callback1' ],
146 [
'Hooks' => [
'FooBaz' => [
'Callback1',
'Callback2' ] ] ] +
self::$default,
148 'FooBaz' => [
'Callback1',
'Callback2' ],
160 $processor->extractInfo( $this->dir, $info, 1 );
161 $extracted = $processor->getExtractedInfo();
162 $this->assertEquals( $expected, $extracted[
'globals'][
'wgHooks'] );
172 'Bar' =>
'somevalue',
184 $processor->extractInfo( $this->dir, $info, 1 );
185 $processor->extractInfo( $this->dir, $info2, 1 );
186 $extracted = $processor->getExtractedInfo();
187 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'wgBar'] );
188 $this->assertEquals( 10, $extracted[
'globals'][
'wgFoo'] );
189 $this->assertArrayNotHasKey(
'wg@IGNORED', $extracted[
'globals'] );
191 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'egBar'] );
201 'Bar' => [
'value' =>
'somevalue' ],
202 'Foo' => [
'value' => 10 ],
203 'Path' => [
'value' =>
'foo.txt',
'path' =>
true ],
208 'Bar' => [
'value' =>
'somevalue' ],
210 'config_prefix' =>
'eg',
213 $processor->extractInfo( $this->dir, $info, 2 );
214 $processor->extractInfo( $this->dir, $info2, 2 );
215 $extracted = $processor->getExtractedInfo();
216 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'wgBar'] );
217 $this->assertEquals( 10, $extracted[
'globals'][
'wgFoo'] );
218 $this->assertEquals(
"{$this->dirname}/foo.txt", $extracted[
'globals'][
'wgPath'] );
220 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'egBar'] );
224 $dir = __DIR__ .
'/FooBar/';
227 [
'ExtensionMessagesFiles' => [
'FooBarAlias' =>
'FooBar.alias.php' ] ],
228 [
'wgExtensionMessagesFiles' => [
'FooBarAlias' =>
$dir .
'FooBar.alias.php' ] ]
232 'ExtensionMessagesFiles' => [
233 'FooBarAlias' =>
'FooBar.alias.php',
234 'FooBarMagic' =>
'FooBar.magic.i18n.php',
238 'wgExtensionMessagesFiles' => [
239 'FooBarAlias' =>
$dir .
'FooBar.alias.php',
240 'FooBarMagic' =>
$dir .
'FooBar.magic.i18n.php',
253 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
254 $out = $processor->getExtractedInfo();
255 foreach ( $expected
as $key =>
$value ) {
256 $this->assertEquals(
$value,
$out[
'globals'][$key] );
261 $dir = __DIR__ .
'/FooBar/';
264 [
'MessagesDirs' => [
'VisualEditor' =>
'i18n' ] ],
265 [
'wgMessagesDirs' => [
'VisualEditor' => [
$dir .
'i18n' ] ] ]
268 [
'MessagesDirs' => [
'VisualEditor' => [
'i18n',
'foobar' ] ] ],
269 [
'wgMessagesDirs' => [
'VisualEditor' => [
$dir .
'i18n',
$dir .
'foobar' ] ] ]
280 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
281 $out = $processor->getExtractedInfo();
282 foreach ( $expected
as $key =>
$value ) {
283 $this->assertEquals(
$value,
$out[
'globals'][$key] );
292 $processor->extractInfo( $this->dir, self::$default, 1 );
293 $this->setExpectedException(
'Exception' );
294 $processor->extractInfo( $this->dir, self::$default, 1 );
303 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
304 $out = $processor->getExtractedInfo();
305 foreach ( $expected
as $key =>
$value ) {
306 $this->assertEquals(
$value,
$out[
'globals'][$key] );
311 $dir = __DIR__ .
'/FooBar';
317 'ResourceModules' => [
319 'styles' =>
'foobar.js',
320 'localBasePath' =>
'',
321 'remoteExtPath' =>
'FooBar',
327 'wgResourceModules' => [
329 'styles' =>
'foobar.js',
330 'localBasePath' =>
$dir,
331 'remoteExtPath' =>
'FooBar',
340 'ResourceFileModulePaths' => [
341 'localBasePath' =>
'',
342 'remoteExtPath' =>
'FooBar',
344 'ResourceModules' => [
347 'styles' =>
'foo.js',
351 'styles' =>
'bar.js',
352 'localBasePath' =>
'subdir',
353 'remoteExtPath' =>
'FooBar/subdir',
357 'class' =>
'FooBarModule',
358 'extra' =>
'argument',
361 'test.class.with.path' => [
362 'class' =>
'FooBarPathModule',
363 'extra' =>
'argument',
364 'localBasePath' =>
'',
370 'wgResourceModules' => [
372 'styles' =>
'foo.js',
373 'localBasePath' =>
$dir,
374 'remoteExtPath' =>
'FooBar',
377 'styles' =>
'bar.js',
378 'localBasePath' =>
"$dir/subdir",
379 'remoteExtPath' =>
'FooBar/subdir',
382 'class' =>
'FooBarModule',
383 'extra' =>
'argument',
384 'localBasePath' =>
$dir,
385 'remoteExtPath' =>
'FooBar',
387 'test.class.with.path' => [
388 'class' =>
'FooBarPathModule',
389 'extra' =>
'argument',
390 'localBasePath' =>
$dir,
391 'remoteExtPath' =>
'FooBar',
400 'ResourceFileModulePaths' => [
401 'localBasePath' =>
'',
402 'remoteSkinPath' =>
'FooBar',
404 'ResourceModuleSkinStyles' => [
406 'test.foo' =>
'foo.css',
412 'wgResourceModuleSkinStyles' => [
414 'test.foo' =>
'foo.css',
415 'localBasePath' =>
$dir,
416 'remoteSkinPath' =>
'FooBar',
425 'ResourceFileModulePaths' => [
426 'localBasePath' =>
'',
427 'remoteSkinPath' =>
'FooBar',
429 'ResourceModuleSkinStyles' => [
431 'test.foo' =>
'foo.css',
432 'remoteSkinPath' =>
'BarFoo'
438 'wgResourceModuleSkinStyles' => [
440 'test.foo' =>
'foo.css',
441 'localBasePath' =>
$dir,
442 'remoteSkinPath' =>
'BarFoo',
453 [
'wgAPIModules',
'wgAvailableRights' ],
456 'APIModules' => [
'foobar' =>
'ApiFooBar' ],
457 'AvailableRights' => [
'foobar',
'unfoobar' ],
460 'wgAPIModules' => [
'foobar' =>
'ApiFooBar' ],
461 'wgAvailableRights' => [
'foobar',
'unfoobar' ],
465 [
'wgAPIModules',
'wgAvailableRights' ],
467 'wgAPIModules' => [
'barbaz' =>
'ApiBarBaz' ],
468 'wgAvailableRights' => [
'barbaz' ]
471 'APIModules' => [
'foobar' =>
'ApiFooBar' ],
472 'AvailableRights' => [
'foobar',
'unfoobar' ],
475 'wgAPIModules' => [
'barbaz' =>
'ApiBarBaz',
'foobar' =>
'ApiFooBar' ],
476 'wgAvailableRights' => [
'barbaz',
'foobar',
'unfoobar' ],
480 [
'wgGroupPermissions' ],
482 'wgGroupPermissions' => [
483 'sysop' => [
'delete' ]
487 'GroupPermissions' => [
488 'sysop' => [
'undelete' ],
493 'wgGroupPermissions' => [
494 'sysop' => [
'delete',
'undelete' ],
511 $processor->extractInfo( $this->dir, [
'name' =>
'FooBar' ], 2 );
512 $processor->extractInfo(
534 $info = $processor->getExtractedInfo();
535 $this->assertArrayHasKey(
'FooBarPlugins', $info[
'attributes'] );
536 $this->assertSame( [
'ext.baz.foobar' ], $info[
'attributes'][
'FooBarPlugins'] );
537 $this->assertArrayNotHasKey(
'FizzBuzzMorePlugins', $info[
'attributes'] );
547 $processor->extractInfo(
554 'FizzBuzzMorePlugins' => [
561 $info = $processor->getExtractedInfo();
562 $this->assertArrayHasKey(
'FooBarPlugins', $info[
'attributes'] );
563 $this->assertSame( [
'ext.baz.foobar' ], $info[
'attributes'][
'FooBarPlugins'] );
564 $this->assertArrayHasKey(
'FizzBuzzMorePlugins', $info[
'attributes'] );
565 $this->assertSame( [
'ext.baz.fizzbuzz' ], $info[
'attributes'][
'FizzBuzzMorePlugins'] );
570 $globalSettings = TestingAccessWrapper::newFromClass(
575 file_get_contents(
"$IP/docs/extension.schema.v$version.json" ),
579 foreach ( $globalSettings
as $global ) {
580 if ( !isset( $schema[
'properties'][$global] ) ) {
581 $missing[] = $global;
585 $this->assertEquals( [], $missing,
586 "The following global settings are not documented in docs/extension.schema.json" );