0d3187822762a89b31e87866a09b8e4cbd6b5ae2
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] );
127 public static function provideSetToGlobal() {
130 array( 'wgAPIModules', 'wgAvailableRights' ),
133 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
134 'AvailableRights' => array( 'foobar', 'unfoobar' ),
137 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
138 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
142 array( 'wgAPIModules', 'wgAvailableRights' ),
144 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
145 'wgAvailableRights' => array( 'barbaz' )
148 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
149 'AvailableRights' => array( 'foobar', 'unfoobar' ),
152 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
153 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
157 array( 'wgGroupPermissions' ),
159 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
162 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
165 'wgGroupPermissions' => array( 'sysop' => array( 'delete', 'undelete' ), 'user' => array( 'edit' ) ),
174 * Allow overriding the default value of $this->globals
175 * so we can test merging
177 class MockExtensionProcessor
extends ExtensionProcessor
{
178 public function __construct( $globals = array() ) {
179 $this->globals
= $globals +
$this->globals
;