Implement extension registration from an extension.json file
[mediawiki.git] / tests / phpunit / includes / registration / ExtensionProcessorTest.php
blob221c2580c5f09a867f59bbe16b5a7cf77080daec
1 <?php
3 class ExtensionProcessorTest extends MediaWikiTestCase {
5 private $dir;
7 public function setUp() {
8 parent::setUp();
9 $this->dir = __DIR__ . '/FooBar/extension.json';
12 /**
13 * 'name' is absolutely required
15 * @var array
17 static $default = array(
18 'name' => 'FooBar',
21 public static function provideRegisterHooks() {
22 return array(
23 // No hooks
24 array(
25 array(),
26 self::$default,
27 array(),
29 // No current hooks, adding one for "FooBaz"
30 array(
31 array(),
32 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self::$default,
33 array( 'FooBaz' => array( 'FooBazCallback' ) ),
35 // Hook for "FooBaz", adding another one
36 array(
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"
42 array(
43 array( 'BarBaz' => array( 'BarBazCallback' ) ),
44 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self::$default,
45 array(
46 'BarBaz' => array( 'BarBazCallback' ),
47 'FooBaz' => array( 'FooBazCallback' ),
53 /**
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'] );
64 /**
65 * @covers ExtensionProcessor::extractConfig
67 public function testExtractConfig() {
68 $processor = new ExtensionProcessor;
69 $info = array(
70 'config' => array(
71 'Bar' => 'somevalue',
72 'Foo' => 10,
74 ) + self::$default;
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() {
82 return array(
83 array(
84 array( 'wgAPIModules', 'wgAvailableRights' ),
85 array(),
86 array(
87 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
88 'AvailableRights' => array( 'foobar', 'unfoobar' ),
90 array(
91 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
92 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
95 array(
96 array( 'wgAPIModules', 'wgAvailableRights' ),
97 array(
98 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
99 'wgAvailableRights' => array( 'barbaz' )
101 array(
102 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
103 'AvailableRights' => array( 'foobar', 'unfoobar' ),
105 array(
106 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
107 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
110 array(
111 array( 'wgGroupPermissions' ),
112 array(
113 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
115 array(
116 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
118 array(
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;