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