Escape message 'redirectto' in Article
[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 /**
22 * @covers ExtensionProcessor::extractInfo
23 */
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' ),
30 ) );
31
32 $extracted = $processor->getExtractedInfo();
33 $attributes = $extracted['attributes'];
34 $this->assertArrayHasKey( 'AnAttribute', $attributes );
35 $this->assertArrayNotHasKey( '@metadata', $attributes );
36 }
37
38 public static function provideRegisterHooks() {
39 return array(
40 // No hooks
41 array(
42 array(),
43 self::$default,
44 array(),
45 ),
46 // No current hooks, adding one for "FooBaz"
47 array(
48 array(),
49 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self::$default,
50 array( 'FooBaz' => array( 'FooBazCallback' ) ),
51 ),
52 // Hook for "FooBaz", adding another one
53 array(
54 array( 'FooBaz' => array( 'PriorCallback' ) ),
55 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self::$default,
56 array( 'FooBaz' => array( 'PriorCallback', 'FooBazCallback' ) ),
57 ),
58 // Hook for "BarBaz", adding one for "FooBaz"
59 array(
60 array( 'BarBaz' => array( 'BarBazCallback' ) ),
61 array( 'Hooks' => array( 'FooBaz' => 'FooBazCallback' ) ) + self::$default,
62 array(
63 'BarBaz' => array( 'BarBazCallback' ),
64 'FooBaz' => array( 'FooBazCallback' ),
65 ),
66 ),
67 );
68 }
69
70 /**
71 * @covers ExtensionProcessor::extractHooks
72 * @dataProvider provideRegisterHooks
73 */
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'] );
79 }
80
81 /**
82 * @covers ExtensionProcessor::extractConfig
83 */
84 public function testExtractConfig() {
85 $processor = new ExtensionProcessor;
86 $info = array(
87 'config' => array(
88 'Bar' => 'somevalue',
89 'Foo' => 10,
90 '@IGNORED' => 'yes',
91 ),
92 ) + self::$default;
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'] );
98 }
99
100 public static function provideSetToGlobal() {
101 return array(
102 array(
103 array( 'wgAPIModules', 'wgAvailableRights' ),
104 array(),
105 array(
106 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
107 'AvailableRights' => array( 'foobar', 'unfoobar' ),
108 ),
109 array(
110 'wgAPIModules' => array( 'foobar' => 'ApiFooBar' ),
111 'wgAvailableRights' => array( 'foobar', 'unfoobar' ),
112 ),
113 ),
114 array(
115 array( 'wgAPIModules', 'wgAvailableRights' ),
116 array(
117 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz' ),
118 'wgAvailableRights' => array( 'barbaz' )
119 ),
120 array(
121 'APIModules' => array( 'foobar' => 'ApiFooBar' ),
122 'AvailableRights' => array( 'foobar', 'unfoobar' ),
123 ),
124 array(
125 'wgAPIModules' => array( 'barbaz' => 'ApiBarBaz', 'foobar' => 'ApiFooBar' ),
126 'wgAvailableRights' => array( 'barbaz', 'foobar', 'unfoobar' ),
127 ),
128 ),
129 array(
130 array( 'wgGroupPermissions' ),
131 array(
132 'wgGroupPermissions' => array( 'sysop' => array( 'delete' ) ),
133 ),
134 array(
135 'GroupPermissions' => array( 'sysop' => array( 'undelete' ), 'user' => array( 'edit' ) ),
136 ),
137 array(
138 'wgGroupPermissions' => array( 'sysop' => array( 'delete', 'undelete' ), 'user' => array( 'edit' ) ),
139 )
140 )
141 );
142 }
143 }
144
145
146 /**
147 * Allow overriding the default value of $this->globals
148 * so we can test merging
149 */
150 class MockExtensionProcessor extends ExtensionProcessor {
151 public function __construct( $globals = array() ) {
152 $this->globals = $globals + $this->globals;
153 }
154 }