96df354b01734dcc15859e1340cdd22b59ee161f
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 provideSetToGlobal() {
103 array( 'wgAPIModules', 'wgAvailableRights' ),
106 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
107 'AvailableRights' => array( 'foobar', 'unfoobar' ),
110 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
111 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
115 array( 'wgAPIModules', 'wgAvailableRights' ),
117 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
118 'wgAvailableRights' => array( 'barbaz' )
121 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
122 'AvailableRights' => array( 'foobar', 'unfoobar' ),
125 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
126 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
130 array( 'wgGroupPermissions' ),
132 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
135 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
138 'wgGroupPermissions' => array( 'sysop' => array( 'delete', 'undelete' ), 'user' => array( 'edit' ) ),
147 * Allow overriding the default value of $this->globals
148 * so we can test merging
150 class MockExtensionProcessor
extends ExtensionProcessor
{
151 public function __construct( $globals = array() ) {
152 $this->globals
= $globals +
$this->globals
;