use Wikimedia\TestingAccessWrapper;
+/**
+ * @covers ExtensionProcessor
+ */
class ExtensionProcessorTest extends MediaWikiTestCase {
private $dir, $dirname;
'name' => 'FooBar',
];
- /**
- * @covers ExtensionProcessor::extractInfo
- */
public function testExtractInfo() {
// Test that attributes that begin with @ are ignored
$processor = new ExtensionProcessor();
'@metadata' => [ 'foobarbaz' ],
'AnAttribute' => [ 'omg' ],
'AutoloadClasses' => [ 'FooBar' => 'includes/FooBar.php' ],
+ 'SpecialPages' => [ 'Foo' => 'SpecialFoo' ],
+ 'callback' => 'FooBar::onRegistration',
], 1 );
$extracted = $processor->getExtractedInfo();
$this->assertArrayHasKey( 'AnAttribute', $attributes );
$this->assertArrayNotHasKey( '@metadata', $attributes );
$this->assertArrayNotHasKey( 'AutoloadClasses', $attributes );
+ $this->assertSame(
+ [ 'FooBar' => 'FooBar::onRegistration' ],
+ $extracted['callbacks']
+ );
+ $this->assertSame(
+ [ 'Foo' => 'SpecialFoo' ],
+ $extracted['globals']['wgSpecialPages']
+ );
}
- /**
- * @covers ExtensionProcessor::extractInfo
- */
- public function testExtractInfo_namespaces() {
+ public function testExtractNamespaces() {
// Test that namespace IDs can be overwritten
if ( !defined( 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X' ) ) {
define( 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X', 123456 );
'id' => 332200,
'constant' => 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
'name' => 'Test_A',
- 'content' => 'TestModel'
+ 'defaultcontentmodel' => 'TestModel',
+ 'gender' => [
+ 'male' => 'Male test',
+ 'female' => 'Female test',
+ ],
+ 'subpages' => true,
+ 'content' => true,
+ 'protection' => 'userright',
],
[ // Test_X will use ID 123456 not 334400
'id' => 334400,
'constant' => 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
'name' => 'Test_X',
- 'content' => 'TestModel'
+ 'defaultcontentmodel' => 'TestModel'
],
]
], 1 );
$this->assertSame( 'Test_X', $extracted['attributes']['ExtensionNamespaces'][123456] );
$this->assertSame( 'Test_A', $extracted['attributes']['ExtensionNamespaces'][332200] );
+ $this->assertSame(
+ [ 'male' => 'Male test', 'female' => 'Female test' ],
+ $extracted['globals']['wgExtraGenderNamespaces'][332200]
+ );
+ // A has subpages, X does not
+ $this->assertTrue( $extracted['globals']['wgNamespacesWithSubpages'][332200] );
+ $this->assertArrayNotHasKey( 123456, $extracted['globals']['wgNamespacesWithSubpages'] );
}
public static function provideRegisterHooks() {
}
/**
- * @covers ExtensionProcessor::extractHooks
* @dataProvider provideRegisterHooks
*/
public function testRegisterHooks( $pre, $info, $expected ) {
$this->assertEquals( $expected, $extracted['globals']['wgHooks'] );
}
- /**
- * @covers ExtensionProcessor::extractConfig1
- */
public function testExtractConfig1() {
$processor = new ExtensionProcessor;
$info = [
$this->assertEquals( 'somevalue', $extracted['globals']['egBar'] );
}
- /**
- * @covers ExtensionProcessor::extractConfig2
- */
public function testExtractConfig2() {
$processor = new ExtensionProcessor;
$info = [
'Bar' => [ 'value' => 'somevalue' ],
'Foo' => [ 'value' => 10 ],
'Path' => [ 'value' => 'foo.txt', 'path' => true ],
+ 'Namespaces' => [
+ 'value' => [
+ '10' => true,
+ '12' => false,
+ ],
+ 'merge_strategy' => 'array_plus',
+ ],
],
] + self::$default;
$info2 = [
$this->assertEquals( "{$this->dirname}/foo.txt", $extracted['globals']['wgPath'] );
// Custom prefix:
$this->assertEquals( 'somevalue', $extracted['globals']['egBar'] );
+ $this->assertSame(
+ [ 10 => true, 12 => false, ExtensionRegistry::MERGE_STRATEGY => 'array_plus' ],
+ $extracted['globals']['wgNamespaces']
+ );
}
/**
- * @covers ExtensionProcessor::addConfigGlobal()
* @expectedException RuntimeException
*/
public function testDuplicateConfigKey1() {
}
/**
- * @covers ExtensionProcessor::addConfigGlobal()
* @expectedException RuntimeException
*/
public function testDuplicateConfigKey2() {
}
/**
- * @covers ExtensionProcessor::extractExtensionMessagesFiles
* @dataProvider provideExtractExtensionMessagesFiles
*/
public function testExtractExtensionMessagesFiles( $input, $expected ) {
}
/**
- * @covers ExtensionProcessor::extractMessagesDirs
* @dataProvider provideExtractMessagesDirs
*/
public function testExtractMessagesDirs( $input, $expected ) {
}
}
- /**
- * @covers ExtensionProcessor::extractCredits
- */
public function testExtractCredits() {
$processor = new ExtensionProcessor();
$processor->extractInfo( $this->dir, self::$default, 1 );
}
/**
- * @covers ExtensionProcessor::extractResourceLoaderModules
* @dataProvider provideExtractResourceLoaderModules
*/
public function testExtractResourceLoaderModules( $input, $expected ) {
// Input
[
'ResourceFileModulePaths' => [
- 'localBasePath' => '',
- 'remoteExtPath' => 'FooBar',
+ 'localBasePath' => 'modules',
+ 'remoteExtPath' => 'FooBar/modules',
],
'ResourceModules' => [
// No paths
'wgResourceModules' => [
'test.foo' => [
'styles' => 'foo.js',
- 'localBasePath' => $dir,
- 'remoteExtPath' => 'FooBar',
+ 'localBasePath' => "$dir/modules",
+ 'remoteExtPath' => 'FooBar/modules',
],
'test.bar' => [
'styles' => 'bar.js',
'test.class' => [
'class' => 'FooBarModule',
'extra' => 'argument',
- 'localBasePath' => $dir,
- 'remoteExtPath' => 'FooBar',
+ 'localBasePath' => "$dir/modules",
+ 'remoteExtPath' => 'FooBar/modules',
],
'test.class.with.path' => [
'class' => 'FooBarPathModule',
'extra' => 'argument',
'localBasePath' => $dir,
- 'remoteExtPath' => 'FooBar',
+ 'remoteExtPath' => 'FooBar/modules',
]
],
],
/**
* Attributes under manifest_version 2
- *
- * @covers ExtensionProcessor::extractAttributes
- * @covers ExtensionProcessor::getExtractedInfo
*/
public function testExtractAttributes() {
$processor = new ExtensionProcessor();
/**
* Attributes under manifest_version 1
- *
- * @covers ExtensionProcessor::extractInfo
*/
public function testAttributes1() {
$processor = new ExtensionProcessor();
],
1
);
+ $processor->extractInfo(
+ $this->dir,
+ [
+ 'name' => 'FooBar2',
+ 'FizzBuzzMorePlugins' => [
+ 'ext.bar.fizzbuzz',
+ ]
+ ],
+ 1
+ );
$info = $processor->getExtractedInfo();
$this->assertArrayHasKey( 'FooBarPlugins', $info['attributes'] );
$this->assertSame( [ 'ext.baz.foobar' ], $info['attributes']['FooBarPlugins'] );
$this->assertArrayHasKey( 'FizzBuzzMorePlugins', $info['attributes'] );
- $this->assertSame( [ 'ext.baz.fizzbuzz' ], $info['attributes']['FizzBuzzMorePlugins'] );
+ $this->assertSame(
+ [ 'ext.baz.fizzbuzz', 'ext.bar.fizzbuzz' ],
+ $info['attributes']['FizzBuzzMorePlugins']
+ );
+ }
+
+ public function testAttributes1_notarray() {
+ $processor = new ExtensionProcessor();
+ $this->setExpectedException(
+ InvalidArgumentException::class,
+ "The value for 'FooBarPlugins' should be an array (from {$this->dir})"
+ );
+ $processor->extractInfo(
+ $this->dir,
+ [
+ 'FooBarPlugins' => 'ext.baz.foobar',
+ ] + self::$default,
+ 1
+ );
+ }
+
+ public function testExtractSimplePathBased() {
+ $processor = new ExtensionProcessor();
+ $processor->extractInfo(
+ $this->dir,
+ [
+ 'ParserTestFiles' => [
+ 'tests/parserTests.txt',
+ 'tests/extraParserTests.txt',
+ ],
+ 'ServiceWiringFiles' => [
+ 'includes/ServiceWiring.php'
+ ],
+ ] + self::$default,
+ 1
+ );
+ $globals = $processor->getExtractedInfo()['globals'];
+ $this->assertArrayHasKey( 'wgParserTestFiles', $globals );
+ $this->assertSame( [
+ "{$this->dirname}/tests/parserTests.txt",
+ "{$this->dirname}/tests/extraParserTests.txt"
+ ], $globals['wgParserTestFiles'] );
+ $this->assertArrayHasKey( 'wgServiceWiringFiles', $globals );
+ $this->assertSame( [
+ "{$this->dirname}/includes/ServiceWiring.php"
+ ], $globals['wgServiceWiringFiles'] );
+ }
+
+ public function testGetRequirements() {
+ $info = self::$default + [
+ 'requires' => [
+ 'MediaWiki' => '>= 1.25.0',
+ 'extensions' => [
+ 'Bar' => '*'
+ ]
+ ]
+ ];
+ $processor = new ExtensionProcessor();
+ $this->assertSame(
+ $info['requires'],
+ $processor->getRequirements( $info )
+ );
+ $this->assertSame(
+ [],
+ $processor->getRequirements( [] )
+ );
+ }
+
+ public function testGetExtraAutoloaderPaths() {
+ $processor = new ExtensionProcessor();
+ $this->assertSame(
+ [ "{$this->dirname}/vendor/autoload.php" ],
+ $processor->getExtraAutoloaderPaths( $this->dirname, [
+ 'load_composer_autoloader' => true,
+ ] )
+ );
}
/**