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(
21 public static function provideRegisterHooks() {
29 // No current hooks, adding one for "FooBaz"
32 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
33 array( 'FooBaz' => array( 'FooBazCallback' ) ),
35 // Hook for "FooBaz", adding another one
37 array( 'FooBaz' => array( 'PriorCallback' ) ),
38 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
39 array( 'FooBaz' => array( 'PriorCallback', 'FooBazCallback' ) ),
41 // Hook for "BarBaz", adding one for "FooBaz"
43 array( 'BarBaz' => array( 'BarBazCallback' ) ),
44 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self
::$default,
46 'BarBaz' => array( 'BarBazCallback' ),
47 'FooBaz' => array( 'FooBazCallback' ),
54 * @covers ExtensionProcessor::extractHooks
55 * @dataProvider provideRegisterHooks
57 public function testRegisterHooks( $pre, $info, $expected ) {
58 $processor = new MockExtensionProcessor( array( 'wgHooks' => $pre ) );
59 $processor->extractInfo( $this->dir
, $info );
60 $extracted = $processor->getExtractedInfo();
61 $this->assertEquals( $expected, $extracted['globals']['wgHooks'] );
65 * @covers ExtensionProcessor::extractConfig
67 public function testExtractConfig() {
68 $processor = new ExtensionProcessor
;
75 $processor->extractInfo( $this->dir
, $info );
76 $extracted = $processor->getExtractedInfo();
77 $this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] );
78 $this->assertEquals( 10, $extracted['globals']['wgFoo'] );
81 public static function provideSetToGlobal() {
84 array( 'wgAPIModules', 'wgAvailableRights' ),
87 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
88 'AvailableRights' => array( 'foobar', 'unfoobar' ),
91 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
92 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
96 array( 'wgAPIModules', 'wgAvailableRights' ),
98 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
99 'wgAvailableRights' => array( 'barbaz' )
102 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
103 'AvailableRights' => array( 'foobar', 'unfoobar' ),
106 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
107 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
111 array( 'wgGroupPermissions' ),
113 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
116 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
119 'wgGroupPermissions' => array( 'sysop' => array( 'delete', 'undelete' ), 'user' => array( 'edit' ) ),
128 * Allow overriding the default value of $this->globals
129 * so we can test merging
131 class MockExtensionProcessor
extends ExtensionProcessor
{
132 public function __construct( $globals = array() ) {
133 $this->globals
= $globals +
$this->globals
;