SpecialTrackingCategories: Read from the extension registry
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / ExtensionProcessorTest.php
1 <?php
2
3 class ExtensionProcessorTest extends MediaWikiTestCase {
4
5 private $dir;
6
7 public function setUp() {
8 parent::setUp();
9 $this->dir = __DIR__ . '/FooBar/extension.json';
10 }
11
12 /**
13 * 'name' is absolutely required
14 *
15 * @var array
16 */
17 static $default = array(
18 'name' => 'FooBar',
19 );
20
21 public static function provideRegisterHooks() {
22 return array(
23 // No hooks
24 array(
25 array(),
26 self::$default,
27 array(),
28 ),
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' ) ),
34 ),
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' ) ),
40 ),
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' ),
48 ),
49 ),
50 );
51 }
52
53 /**
54 * @covers ExtensionProcessor::extractHooks
55 * @dataProvider provideRegisterHooks
56 */
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'] );
62 }
63
64 /**
65 * @covers ExtensionProcessor::extractConfig
66 */
67 public function testExtractConfig() {
68 $processor = new ExtensionProcessor;
69 $info = array(
70 'config' => array(
71 'Bar' => 'somevalue',
72 'Foo' => 10,
73 ),
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'] );
79 }
80
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' ),
89 ),
90 array(
91 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
92 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
93 ),
94 ),
95 array(
96 array( 'wgAPIModules', 'wgAvailableRights' ),
97 array(
98 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
99 'wgAvailableRights' => array( 'barbaz' )
100 ),
101 array(
102 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
103 'AvailableRights' => array( 'foobar', 'unfoobar' ),
104 ),
105 array(
106 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
107 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
108 ),
109 ),
110 array(
111 array( 'wgGroupPermissions' ),
112 array(
113 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
114 ),
115 array(
116 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
117 ),
118 array(
119 'wgGroupPermissions' => array( 'sysop' => array( 'delete', 'undelete' ), 'user' => array( 'edit' ) ),
120 )
121 )
122 );
123 }
124 }
125
126
127 /**
128 * Allow overriding the default value of $this->globals
129 * so we can test merging
130 */
131 class MockExtensionProcessor extends ExtensionProcessor {
132 public function __construct( $globals = array() ) {
133 $this->globals = $globals + $this->globals;
134 }
135 }