3 use Wikimedia\TestingAccessWrapper;
14 $this->dir = __DIR__ .
'/FooBar/extension.json';
15 $this->dirname = dirname( $this->dir );
30 $processor->extractInfo( $this->dir, self::$default + [
31 '@metadata' => [
'foobarbaz' ],
32 'AnAttribute' => [
'omg' ],
33 'AutoloadClasses' => [
'FooBar' =>
'includes/FooBar.php' ],
34 'SpecialPages' => [
'Foo' =>
'SpecialFoo' ],
35 'callback' =>
'FooBar::onRegistration',
38 $extracted = $processor->getExtractedInfo();
39 $attributes = $extracted[
'attributes'];
40 $this->assertArrayHasKey(
'AnAttribute', $attributes );
41 $this->assertArrayNotHasKey(
'@metadata', $attributes );
42 $this->assertArrayNotHasKey(
'AutoloadClasses', $attributes );
44 [
'FooBar' =>
'FooBar::onRegistration' ],
45 $extracted[
'callbacks']
48 [
'Foo' =>
'SpecialFoo' ],
49 $extracted[
'globals'][
'wgSpecialPages']
55 if ( !defined(
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X' ) ) {
56 define(
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X', 123456 );
60 $processor->extractInfo( $this->dir, self::$default + [
64 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
66 'defaultcontentmodel' =>
'TestModel',
68 'male' =>
'Male test',
69 'female' =>
'Female test',
73 'protection' =>
'userright',
77 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
79 'defaultcontentmodel' =>
'TestModel'
84 $extracted = $processor->getExtractedInfo();
86 $this->assertArrayHasKey(
87 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
90 $this->assertArrayNotHasKey(
91 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
96 $extracted[
'defines'][
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A'],
100 $this->assertArrayHasKey(
'ExtensionNamespaces', $extracted[
'attributes'] );
101 $this->assertArrayHasKey( 123456, $extracted[
'attributes'][
'ExtensionNamespaces'] );
102 $this->assertArrayHasKey( 332200, $extracted[
'attributes'][
'ExtensionNamespaces'] );
103 $this->assertArrayNotHasKey( 334400, $extracted[
'attributes'][
'ExtensionNamespaces'] );
105 $this->assertSame(
'Test_X', $extracted[
'attributes'][
'ExtensionNamespaces'][123456] );
106 $this->assertSame(
'Test_A', $extracted[
'attributes'][
'ExtensionNamespaces'][332200] );
108 [
'male' =>
'Male test',
'female' =>
'Female test' ],
109 $extracted[
'globals'][
'wgExtraGenderNamespaces'][332200]
112 $this->assertTrue( $extracted[
'globals'][
'wgNamespacesWithSubpages'][332200] );
113 $this->assertArrayNotHasKey( 123456, $extracted[
'globals'][
'wgNamespacesWithSubpages'] );
133 [
'FooBaz' => [
'FooBazCallback' ] ] + $merge,
137 [
'FooBaz' => [
'PriorCallback' ] ],
139 [
'FooBaz' => [
'PriorCallback',
'FooBazCallback' ] ] + $merge,
144 [
'Hooks' => [
'FooBaz' => [
'FooBazCallback' ] ] ] +
self::$default,
145 [
'FooBaz' => [
'FooBazCallback' ] ] + $merge,
149 [
'BarBaz' => [
'BarBazCallback' ] ],
152 'BarBaz' => [
'BarBazCallback' ],
153 'FooBaz' => [
'FooBazCallback' ],
161 'FooBaz' => [
'Callback1' ],
167 [
'Hooks' => [
'FooBaz' => [
'Callback1',
'Callback2' ] ] ] +
self::$default,
169 'FooBaz' => [
'Callback1',
'Callback2' ],
180 $processor->extractInfo( $this->dir, $info, 1 );
181 $extracted = $processor->getExtractedInfo();
182 $this->assertEquals( $expected, $extracted[
'globals'][
'wgHooks'] );
189 'Bar' =>
'somevalue',
201 $processor->extractInfo( $this->dir, $info, 1 );
202 $processor->extractInfo( $this->dir, $info2, 1 );
203 $extracted = $processor->getExtractedInfo();
204 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'wgBar'] );
205 $this->assertEquals( 10, $extracted[
'globals'][
'wgFoo'] );
206 $this->assertArrayNotHasKey(
'wg@IGNORED', $extracted[
'globals'] );
208 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'egBar'] );
215 'Bar' => [
'value' =>
'somevalue' ],
216 'Foo' => [
'value' => 10 ],
217 'Path' => [
'value' =>
'foo.txt',
'path' =>
true ],
223 'merge_strategy' =>
'array_plus',
229 'Bar' => [
'value' =>
'somevalue' ],
231 'config_prefix' =>
'eg',
234 $processor->extractInfo( $this->dir, $info, 2 );
235 $processor->extractInfo( $this->dir, $info2, 2 );
236 $extracted = $processor->getExtractedInfo();
237 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'wgBar'] );
238 $this->assertEquals( 10, $extracted[
'globals'][
'wgFoo'] );
239 $this->assertEquals(
"{$this->dirname}/foo.txt", $extracted[
'globals'][
'wgPath'] );
241 $this->assertEquals(
'somevalue', $extracted[
'globals'][
'egBar'] );
244 $extracted[
'globals'][
'wgNamespaces']
264 $processor->extractInfo( $this->dir, $info, 1 );
265 $processor->extractInfo( $this->dir, $info2, 1 );
275 'Bar' => [
'value' =>
'somevalue' ],
280 'Bar' => [
'value' =>
'somevalue' ],
284 $processor->extractInfo( $this->dir, $info, 2 );
285 $processor->extractInfo( $this->dir, $info2, 2 );
289 $dir = __DIR__ .
'/FooBar/';
292 [
'ExtensionMessagesFiles' => [
'FooBarAlias' =>
'FooBar.alias.php' ] ],
293 [
'wgExtensionMessagesFiles' => [
'FooBarAlias' =>
$dir .
'FooBar.alias.php' ] ]
297 'ExtensionMessagesFiles' => [
298 'FooBarAlias' =>
'FooBar.alias.php',
299 'FooBarMagic' =>
'FooBar.magic.i18n.php',
303 'wgExtensionMessagesFiles' => [
304 'FooBarAlias' =>
$dir .
'FooBar.alias.php',
305 'FooBarMagic' =>
$dir .
'FooBar.magic.i18n.php',
317 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
318 $out = $processor->getExtractedInfo();
319 foreach ( $expected
as $key =>
$value ) {
320 $this->assertEquals(
$value,
$out[
'globals'][$key] );
325 $dir = __DIR__ .
'/FooBar/';
328 [
'MessagesDirs' => [
'VisualEditor' =>
'i18n' ] ],
329 [
'wgMessagesDirs' => [
'VisualEditor' => [
$dir .
'i18n' ] ] ]
332 [
'MessagesDirs' => [
'VisualEditor' => [
'i18n',
'foobar' ] ] ],
333 [
'wgMessagesDirs' => [
'VisualEditor' => [
$dir .
'i18n',
$dir .
'foobar' ] ] ]
343 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
344 $out = $processor->getExtractedInfo();
345 foreach ( $expected
as $key =>
$value ) {
346 $this->assertEquals(
$value,
$out[
'globals'][$key] );
352 $processor->extractInfo( $this->dir, self::$default, 1 );
354 $processor->extractInfo( $this->dir, self::$default, 1 );
362 array $expectedGlobals,
363 array $expectedAttribs = []
366 $processor->extractInfo( $this->dir,
$input + self::$default, 1 );
367 $out = $processor->getExtractedInfo();
368 foreach ( $expectedGlobals
as $key =>
$value ) {
369 $this->assertEquals(
$value,
$out[
'globals'][$key] );
371 foreach ( $expectedAttribs
as $key =>
$value ) {
372 $this->assertEquals(
$value,
$out[
'attributes'][$key] );
377 $dir = __DIR__ .
'/FooBar';
383 'ResourceModules' => [
385 'styles' =>
'foobar.js',
386 'localBasePath' =>
'',
387 'remoteExtPath' =>
'FooBar',
393 'wgResourceModules' => [
395 'styles' =>
'foobar.js',
396 'localBasePath' =>
$dir,
397 'remoteExtPath' =>
'FooBar',
406 'ResourceFileModulePaths' => [
407 'localBasePath' =>
'modules',
408 'remoteExtPath' =>
'FooBar/modules',
410 'ResourceModules' => [
413 'styles' =>
'foo.js',
417 'styles' =>
'bar.js',
418 'localBasePath' =>
'subdir',
419 'remoteExtPath' =>
'FooBar/subdir',
423 'class' =>
'FooBarModule',
424 'extra' =>
'argument',
427 'test.class.with.path' => [
428 'class' =>
'FooBarPathModule',
429 'extra' =>
'argument',
430 'localBasePath' =>
'',
436 'wgResourceModules' => [
438 'styles' =>
'foo.js',
439 'localBasePath' =>
"$dir/modules",
440 'remoteExtPath' =>
'FooBar/modules',
443 'styles' =>
'bar.js',
444 'localBasePath' =>
"$dir/subdir",
445 'remoteExtPath' =>
'FooBar/subdir',
448 'class' =>
'FooBarModule',
449 'extra' =>
'argument',
450 'localBasePath' =>
"$dir/modules",
451 'remoteExtPath' =>
'FooBar/modules',
453 'test.class.with.path' => [
454 'class' =>
'FooBarPathModule',
455 'extra' =>
'argument',
456 'localBasePath' =>
$dir,
457 'remoteExtPath' =>
'FooBar/modules',
466 'ResourceFileModulePaths' => [
467 'localBasePath' =>
'',
468 'remoteSkinPath' =>
'FooBar',
470 'ResourceModuleSkinStyles' => [
472 'test.foo' =>
'foo.css',
478 'wgResourceModuleSkinStyles' => [
480 'test.foo' =>
'foo.css',
481 'localBasePath' =>
$dir,
482 'remoteSkinPath' =>
'FooBar',
491 'ResourceFileModulePaths' => [
492 'localBasePath' =>
'',
493 'remoteSkinPath' =>
'FooBar',
495 'ResourceModuleSkinStyles' => [
497 'test.foo' =>
'foo.css',
498 'remoteSkinPath' =>
'BarFoo'
504 'wgResourceModuleSkinStyles' => [
506 'test.foo' =>
'foo.css',
507 'localBasePath' =>
$dir,
508 'remoteSkinPath' =>
'BarFoo',
513 'QUnit test module' => [
516 'QUnitTestModule' => [
517 'localBasePath' =>
'',
518 'remoteExtPath' =>
'Foo',
519 'scripts' =>
'bar.js',
525 'QUnitTestModules' => [
527 'localBasePath' =>
$dir,
528 'remoteExtPath' =>
'Foo',
529 'scripts' =>
'bar.js',
540 [
'wgAPIModules',
'wgAvailableRights' ],
543 'APIModules' => [
'foobar' =>
'ApiFooBar' ],
544 'AvailableRights' => [
'foobar',
'unfoobar' ],
547 'wgAPIModules' => [
'foobar' =>
'ApiFooBar' ],
548 'wgAvailableRights' => [
'foobar',
'unfoobar' ],
552 [
'wgAPIModules',
'wgAvailableRights' ],
554 'wgAPIModules' => [
'barbaz' =>
'ApiBarBaz' ],
555 'wgAvailableRights' => [
'barbaz' ]
558 'APIModules' => [
'foobar' =>
'ApiFooBar' ],
559 'AvailableRights' => [
'foobar',
'unfoobar' ],
562 'wgAPIModules' => [
'barbaz' =>
'ApiBarBaz',
'foobar' =>
'ApiFooBar' ],
563 'wgAvailableRights' => [
'barbaz',
'foobar',
'unfoobar' ],
567 [
'wgGroupPermissions' ],
569 'wgGroupPermissions' => [
570 'sysop' => [
'delete' ]
574 'GroupPermissions' => [
575 'sysop' => [
'undelete' ],
580 'wgGroupPermissions' => [
581 'sysop' => [
'delete',
'undelete' ],
595 $processor->extractInfo( $this->dir, [
'name' =>
'FooBar' ], 2 );
596 $processor->extractInfo(
618 $info = $processor->getExtractedInfo();
619 $this->assertArrayHasKey(
'FooBarPlugins', $info[
'attributes'] );
620 $this->assertSame( [
'ext.baz.foobar' ], $info[
'attributes'][
'FooBarPlugins'] );
621 $this->assertArrayNotHasKey(
'FizzBuzzMorePlugins', $info[
'attributes'] );
629 $processor->extractInfo(
636 'FizzBuzzMorePlugins' => [
642 $processor->extractInfo(
646 'FizzBuzzMorePlugins' => [
653 $info = $processor->getExtractedInfo();
654 $this->assertArrayHasKey(
'FooBarPlugins', $info[
'attributes'] );
655 $this->assertSame( [
'ext.baz.foobar' ], $info[
'attributes'][
'FooBarPlugins'] );
656 $this->assertArrayHasKey(
'FizzBuzzMorePlugins', $info[
'attributes'] );
658 [
'ext.baz.fizzbuzz',
'ext.bar.fizzbuzz' ],
659 $info[
'attributes'][
'FizzBuzzMorePlugins']
665 $this->setExpectedException(
667 "The value for 'FooBarPlugins' should be an array (from {$this->dir})"
669 $processor->extractInfo(
672 'FooBarPlugins' =>
'ext.baz.foobar',
680 $processor->extractInfo(
683 'ParserTestFiles' => [
684 'tests/parserTests.txt',
685 'tests/extraParserTests.txt',
687 'ServiceWiringFiles' => [
688 'includes/ServiceWiring.php'
693 $globals = $processor->getExtractedInfo()[
'globals'];
694 $this->assertArrayHasKey(
'wgParserTestFiles', $globals );
696 "{$this->dirname}/tests/parserTests.txt",
697 "{$this->dirname}/tests/extraParserTests.txt"
698 ], $globals[
'wgParserTestFiles'] );
699 $this->assertArrayHasKey(
'wgServiceWiringFiles', $globals );
701 "{$this->dirname}/includes/ServiceWiring.php"
702 ], $globals[
'wgServiceWiringFiles'] );
706 $info = self::$default + [
708 'MediaWiki' =>
'>= 1.25.0',
720 $processor->getRequirements( $info )
724 $processor->getRequirements( [] )
731 [
"{$this->dirname}/vendor/autoload.php" ],
732 $processor->getExtraAutoloaderPaths( $this->dirname, [
733 'load_composer_autoloader' =>
true,
745 $globalSettings = TestingAccessWrapper::newFromClass(
750 file_get_contents(
"$IP/docs/extension.schema.v$version.json" ),
754 foreach ( $globalSettings
as $global ) {
755 if ( !isset( $schema[
'properties'][$global] ) ) {
756 $missing[] = $global;
760 $this->assertEquals( [], $missing,
761 "The following global settings are not documented in docs/extension.schema.json" );