Merge "Merge namespace aliases like we merge namespace names"
[lhc/web/wiklou.git] / tests / phpunit / includes / logging / ProtectLogFormatterTest.php
1 <?php
2
3 class ProtectLogFormatterTest extends LogFormatterTestCase {
4
5 /**
6 * Provide different rows from the logging table to test
7 * for backward compatibility.
8 * Do not change the existing data, just add a new database row
9 */
10 public static function provideProtectLogDatabaseRows() {
11 return array(
12 // Current format
13 array(
14 array(
15 'type' => 'protect',
16 'action' => 'protect',
17 'comment' => 'protect comment',
18 'namespace' => NS_MAIN,
19 'title' => 'ProtectPage',
20 'params' => array(
21 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
22 '5:bool:cascade' => false,
23 'details' => array(
24 array(
25 'type' => 'edit',
26 'level' => 'sysop',
27 'expiry' => 'infinity',
28 'cascade' => false,
29 ),
30 array(
31 'type' => 'move',
32 'level' => 'sysop',
33 'expiry' => 'infinity',
34 'cascade' => false,
35 ),
36 ),
37 ),
38 ),
39 array(
40 'text' => 'User protected ProtectPage [Edit=Allow only administrators] ' .
41 '(indefinite) [Move=Allow only administrators] (indefinite)',
42 'api' => array(
43 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
44 'cascade' => false,
45 'details' => array(
46 array(
47 'type' => 'edit',
48 'level' => 'sysop',
49 'expiry' => 'infinite',
50 'cascade' => false,
51 ),
52 array(
53 'type' => 'move',
54 'level' => 'sysop',
55 'expiry' => 'infinite',
56 'cascade' => false,
57 ),
58 ),
59 ),
60 ),
61 ),
62
63 // Current format with cascade
64 array(
65 array(
66 'type' => 'protect',
67 'action' => 'protect',
68 'comment' => 'protect comment',
69 'namespace' => NS_MAIN,
70 'title' => 'ProtectPage',
71 'params' => array(
72 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
73 '5:bool:cascade' => true,
74 'details' => array(
75 array(
76 'type' => 'edit',
77 'level' => 'sysop',
78 'expiry' => 'infinity',
79 'cascade' => true,
80 ),
81 array(
82 'type' => 'move',
83 'level' => 'sysop',
84 'expiry' => 'infinity',
85 'cascade' => false,
86 ),
87 ),
88 ),
89 ),
90 array(
91 'text' => 'User protected ProtectPage [Edit=Allow only administrators] ' .
92 '(indefinite) [Move=Allow only administrators] (indefinite) [cascading]',
93 'api' => array(
94 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
95 'cascade' => true,
96 'details' => array(
97 array(
98 'type' => 'edit',
99 'level' => 'sysop',
100 'expiry' => 'infinite',
101 'cascade' => true,
102 ),
103 array(
104 'type' => 'move',
105 'level' => 'sysop',
106 'expiry' => 'infinite',
107 'cascade' => false,
108 ),
109 ),
110 ),
111 ),
112 ),
113
114 // Legacy format
115 array(
116 array(
117 'type' => 'protect',
118 'action' => 'protect',
119 'comment' => 'protect comment',
120 'namespace' => NS_MAIN,
121 'title' => 'ProtectPage',
122 'params' => array(
123 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
124 '',
125 ),
126 ),
127 array(
128 'legacy' => true,
129 'text' => 'User protected ProtectPage [edit=sysop] (indefinite)[move=sysop] (indefinite)',
130 'api' => array(
131 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
132 'cascade' => false,
133 ),
134 ),
135 ),
136
137 // Legacy format with cascade
138 array(
139 array(
140 'type' => 'protect',
141 'action' => 'protect',
142 'comment' => 'protect comment',
143 'namespace' => NS_MAIN,
144 'title' => 'ProtectPage',
145 'params' => array(
146 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
147 'cascade',
148 ),
149 ),
150 array(
151 'legacy' => true,
152 'text' => 'User protected ProtectPage [edit=sysop] ' .
153 '(indefinite)[move=sysop] (indefinite) [cascading]',
154 'api' => array(
155 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
156 'cascade' => true,
157 ),
158 ),
159 ),
160 );
161 }
162
163
164 /**
165 * @dataProvider provideProtectLogDatabaseRows
166 */
167 public function testProtectLogDatabaseRows( $row, $extra ) {
168 $this->doTestLogFormatter( $row, $extra );
169 }
170
171 /**
172 * Provide different rows from the logging table to test
173 * for backward compatibility.
174 * Do not change the existing data, just add a new database row
175 */
176 public static function provideModifyLogDatabaseRows() {
177 return array(
178 // Current format
179 array(
180 array(
181 'type' => 'protect',
182 'action' => 'modify',
183 'comment' => 'protect comment',
184 'namespace' => NS_MAIN,
185 'title' => 'ProtectPage',
186 'params' => array(
187 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
188 '5:bool:cascade' => false,
189 'details' => array(
190 array(
191 'type' => 'edit',
192 'level' => 'sysop',
193 'expiry' => 'infinity',
194 'cascade' => false,
195 ),
196 array(
197 'type' => 'move',
198 'level' => 'sysop',
199 'expiry' => 'infinity',
200 'cascade' => false,
201 ),
202 ),
203 ),
204 ),
205 array(
206 'text' => 'User changed protection level for ProtectPage ' .
207 '[Edit=Allow only administrators] ' .
208 '(indefinite) [Move=Allow only administrators] (indefinite)',
209 'api' => array(
210 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
211 'cascade' => false,
212 'details' => array(
213 array(
214 'type' => 'edit',
215 'level' => 'sysop',
216 'expiry' => 'infinite',
217 'cascade' => false,
218 ),
219 array(
220 'type' => 'move',
221 'level' => 'sysop',
222 'expiry' => 'infinite',
223 'cascade' => false,
224 ),
225 ),
226 ),
227 ),
228 ),
229
230 // Current format with cascade
231 array(
232 array(
233 'type' => 'protect',
234 'action' => 'modify',
235 'comment' => 'protect comment',
236 'namespace' => NS_MAIN,
237 'title' => 'ProtectPage',
238 'params' => array(
239 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
240 '5:bool:cascade' => true,
241 'details' => array(
242 array(
243 'type' => 'edit',
244 'level' => 'sysop',
245 'expiry' => 'infinity',
246 'cascade' => true,
247 ),
248 array(
249 'type' => 'move',
250 'level' => 'sysop',
251 'expiry' => 'infinity',
252 'cascade' => false,
253 ),
254 ),
255 ),
256 ),
257 array(
258 'text' => 'User changed protection level for ProtectPage ' .
259 '[Edit=Allow only administrators] (indefinite) ' .
260 '[Move=Allow only administrators] (indefinite) [cascading]',
261 'api' => array(
262 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
263 'cascade' => true,
264 'details' => array(
265 array(
266 'type' => 'edit',
267 'level' => 'sysop',
268 'expiry' => 'infinite',
269 'cascade' => true,
270 ),
271 array(
272 'type' => 'move',
273 'level' => 'sysop',
274 'expiry' => 'infinite',
275 'cascade' => false,
276 ),
277 ),
278 ),
279 ),
280 ),
281
282 // Legacy format
283 array(
284 array(
285 'type' => 'protect',
286 'action' => 'modify',
287 'comment' => 'protect comment',
288 'namespace' => NS_MAIN,
289 'title' => 'ProtectPage',
290 'params' => array(
291 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
292 '',
293 ),
294 ),
295 array(
296 'legacy' => true,
297 'text' => 'User changed protection level for ProtectPage ' .
298 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
299 'api' => array(
300 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
301 'cascade' => false,
302 ),
303 ),
304 ),
305
306 // Legacy format with cascade
307 array(
308 array(
309 'type' => 'protect',
310 'action' => 'modify',
311 'comment' => 'protect comment',
312 'namespace' => NS_MAIN,
313 'title' => 'ProtectPage',
314 'params' => array(
315 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
316 'cascade',
317 ),
318 ),
319 array(
320 'legacy' => true,
321 'text' => 'User changed protection level for ProtectPage ' .
322 '[edit=sysop] (indefinite)[move=sysop] (indefinite) [cascading]',
323 'api' => array(
324 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
325 'cascade' => true,
326 ),
327 ),
328 ),
329 );
330 }
331
332
333 /**
334 * @dataProvider provideModifyLogDatabaseRows
335 */
336 public function testModifyLogDatabaseRows( $row, $extra ) {
337 $this->doTestLogFormatter( $row, $extra );
338 }
339
340 /**
341 * Provide different rows from the logging table to test
342 * for backward compatibility.
343 * Do not change the existing data, just add a new database row
344 */
345 public static function provideUnprotectLogDatabaseRows() {
346 return array(
347 // Current format
348 array(
349 array(
350 'type' => 'protect',
351 'action' => 'unprotect',
352 'comment' => 'unprotect comment',
353 'namespace' => NS_MAIN,
354 'title' => 'ProtectPage',
355 'params' => array(),
356 ),
357 array(
358 'text' => 'User removed protection from ProtectPage',
359 'api' => array(),
360 ),
361 ),
362 );
363 }
364
365
366 /**
367 * @dataProvider provideUnprotectLogDatabaseRows
368 */
369 public function testUnprotectLogDatabaseRows( $row, $extra ) {
370 $this->doTestLogFormatter( $row, $extra );
371 }
372
373 /**
374 * Provide different rows from the logging table to test
375 * for backward compatibility.
376 * Do not change the existing data, just add a new database row
377 */
378 public static function provideMoveProtLogDatabaseRows() {
379 return array(
380 // Current format
381 array(
382 array(
383 'type' => 'protect',
384 'action' => 'move_prot',
385 'comment' => 'Move comment',
386 'namespace' => NS_MAIN,
387 'title' => 'NewPage',
388 'params' => array(
389 '4::oldtitle' => 'OldPage',
390 ),
391 ),
392 array(
393 'text' => 'User moved protection settings from OldPage to NewPage',
394 'api' => array(
395 'oldtitle_ns' => 0,
396 'oldtitle_title' => 'OldPage',
397 ),
398 ),
399 ),
400
401 // Legacy format
402 array(
403 array(
404 'type' => 'protect',
405 'action' => 'move_prot',
406 'comment' => 'Move comment',
407 'namespace' => NS_MAIN,
408 'title' => 'NewPage',
409 'params' => array(
410 'OldPage',
411 ),
412 ),
413 array(
414 'legacy' => true,
415 'text' => 'User moved protection settings from OldPage to NewPage',
416 'api' => array(
417 'oldtitle_ns' => 0,
418 'oldtitle_title' => 'OldPage',
419 ),
420 ),
421 ),
422 );
423 }
424
425 /**
426 * @dataProvider provideMoveProtLogDatabaseRows
427 */
428 public function testMoveProtLogDatabaseRows( $row, $extra ) {
429 $this->doTestLogFormatter( $row, $extra );
430 }
431 }