Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / includes / logging / BlockLogFormatterTest.php
1 <?php
2
3 /**
4 * @covers BlockLogFormatter
5 */
6 class BlockLogFormatterTest extends LogFormatterTestCase {
7
8 /**
9 * Provide different rows from the logging table to test
10 * for backward compatibility.
11 * Do not change the existing data, just add a new database row
12 */
13 public static function provideBlockLogDatabaseRows() {
14 return [
15 // Current log format
16 [
17 [
18 'type' => 'block',
19 'action' => 'block',
20 'comment' => 'Block comment',
21 'user' => 0,
22 'user_text' => 'Sysop',
23 'namespace' => NS_USER,
24 'title' => 'Logtestuser',
25 'params' => [
26 '5::duration' => 'infinite',
27 '6::flags' => 'anononly',
28 ],
29 ],
30 [
31 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
32 . ' (anonymous users only)',
33 'api' => [
34 'duration' => 'infinite',
35 'flags' => [ 'anononly' ],
36 ],
37 'preload' => [ new TitleValue( NS_USER_TALK, 'Logtestuser' ) ],
38 ],
39 ],
40
41 // With blank page title (T224811)
42 [
43 [
44 'type' => 'block',
45 'action' => 'block',
46 'comment' => 'Block comment',
47 'user' => 0,
48 'user_text' => 'Sysop',
49 'namespace' => NS_USER,
50 'title' => '',
51 'params' => [],
52 ],
53 [
54 'text' => 'Sysop blocked (no username available) '
55 . 'with an expiration time of indefinite',
56 'api' => [
57 'duration' => 'infinite',
58 'flags' => [],
59 ],
60 'preload' => [],
61 ],
62 ],
63
64 // Old legacy log
65 [
66 [
67 'type' => 'block',
68 'action' => 'block',
69 'comment' => 'Block comment',
70 'user' => 0,
71 'user_text' => 'Sysop',
72 'namespace' => NS_USER,
73 'title' => 'Logtestuser',
74 'params' => [
75 'infinite',
76 'anononly',
77 ],
78 ],
79 [
80 'legacy' => true,
81 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
82 . ' (anonymous users only)',
83 'api' => [
84 'duration' => 'infinite',
85 'flags' => [ 'anononly' ],
86 ],
87 ],
88 ],
89
90 // Old legacy log without flag
91 [
92 [
93 'type' => 'block',
94 'action' => 'block',
95 'comment' => 'Block comment',
96 'user' => 0,
97 'user_text' => 'Sysop',
98 'namespace' => NS_USER,
99 'title' => 'Logtestuser',
100 'params' => [
101 'infinite',
102 ],
103 ],
104 [
105 'legacy' => true,
106 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
107 'api' => [
108 'duration' => 'infinite',
109 'flags' => [],
110 ],
111 ],
112 ],
113
114 // Very old legacy log without duration
115 [
116 [
117 'type' => 'block',
118 'action' => 'block',
119 'comment' => 'Block comment',
120 'user' => 0,
121 'user_text' => 'Sysop',
122 'namespace' => NS_USER,
123 'title' => 'Logtestuser',
124 'params' => [],
125 ],
126 [
127 'legacy' => true,
128 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
129 'api' => [
130 'duration' => 'infinite',
131 'flags' => [],
132 ],
133 ],
134 ],
135 ];
136 }
137
138 /**
139 * @dataProvider provideBlockLogDatabaseRows
140 */
141 public function testBlockLogDatabaseRows( $row, $extra ) {
142 $this->doTestLogFormatter( $row, $extra );
143 }
144
145 /**
146 * Provide different rows from the logging table to test
147 * for backward compatibility.
148 * Do not change the existing data, just add a new database row
149 */
150 public static function provideReblockLogDatabaseRows() {
151 return [
152 // Current log format
153 [
154 [
155 'type' => 'block',
156 'action' => 'reblock',
157 'comment' => 'Block comment',
158 'user' => 0,
159 'user_text' => 'Sysop',
160 'namespace' => NS_USER,
161 'title' => 'Logtestuser',
162 'params' => [
163 '5::duration' => 'infinite',
164 '6::flags' => 'anononly',
165 ],
166 ],
167 [
168 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
169 . ' indefinite (anonymous users only)',
170 'api' => [
171 'duration' => 'infinite',
172 'flags' => [ 'anononly' ],
173 ],
174 ],
175 ],
176
177 // Old log
178 [
179 [
180 'type' => 'block',
181 'action' => 'reblock',
182 'comment' => 'Block comment',
183 'user' => 0,
184 'user_text' => 'Sysop',
185 'namespace' => NS_USER,
186 'title' => 'Logtestuser',
187 'params' => [
188 'infinite',
189 'anononly',
190 ],
191 ],
192 [
193 'legacy' => true,
194 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
195 . ' indefinite (anonymous users only)',
196 'api' => [
197 'duration' => 'infinite',
198 'flags' => [ 'anononly' ],
199 ],
200 ],
201 ],
202
203 // Older log without flag
204 [
205 [
206 'type' => 'block',
207 'action' => 'reblock',
208 'comment' => 'Block comment',
209 'user' => 0,
210 'user_text' => 'Sysop',
211 'namespace' => NS_USER,
212 'title' => 'Logtestuser',
213 'params' => [
214 'infinite',
215 ]
216 ],
217 [
218 'legacy' => true,
219 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of indefinite',
220 'api' => [
221 'duration' => 'infinite',
222 'flags' => [],
223 ],
224 ],
225 ],
226 ];
227 }
228
229 /**
230 * @dataProvider provideReblockLogDatabaseRows
231 */
232 public function testReblockLogDatabaseRows( $row, $extra ) {
233 $this->doTestLogFormatter( $row, $extra );
234 }
235
236 /**
237 * Provide different rows from the logging table to test
238 * for backward compatibility.
239 * Do not change the existing data, just add a new database row
240 */
241 public static function provideUnblockLogDatabaseRows() {
242 return [
243 // Current log format
244 [
245 [
246 'type' => 'block',
247 'action' => 'unblock',
248 'comment' => 'Block comment',
249 'user' => 0,
250 'user_text' => 'Sysop',
251 'namespace' => NS_USER,
252 'title' => 'Logtestuser',
253 'params' => [],
254 ],
255 [
256 'text' => 'Sysop unblocked Logtestuser',
257 'api' => [],
258 ],
259 ],
260 ];
261 }
262
263 /**
264 * @dataProvider provideUnblockLogDatabaseRows
265 */
266 public function testUnblockLogDatabaseRows( $row, $extra ) {
267 $this->doTestLogFormatter( $row, $extra );
268 }
269
270 /**
271 * Provide different rows from the logging table to test
272 * for backward compatibility.
273 * Do not change the existing data, just add a new database row
274 */
275 public static function provideSuppressBlockLogDatabaseRows() {
276 return [
277 // Current log format
278 [
279 [
280 'type' => 'suppress',
281 'action' => 'block',
282 'comment' => 'Block comment',
283 'user' => 0,
284 'user_text' => 'Sysop',
285 'namespace' => NS_USER,
286 'title' => 'Logtestuser',
287 'params' => [
288 '5::duration' => 'infinite',
289 '6::flags' => 'anononly',
290 ],
291 ],
292 [
293 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
294 . ' (anonymous users only)',
295 'api' => [
296 'duration' => 'infinite',
297 'flags' => [ 'anononly' ],
298 ],
299 ],
300 ],
301
302 // legacy log
303 [
304 [
305 'type' => 'suppress',
306 'action' => 'block',
307 'comment' => 'Block comment',
308 'user' => 0,
309 'user_text' => 'Sysop',
310 'namespace' => NS_USER,
311 'title' => 'Logtestuser',
312 'params' => [
313 'infinite',
314 'anononly',
315 ],
316 ],
317 [
318 'legacy' => true,
319 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
320 . ' (anonymous users only)',
321 'api' => [
322 'duration' => 'infinite',
323 'flags' => [ 'anononly' ],
324 ],
325 ],
326 ],
327 ];
328 }
329
330 /**
331 * @dataProvider provideSuppressBlockLogDatabaseRows
332 */
333 public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
334 $this->doTestLogFormatter( $row, $extra );
335 }
336
337 /**
338 * Provide different rows from the logging table to test
339 * for backward compatibility.
340 * Do not change the existing data, just add a new database row
341 */
342 public static function provideSuppressReblockLogDatabaseRows() {
343 return [
344 // Current log format
345 [
346 [
347 'type' => 'suppress',
348 'action' => 'reblock',
349 'comment' => 'Block comment',
350 'user' => 0,
351 'user_text' => 'Sysop',
352 'namespace' => NS_USER,
353 'title' => 'Logtestuser',
354 'params' => [
355 '5::duration' => 'infinite',
356 '6::flags' => 'anononly',
357 ],
358 ],
359 [
360 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
361 . ' indefinite (anonymous users only)',
362 'api' => [
363 'duration' => 'infinite',
364 'flags' => [ 'anononly' ],
365 ],
366 ],
367 ],
368
369 // Legacy format
370 [
371 [
372 'type' => 'suppress',
373 'action' => 'reblock',
374 'comment' => 'Block comment',
375 'user' => 0,
376 'user_text' => 'Sysop',
377 'namespace' => NS_USER,
378 'title' => 'Logtestuser',
379 'params' => [
380 'infinite',
381 'anononly',
382 ],
383 ],
384 [
385 'legacy' => true,
386 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
387 . ' indefinite (anonymous users only)',
388 'api' => [
389 'duration' => 'infinite',
390 'flags' => [ 'anononly' ],
391 ],
392 ],
393 ],
394 ];
395 }
396
397 /**
398 * @dataProvider provideSuppressReblockLogDatabaseRows
399 */
400 public function testSuppressReblockLogDatabaseRows( $row, $extra ) {
401 $this->doTestLogFormatter( $row, $extra );
402 }
403
404 public function providePartialBlockLogDatabaseRows() {
405 return [
406 [
407 [
408 'type' => 'block',
409 'action' => 'block',
410 'comment' => 'Block comment',
411 'user' => 0,
412 'user_text' => 'Sysop',
413 'namespace' => NS_USER,
414 'title' => 'Logtestuser',
415 'params' => [
416 '5::duration' => 'infinite',
417 '6::flags' => 'anononly',
418 '7::restrictions' => [ 'pages' => [ 'User:Test1', 'Main Page' ] ],
419 'sitewide' => false,
420 ],
421 ],
422 [
423 'text' => 'Sysop blocked Logtestuser from editing the pages User:Test1 and Main Page'
424 . ' with an expiration time of indefinite (anonymous users only)',
425 'api' => [
426 'duration' => 'infinite',
427 'flags' => [ 'anononly' ],
428 'restrictions' => [
429 'pages' => [
430 [
431 'page_ns' => 2,
432 'page_title' => 'User:Test1',
433 ], [
434 'page_ns' => 0,
435 'page_title' => 'Main Page',
436 ],
437 ],
438 ],
439 'sitewide' => false,
440 ],
441 ],
442 ],
443 [
444 [
445 'type' => 'block',
446 'action' => 'block',
447 'comment' => 'Block comment',
448 'user' => 0,
449 'user_text' => 'Sysop',
450 'namespace' => NS_USER,
451 'title' => 'Logtestuser',
452 'params' => [
453 '5::duration' => 'infinite',
454 '6::flags' => 'anononly',
455 '7::restrictions' => [
456 'namespaces' => [ NS_USER ],
457 ],
458 'sitewide' => false,
459 ],
460 ],
461 [
462 'text' => 'Sysop blocked Logtestuser from editing the namespace User'
463 . ' with an expiration time of indefinite (anonymous users only)',
464 'api' => [
465 'duration' => 'infinite',
466 'flags' => [ 'anononly' ],
467 'restrictions' => [
468 'namespaces' => [ NS_USER ],
469 ],
470 'sitewide' => false,
471 ],
472 ],
473 ],
474 [
475 [
476 'type' => 'block',
477 'action' => 'block',
478 'comment' => 'Block comment',
479 'user' => 0,
480 'user_text' => 'Sysop',
481 'namespace' => NS_USER,
482 'title' => 'Logtestuser',
483 'params' => [
484 '5::duration' => 'infinite',
485 '6::flags' => 'anononly',
486 '7::restrictions' => [
487 'pages' => [ 'Main Page' ],
488 'namespaces' => [ NS_USER, NS_MAIN ],
489 ],
490 'sitewide' => false,
491 ],
492 ],
493 [
494 'text' => 'Sysop blocked Logtestuser from editing the page Main Page and the'
495 . ' namespaces User and (Main) with an expiration time of indefinite'
496 . ' (anonymous users only)',
497 'api' => [
498 'duration' => 'infinite',
499 'flags' => [ 'anononly' ],
500 'restrictions' => [
501 'pages' => [
502 [
503 'page_ns' => 0,
504 'page_title' => 'Main Page',
505 ],
506 ],
507 'namespaces' => [ NS_USER, NS_MAIN ],
508 ],
509 'sitewide' => false,
510 ],
511 ],
512 ],
513 [
514 [
515 'type' => 'block',
516 'action' => 'block',
517 'comment' => 'Block comment',
518 'user' => 0,
519 'user_text' => 'Sysop',
520 'namespace' => NS_USER,
521 'title' => 'Logtestuser',
522 'params' => [
523 '5::duration' => 'infinite',
524 '6::flags' => 'anononly',
525 'sitewide' => false,
526 ],
527 ],
528 [
529 'text' => 'Sysop blocked Logtestuser from specified non-editing actions'
530 . ' with an expiration time of indefinite (anonymous users only)',
531 'api' => [
532 'duration' => 'infinite',
533 'flags' => [ 'anononly' ],
534 'sitewide' => false,
535 ],
536 ],
537 ],
538 ];
539 }
540
541 /**
542 * @dataProvider providePartialBlockLogDatabaseRows
543 */
544 public function testPartialBlockLogDatabaseRows( $row, $extra ) {
545 $this->doTestLogFormatter( $row, $extra );
546 }
547 }