* @return array
*/
public function extractInfo( $path, array $info, $version ) {
+ $dir = dirname( $path );
if ( $version === 2 ) {
- $this->extractConfig2( $info );
+ $this->extractConfig2( $info, $dir );
} else {
// $version === 1
$this->extractConfig1( $info );
}
$this->extractHooks( $info );
- $dir = dirname( $path );
$this->extractExtensionMessagesFiles( $dir, $info );
$this->extractMessagesDirs( $dir, $info );
$this->extractNamespaces( $info );
* @todo In the future, this should be done via Config interfaces
*
* @param array $info
+ * @param string $dir
*/
- protected function extractConfig2( array $info ) {
+ protected function extractConfig2( array $info, $dir ) {
if ( isset( $info['config_prefix'] ) ) {
$prefix = $info['config_prefix'];
} else {
if ( isset( $value['merge_strategy'] ) ) {
$value[ExtensionRegistry::MERGE_STRATEGY] = $data['merge_strategy'];
}
+ if ( isset( $data['path'] ) && $data['path'] ) {
+ $value = "$dir/$value";
+ }
$this->globals["$prefix$key"] = $value;
}
}
class ExtensionProcessorTest extends MediaWikiTestCase {
- private $dir;
+ private $dir, $dirname;
public function setUp() {
parent::setUp();
$this->dir = __DIR__ . '/FooBar/extension.json';
+ $this->dirname = dirname( $this->dir );
}
/**
/**
* @covers ExtensionProcessor::extractConfig1
*/
- public function testExtractConfig() {
+ public function testExtractConfig1() {
$processor = new ExtensionProcessor;
$info = [
'config' => [
$this->assertEquals( 'somevalue', $extracted['globals']['egBar'] );
}
+ /**
+ * @covers ExtensionProcessor::extractConfig2
+ */
+ public function testExtractConfig2() {
+ $processor = new ExtensionProcessor;
+ $info = [
+ 'config' => [
+ 'Bar' => [ 'value' => 'somevalue' ],
+ 'Foo' => [ 'value' => 10 ],
+ 'Path' => [ 'value' => 'foo.txt', 'path' => true ],
+ ],
+ ] + self::$default;
+ $info2 = [
+ 'config' => [
+ 'Bar' => [ 'value' => 'somevalue' ],
+ ],
+ 'config_prefix' => 'eg',
+ 'name' => 'FooBar2',
+ ];
+ $processor->extractInfo( $this->dir, $info, 2 );
+ $processor->extractInfo( $this->dir, $info2, 2 );
+ $extracted = $processor->getExtractedInfo();
+ $this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] );
+ $this->assertEquals( 10, $extracted['globals']['wgFoo'] );
+ $this->assertEquals( "{$this->dirname}/foo.txt", $extracted['globals']['wgPath'] );
+ // Custom prefix:
+ $this->assertEquals( 'somevalue', $extracted['globals']['egBar'] );
+ }
+
public static function provideExtractExtensionMessagesFiles() {
$dir = __DIR__ . '/FooBar/';
return [