Fix testsuites for LogFormatter
[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 ],
38 ],
39
40 // Old legacy log
41 [
42 [
43 'type' => 'block',
44 'action' => 'block',
45 'comment' => 'Block comment',
46 'user' => 0,
47 'user_text' => 'Sysop',
48 'namespace' => NS_USER,
49 'title' => 'Logtestuser',
50 'params' => [
51 'infinite',
52 'anononly',
53 ],
54 ],
55 [
56 'legacy' => true,
57 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
58 . ' (anonymous users only)',
59 'api' => [
60 'duration' => 'infinite',
61 'flags' => [ 'anononly' ],
62 ],
63 ],
64 ],
65
66 // Old legacy log without flag
67 [
68 [
69 'type' => 'block',
70 'action' => 'block',
71 'comment' => 'Block comment',
72 'user' => 0,
73 'user_text' => 'Sysop',
74 'namespace' => NS_USER,
75 'title' => 'Logtestuser',
76 'params' => [
77 'infinite',
78 ],
79 ],
80 [
81 'legacy' => true,
82 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
83 'api' => [
84 'duration' => 'infinite',
85 'flags' => [],
86 ],
87 ],
88 ],
89
90 // Very old legacy log without duration
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 ],
102 [
103 'legacy' => true,
104 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
105 'api' => [
106 'duration' => 'infinite',
107 'flags' => [],
108 ],
109 ],
110 ],
111 ];
112 }
113
114 /**
115 * @dataProvider provideBlockLogDatabaseRows
116 */
117 public function testBlockLogDatabaseRows( $row, $extra ) {
118 $this->doTestLogFormatter( $row, $extra );
119 }
120
121 /**
122 * Provide different rows from the logging table to test
123 * for backward compatibility.
124 * Do not change the existing data, just add a new database row
125 */
126 public static function provideReblockLogDatabaseRows() {
127 return [
128 // Current log format
129 [
130 [
131 'type' => 'block',
132 'action' => 'reblock',
133 'comment' => 'Block comment',
134 'user' => 0,
135 'user_text' => 'Sysop',
136 'namespace' => NS_USER,
137 'title' => 'Logtestuser',
138 'params' => [
139 '5::duration' => 'infinite',
140 '6::flags' => 'anononly',
141 ],
142 ],
143 [
144 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
145 . ' indefinite (anonymous users only)',
146 'api' => [
147 'duration' => 'infinite',
148 'flags' => [ 'anononly' ],
149 ],
150 ],
151 ],
152
153 // Old log
154 [
155 [
156 'type' => 'block',
157 'action' => 'reblock',
158 'comment' => 'Block comment',
159 'user' => 0,
160 'user_text' => 'Sysop',
161 'namespace' => NS_USER,
162 'title' => 'Logtestuser',
163 'params' => [
164 'infinite',
165 'anononly',
166 ],
167 ],
168 [
169 'legacy' => true,
170 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
171 . ' indefinite (anonymous users only)',
172 'api' => [
173 'duration' => 'infinite',
174 'flags' => [ 'anononly' ],
175 ],
176 ],
177 ],
178
179 // Older log without flag
180 [
181 [
182 'type' => 'block',
183 'action' => 'reblock',
184 'comment' => 'Block comment',
185 'user' => 0,
186 'user_text' => 'Sysop',
187 'namespace' => NS_USER,
188 'title' => 'Logtestuser',
189 'params' => [
190 'infinite',
191 ]
192 ],
193 [
194 'legacy' => true,
195 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of indefinite',
196 'api' => [
197 'duration' => 'infinite',
198 'flags' => [],
199 ],
200 ],
201 ],
202 ];
203 }
204
205 /**
206 * @dataProvider provideReblockLogDatabaseRows
207 */
208 public function testReblockLogDatabaseRows( $row, $extra ) {
209 $this->doTestLogFormatter( $row, $extra );
210 }
211
212 /**
213 * Provide different rows from the logging table to test
214 * for backward compatibility.
215 * Do not change the existing data, just add a new database row
216 */
217 public static function provideUnblockLogDatabaseRows() {
218 return [
219 // Current log format
220 [
221 [
222 'type' => 'block',
223 'action' => 'unblock',
224 'comment' => 'Block comment',
225 'user' => 0,
226 'user_text' => 'Sysop',
227 'namespace' => NS_USER,
228 'title' => 'Logtestuser',
229 'params' => [],
230 ],
231 [
232 'text' => 'Sysop unblocked Logtestuser',
233 'api' => [],
234 ],
235 ],
236 ];
237 }
238
239 /**
240 * @dataProvider provideUnblockLogDatabaseRows
241 */
242 public function testUnblockLogDatabaseRows( $row, $extra ) {
243 $this->doTestLogFormatter( $row, $extra );
244 }
245
246 /**
247 * Provide different rows from the logging table to test
248 * for backward compatibility.
249 * Do not change the existing data, just add a new database row
250 */
251 public static function provideSuppressBlockLogDatabaseRows() {
252 return [
253 // Current log format
254 [
255 [
256 'type' => 'suppress',
257 'action' => 'block',
258 'comment' => 'Block comment',
259 'user' => 0,
260 'user_text' => 'Sysop',
261 'namespace' => NS_USER,
262 'title' => 'Logtestuser',
263 'params' => [
264 '5::duration' => 'infinite',
265 '6::flags' => 'anononly',
266 ],
267 ],
268 [
269 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
270 . ' (anonymous users only)',
271 'api' => [
272 'duration' => 'infinite',
273 'flags' => [ 'anononly' ],
274 ],
275 ],
276 ],
277
278 // legacy log
279 [
280 [
281 'type' => 'suppress',
282 'action' => 'block',
283 'comment' => 'Block comment',
284 'user' => 0,
285 'user_text' => 'Sysop',
286 'namespace' => NS_USER,
287 'title' => 'Logtestuser',
288 'params' => [
289 'infinite',
290 'anononly',
291 ],
292 ],
293 [
294 'legacy' => true,
295 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
296 . ' (anonymous users only)',
297 'api' => [
298 'duration' => 'infinite',
299 'flags' => [ 'anononly' ],
300 ],
301 ],
302 ],
303 ];
304 }
305
306 /**
307 * @dataProvider provideSuppressBlockLogDatabaseRows
308 */
309 public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
310 $this->setMwGlobals(
311 'wgGroupPermissions',
312 [
313 'oversight' => [
314 'viewsuppressed' => true,
315 'suppressionlog' => true,
316 ],
317 ]
318 );
319 $this->doTestLogFormatter( $row, $extra, [ 'oversight' ] );
320 }
321
322 /**
323 * Provide different rows from the logging table to test
324 * for backward compatibility.
325 * Do not change the existing data, just add a new database row
326 */
327 public static function provideSuppressBlockLogDatabaseRowsNonPrivileged() {
328 return [
329 // Current log format
330 [
331 [
332 'type' => 'suppress',
333 'action' => 'block',
334 'comment' => 'Block comment',
335 'user' => 0,
336 'user_text' => 'Sysop',
337 'namespace' => NS_USER,
338 'title' => 'Logtestuser',
339 'params' => [
340 '5::duration' => 'infinite',
341 '6::flags' => 'anononly',
342 ],
343 ],
344 [
345 'text' => '(username removed) (log details removed)',
346 'api' => [
347 'duration' => 'infinite',
348 'flags' => [ 'anononly' ],
349 ],
350 ],
351 ],
352
353 // legacy log
354 [
355 [
356 'type' => 'suppress',
357 'action' => 'block',
358 'comment' => 'Block comment',
359 'user' => 0,
360 'user_text' => 'Sysop',
361 'namespace' => NS_USER,
362 'title' => 'Logtestuser',
363 'params' => [
364 'infinite',
365 'anononly',
366 ],
367 ],
368 [
369 'legacy' => true,
370 'text' => '(username removed) (log details removed)',
371 'api' => [
372 'duration' => 'infinite',
373 'flags' => [ 'anononly' ],
374 ],
375 ],
376 ],
377 ];
378 }
379
380 /**
381 * @dataProvider provideSuppressBlockLogDatabaseRowsNonPrivileged
382 */
383 public function testSuppressBlockLogDatabaseRowsNonPrivileged( $row, $extra ) {
384 $this->user = $this->getTestUser()->getUser();
385 $this->doTestLogFormatter( $row, $extra );
386 }
387
388 /**
389 * Provide different rows from the logging table to test
390 * for backward compatibility.
391 * Do not change the existing data, just add a new database row
392 */
393 public static function provideSuppressReblockLogDatabaseRows() {
394 return [
395 // Current log format
396 [
397 [
398 'type' => 'suppress',
399 'action' => 'reblock',
400 'comment' => 'Block comment',
401 'user' => 0,
402 'user_text' => 'Sysop',
403 'namespace' => NS_USER,
404 'title' => 'Logtestuser',
405 'params' => [
406 '5::duration' => 'infinite',
407 '6::flags' => 'anononly',
408 ],
409 ],
410 [
411 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
412 . ' indefinite (anonymous users only)',
413 'api' => [
414 'duration' => 'infinite',
415 'flags' => [ 'anononly' ],
416 ],
417 ],
418 ],
419
420 // Legacy format
421 [
422 [
423 'type' => 'suppress',
424 'action' => 'reblock',
425 'comment' => 'Block comment',
426 'user' => 0,
427 'user_text' => 'Sysop',
428 'namespace' => NS_USER,
429 'title' => 'Logtestuser',
430 'params' => [
431 'infinite',
432 'anononly',
433 ],
434 ],
435 [
436 'legacy' => true,
437 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
438 . ' indefinite (anonymous users only)',
439 'api' => [
440 'duration' => 'infinite',
441 'flags' => [ 'anononly' ],
442 ],
443 ],
444 ],
445 ];
446 }
447
448 /**
449 * @dataProvider provideSuppressReblockLogDatabaseRows
450 */
451 public function testSuppressReblockLogDatabaseRows( $row, $extra ) {
452 $this->setMwGlobals(
453 'wgGroupPermissions',
454 [
455 'oversight' => [
456 'viewsuppressed' => true,
457 'suppressionlog' => true,
458 ],
459 ]
460 );
461 $this->doTestLogFormatter( $row, $extra, [ 'oversight' ] );
462 }
463
464 /**
465 * Provide different rows from the logging table to test
466 * for backward compatibility.
467 * Do not change the existing data, just add a new database row
468 */
469 public static function provideSuppressReblockLogDatabaseRowsNonPrivileged() {
470 return [
471 // Current log format
472 [
473 [
474 'type' => 'suppress',
475 'action' => 'reblock',
476 'comment' => 'Block comment',
477 'user' => 0,
478 'user_text' => 'Sysop',
479 'namespace' => NS_USER,
480 'title' => 'Logtestuser',
481 'params' => [
482 '5::duration' => 'infinite',
483 '6::flags' => 'anononly',
484 ],
485 ],
486 [
487 'text' => '(username removed) (log details removed)',
488 'api' => [
489 'duration' => 'infinite',
490 'flags' => [ 'anononly' ],
491 ],
492 ],
493 ],
494
495 // Legacy format
496 [
497 [
498 'type' => 'suppress',
499 'action' => 'reblock',
500 'comment' => 'Block comment',
501 'user' => 0,
502 'user_text' => 'Sysop',
503 'namespace' => NS_USER,
504 'title' => 'Logtestuser',
505 'params' => [
506 'infinite',
507 'anononly',
508 ],
509 ],
510 [
511 'legacy' => true,
512 'text' => '(username removed) (log details removed)',
513 'api' => [
514 'duration' => 'infinite',
515 'flags' => [ 'anononly' ],
516 ],
517 ],
518 ],
519 ];
520 }
521
522 /**
523 * @dataProvider provideSuppressReblockLogDatabaseRowsNonPrivileged
524 */
525 public function testSuppressReblockLogDatabaseRowsNonPrivileged( $row, $extra ) {
526 $this->user = $this->getTestUser()->getUser();
527 $this->doTestLogFormatter( $row, $extra );
528 }
529
530 public function providePartialBlockLogDatabaseRows() {
531 return [
532 [
533 [
534 'type' => 'block',
535 'action' => 'block',
536 'comment' => 'Block comment',
537 'user' => 0,
538 'user_text' => 'Sysop',
539 'namespace' => NS_USER,
540 'title' => 'Logtestuser',
541 'params' => [
542 '5::duration' => 'infinite',
543 '6::flags' => 'anononly',
544 '7::restrictions' => [ 'pages' => [ 'User:Test1', 'Main Page' ] ],
545 'sitewide' => false,
546 ],
547 ],
548 [
549 'text' => 'Sysop blocked Logtestuser from editing the pages User:Test1 and Main Page'
550 . ' with an expiration time of indefinite (anonymous users only)',
551 'api' => [
552 'duration' => 'infinite',
553 'flags' => [ 'anononly' ],
554 'restrictions' => [
555 'pages' => [
556 [
557 'page_ns' => 2,
558 'page_title' => 'User:Test1',
559 ], [
560 'page_ns' => 0,
561 'page_title' => 'Main Page',
562 ],
563 ],
564 ],
565 'sitewide' => false,
566 ],
567 ],
568 ],
569 [
570 [
571 'type' => 'block',
572 'action' => 'block',
573 'comment' => 'Block comment',
574 'user' => 0,
575 'user_text' => 'Sysop',
576 'namespace' => NS_USER,
577 'title' => 'Logtestuser',
578 'params' => [
579 '5::duration' => 'infinite',
580 '6::flags' => 'anononly',
581 '7::restrictions' => [
582 'namespaces' => [ NS_USER ],
583 ],
584 'sitewide' => false,
585 ],
586 ],
587 [
588 'text' => 'Sysop blocked Logtestuser from editing the namespace User'
589 . ' with an expiration time of indefinite (anonymous users only)',
590 'api' => [
591 'duration' => 'infinite',
592 'flags' => [ 'anononly' ],
593 'restrictions' => [
594 'namespaces' => [ NS_USER ],
595 ],
596 'sitewide' => false,
597 ],
598 ],
599 ],
600 [
601 [
602 'type' => 'block',
603 'action' => 'block',
604 'comment' => 'Block comment',
605 'user' => 0,
606 'user_text' => 'Sysop',
607 'namespace' => NS_USER,
608 'title' => 'Logtestuser',
609 'params' => [
610 '5::duration' => 'infinite',
611 '6::flags' => 'anononly',
612 '7::restrictions' => [
613 'pages' => [ 'Main Page' ],
614 'namespaces' => [ NS_USER, NS_MAIN ],
615 ],
616 'sitewide' => false,
617 ],
618 ],
619 [
620 'text' => 'Sysop blocked Logtestuser from editing the page Main Page and the'
621 . ' namespaces User and (Main) with an expiration time of indefinite'
622 . ' (anonymous users only)',
623 'api' => [
624 'duration' => 'infinite',
625 'flags' => [ 'anononly' ],
626 'restrictions' => [
627 'pages' => [
628 [
629 'page_ns' => 0,
630 'page_title' => 'Main Page',
631 ],
632 ],
633 'namespaces' => [ NS_USER, NS_MAIN ],
634 ],
635 'sitewide' => false,
636 ],
637 ],
638 ],
639 [
640 [
641 'type' => 'block',
642 'action' => 'block',
643 'comment' => 'Block comment',
644 'user' => 0,
645 'user_text' => 'Sysop',
646 'namespace' => NS_USER,
647 'title' => 'Logtestuser',
648 'params' => [
649 '5::duration' => 'infinite',
650 '6::flags' => 'anononly',
651 'sitewide' => false,
652 ],
653 ],
654 [
655 'text' => 'Sysop blocked Logtestuser from specified non-editing actions'
656 . ' with an expiration time of indefinite (anonymous users only)',
657 'api' => [
658 'duration' => 'infinite',
659 'flags' => [ 'anononly' ],
660 'sitewide' => false,
661 ],
662 ],
663 ],
664 ];
665 }
666
667 /**
668 * @dataProvider providePartialBlockLogDatabaseRows
669 */
670 public function testPartialBlockLogDatabaseRows( $row, $extra ) {
671 $this->doTestLogFormatter( $row, $extra );
672 }
673 }