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() {
46 // No current hooks, adding one for "FooBaz"
49 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
50 array( 'FooBaz' => array( 'FooBazCallback' ) ),
52 // Hook for "FooBaz", adding another one
54 array( 'FooBaz' => array( 'PriorCallback' ) ),
55 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
56 array( 'FooBaz' => array( 'PriorCallback', 'FooBazCallback' ) ),
58 // Hook for "BarBaz", adding one for "FooBaz"
60 array( 'BarBaz' => array( 'BarBazCallback' ) ),
61 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
63 'BarBaz' => array( 'BarBazCallback' ),
64 'FooBaz' => array( 'FooBazCallback' ),
71 * @covers ExtensionProcessor::extractHooks
72 * @dataProvider provideRegisterHooks
74 public function testRegisterHooks( $pre, $info, $expected ) {
75 $processor = new MockExtensionProcessor( array( 'wgHooks' => $pre ) );
76 $processor->extractInfo( $this->dir
, $info );
77 $extracted = $processor->getExtractedInfo();
78 $this->assertEquals( $expected, $extracted['globals']['wgHooks'] );
82 * @covers ExtensionProcessor::extractConfig
84 public function testExtractConfig() {
85 $processor = new ExtensionProcessor
;
93 $processor->extractInfo( $this->dir
, $info );
94 $extracted = $processor->getExtractedInfo();
95 $this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] );
96 $this->assertEquals( 10, $extracted['globals']['wgFoo'] );
97 $this->assertArrayNotHasKey( 'wg@IGNORED', $extracted['globals'] );
100 public static function provideExtractMessageSettings() {
101 $dir = __DIR__
. '/FooBar/';
104 array( 'MessagesDirs' => array( 'VisualEditor' => 'i18n' ) ),
105 array( 'wgMessagesDirs' => array( 'VisualEditor' => array( $dir . 'i18n' ) ) )
108 array( 'MessagesDirs' => array( 'VisualEditor' => array( 'i18n', 'foobar' ) ) ),
109 array( 'wgMessagesDirs' => array( 'VisualEditor' => array( $dir . 'i18n', $dir . 'foobar' ) ) )
115 * @covers ExtensionProcessor::extractMessageSettings
116 * @dataProvider provideExtractMessageSettings
118 public function testExtractMessageSettings( $input, $expected ) {
119 $processor = new ExtensionProcessor();
120 $processor->extractInfo( $this->dir
, $input + self
::$default );
121 $out = $processor->getExtractedInfo();
122 foreach ( $expected as $key => $value ) {
123 $this->assertEquals( $value, $out['globals'][$key] );
128 * @covers ExtensionProcessor::extractResourceLoaderModules
129 * @dataProvider provideExtractResourceLoaderModules
131 public function testExtractResourceLoaderModules( $input, $expected ) {
132 $processor = new ExtensionProcessor();
133 $processor->extractInfo( $this->dir
, $input + self
::$default );
134 $out = $processor->getExtractedInfo();
135 foreach ( $expected as $key => $value ) {
136 $this->assertEquals( $value, $out['globals'][$key] );
140 public static function provideExtractResourceLoaderModules() {
141 $dir = __DIR__
. '/FooBar/';
143 // Generic module with localBasePath/remoteExtPath specified
147 'ResourceModules' => array(
149 'styles' => 'foobar.js',
150 'localBasePath' => '',
151 'remoteExtPath' => 'FooBar',
157 'wgResourceModules' => array(
159 'styles' => 'foobar.js',
160 'localBasePath' => $dir,
161 'remoteExtPath' => 'FooBar',
166 // ResourceFileModulePaths specified:
170 'ResourceFileModulePaths' => array(
171 'localBasePath' => '',
172 'remoteExtPath' => 'FooBar',
174 'ResourceModules' => array(
177 'styles' => 'foo.js',
179 // Different paths set
181 'styles' => 'bar.js',
182 'localBasePath' => 'subdir',
183 'remoteExtPath' => 'FooBar/subdir',
185 // Custom class with no paths set
186 'test.class' => array(
187 'class' => 'FooBarModule',
188 'extra' => 'argument',
190 // Custom class with a localBasePath
191 'test.class.with.path' => array(
192 'class' => 'FooBarPathModule',
193 'extra' => 'argument',
194 'localBasePath' => '',
200 'wgResourceModules' => array(
202 'styles' => 'foo.js',
203 'localBasePath' => $dir,
204 'remoteExtPath' => 'FooBar',
207 'styles' => 'bar.js',
208 'localBasePath' => $dir . 'subdir',
209 'remoteExtPath' => 'FooBar/subdir',
211 'test.class' => array(
212 'class' => 'FooBarModule',
213 'extra' => 'argument',
215 'test.class.with.path' => array(
216 'class' => 'FooBarPathModule',
217 'extra' => 'argument',
218 'localBasePath' => $dir,
226 public static function provideSetToGlobal() {
229 array( 'wgAPIModules', 'wgAvailableRights' ),
232 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
233 'AvailableRights' => array( 'foobar', 'unfoobar' ),
236 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
237 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
241 array( 'wgAPIModules', 'wgAvailableRights' ),
243 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
244 'wgAvailableRights' => array( 'barbaz' )
247 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
248 'AvailableRights' => array( 'foobar', 'unfoobar' ),
251 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
252 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
256 array( 'wgGroupPermissions' ),
258 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
261 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
264 'wgGroupPermissions' => array( 'sysop' => array( 'delete', 'undelete' ), 'user' => array( 'edit' ) ),
273 * Allow overriding the default value of $this->globals
274 * so we can test merging
276 class MockExtensionProcessor
extends ExtensionProcessor
{
277 public function __construct( $globals = array() ) {
278 $this->globals
= $globals +
$this->globals
;