Merge "Drop cache interwiki"
[mediawiki.git] / tests / phpunit / includes / logging / BlockLogFormatterTest.php
blob422575e4cb28e9800b7f8f1b3dc1ba09562fc68d
1 <?php
3 use MediaWiki\Title\TitleValue;
5 /**
6 * @covers \BlockLogFormatter
7 */
8 class BlockLogFormatterTest extends LogFormatterTestCase {
10 /**
11 * Provide different rows from the logging table to test
12 * for backward compatibility.
13 * Do not change the existing data, just add a new database row
15 public static function provideBlockLogDatabaseRows() {
16 return [
17 // Current log format
20 'type' => 'block',
21 'action' => 'block',
22 'comment' => 'Block comment',
23 'user' => 0,
24 'user_text' => 'Sysop',
25 'namespace' => NS_USER,
26 'title' => 'Logtestuser',
27 'params' => [
28 '5::duration' => 'infinity',
29 '6::flags' => 'anononly',
33 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
34 . ' (anonymous users only)',
35 'api' => [
36 'duration' => 'infinity',
37 'flags' => [ 'anononly' ],
39 'preload' => [ new TitleValue( NS_USER_TALK, 'Logtestuser' ) ],
43 // Old log format with one of the 4 values for 'infinity'
46 'type' => 'block',
47 'action' => 'block',
48 'comment' => 'Block comment',
49 'user' => 0,
50 'user_text' => 'Sysop',
51 'namespace' => NS_USER,
52 'title' => 'Logtestuser',
53 'params' => [
54 '5::duration' => 'infinite',
55 '6::flags' => 'anononly',
59 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
60 . ' (anonymous users only)',
61 'api' => [
62 'duration' => 'infinity',
63 'flags' => [ 'anononly' ],
65 'preload' => [ new TitleValue( NS_USER_TALK, 'Logtestuser' ) ],
69 // With blank page title (T224811)
72 'type' => 'block',
73 'action' => 'block',
74 'comment' => 'Block comment',
75 'user' => 0,
76 'user_text' => 'Sysop',
77 'namespace' => NS_USER,
78 'title' => '',
79 'params' => [],
82 'text' => 'Sysop blocked (no username available) '
83 . 'with an expiration time of indefinite',
84 'api' => [
85 'duration' => 'infinity',
86 'flags' => [],
88 'preload' => [],
92 // Old legacy log
95 'type' => 'block',
96 'action' => 'block',
97 'comment' => 'Block comment',
98 'user' => 0,
99 'user_text' => 'Sysop',
100 'namespace' => NS_USER,
101 'title' => 'Logtestuser',
102 'params' => [
103 'infinite',
104 'anononly',
108 'legacy' => true,
109 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
110 . ' (anonymous users only)',
111 'api' => [
112 'duration' => 'infinity',
113 'flags' => [ 'anononly' ],
118 // Old legacy log without flag
121 'type' => 'block',
122 'action' => 'block',
123 'comment' => 'Block comment',
124 'user' => 0,
125 'user_text' => 'Sysop',
126 'namespace' => NS_USER,
127 'title' => 'Logtestuser',
128 'params' => [
129 'infinite',
133 'legacy' => true,
134 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
135 'api' => [
136 'duration' => 'infinity',
137 'flags' => [],
142 // Very old legacy log without duration
145 'type' => 'block',
146 'action' => 'block',
147 'comment' => 'Block comment',
148 'user' => 0,
149 'user_text' => 'Sysop',
150 'namespace' => NS_USER,
151 'title' => 'Logtestuser',
152 'params' => [],
155 'legacy' => true,
156 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
157 'api' => [
158 'duration' => 'infinity',
159 'flags' => [],
167 * @dataProvider provideBlockLogDatabaseRows
169 public function testBlockLogDatabaseRows( $row, $extra ) {
170 $this->doTestLogFormatter( $row, $extra );
174 * Provide different rows from the logging table to test
175 * for backward compatibility.
176 * Do not change the existing data, just add a new database row
178 public static function provideReblockLogDatabaseRows() {
179 return [
180 // Current log format
183 'type' => 'block',
184 'action' => 'reblock',
185 'comment' => 'Block comment',
186 'user' => 0,
187 'user_text' => 'Sysop',
188 'namespace' => NS_USER,
189 'title' => 'Logtestuser',
190 'params' => [
191 '5::duration' => 'infinite',
192 '6::flags' => 'anononly',
196 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
197 . ' indefinite (anonymous users only)',
198 'api' => [
199 'duration' => 'infinity',
200 'flags' => [ 'anononly' ],
205 // Old log
208 'type' => 'block',
209 'action' => 'reblock',
210 'comment' => 'Block comment',
211 'user' => 0,
212 'user_text' => 'Sysop',
213 'namespace' => NS_USER,
214 'title' => 'Logtestuser',
215 'params' => [
216 'infinite',
217 'anononly',
221 'legacy' => true,
222 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
223 . ' indefinite (anonymous users only)',
224 'api' => [
225 'duration' => 'infinity',
226 'flags' => [ 'anononly' ],
231 // Older log without flag
234 'type' => 'block',
235 'action' => 'reblock',
236 'comment' => 'Block comment',
237 'user' => 0,
238 'user_text' => 'Sysop',
239 'namespace' => NS_USER,
240 'title' => 'Logtestuser',
241 'params' => [
242 'infinite',
246 'legacy' => true,
247 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of indefinite',
248 'api' => [
249 'duration' => 'infinity',
250 'flags' => [],
258 * @dataProvider provideReblockLogDatabaseRows
260 public function testReblockLogDatabaseRows( $row, $extra ) {
261 $this->doTestLogFormatter( $row, $extra );
265 * Provide different rows from the logging table to test
266 * for backward compatibility.
267 * Do not change the existing data, just add a new database row
269 public static function provideUnblockLogDatabaseRows() {
270 return [
271 // Current log format
274 'type' => 'block',
275 'action' => 'unblock',
276 'comment' => 'Block comment',
277 'user' => 0,
278 'user_text' => 'Sysop',
279 'namespace' => NS_USER,
280 'title' => 'Logtestuser',
281 'params' => [],
284 'text' => 'Sysop unblocked Logtestuser',
285 'api' => [],
292 * @dataProvider provideUnblockLogDatabaseRows
294 public function testUnblockLogDatabaseRows( $row, $extra ) {
295 $this->doTestLogFormatter( $row, $extra );
299 * Provide different rows from the logging table to test
300 * for backward compatibility.
301 * Do not change the existing data, just add a new database row
303 public static function provideSuppressBlockLogDatabaseRows() {
304 return [
305 // Current log format
308 'type' => 'suppress',
309 'action' => 'block',
310 'comment' => 'Block comment',
311 'user' => 0,
312 'user_text' => 'Sysop',
313 'namespace' => NS_USER,
314 'title' => 'Logtestuser',
315 'params' => [
316 '5::duration' => 'infinite',
317 '6::flags' => 'anononly',
321 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
322 . ' (anonymous users only)',
323 'api' => [
324 'duration' => 'infinity',
325 'flags' => [ 'anononly' ],
330 // legacy log
333 'type' => 'suppress',
334 'action' => 'block',
335 'comment' => 'Block comment',
336 'user' => 0,
337 'user_text' => 'Sysop',
338 'namespace' => NS_USER,
339 'title' => 'Logtestuser',
340 'params' => [
341 'infinite',
342 'anononly',
346 'legacy' => true,
347 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
348 . ' (anonymous users only)',
349 'api' => [
350 'duration' => 'infinity',
351 'flags' => [ 'anononly' ],
359 * Provide different rows from the logging table to test
360 * for backward compatibility.
361 * Do not change the existing data, just add a new database row
363 public static function provideSuppressBlockLogDatabaseRowsNonPrivileged() {
364 return [
365 // Current log format
368 'type' => 'suppress',
369 'action' => 'block',
370 'comment' => 'Block comment',
371 'user' => 0,
372 'user_text' => 'Sysop',
373 'namespace' => NS_USER,
374 'title' => 'Logtestuser',
375 'params' => [
376 '5::duration' => 'infinite',
377 '6::flags' => 'anononly',
381 'text' => '(username removed) (log details removed)',
382 'api' => [
383 'duration' => 'infinity',
384 'flags' => [ 'anononly' ],
389 // legacy log
392 'type' => 'suppress',
393 'action' => 'block',
394 'comment' => 'Block comment',
395 'user' => 0,
396 'user_text' => 'Sysop',
397 'namespace' => NS_USER,
398 'title' => 'Logtestuser',
399 'params' => [
400 'infinite',
401 'anononly',
405 'legacy' => true,
406 'text' => '(username removed) (log details removed)',
407 'api' => [
408 'duration' => 'infinity',
409 'flags' => [ 'anononly' ],
417 * @dataProvider provideSuppressBlockLogDatabaseRowsNonPrivileged
419 public function testSuppressBlockLogDatabaseRowsNonPrivileged( $row, $extra ) {
420 $this->doTestLogFormatter( $row, $extra );
424 * Provide different rows from the logging table to test
425 * for backward compatibility.
426 * Do not change the existing data, just add a new database row
428 public static function provideSuppressReblockLogDatabaseRows() {
429 return [
430 // Current log format
433 'type' => 'suppress',
434 'action' => 'reblock',
435 'comment' => 'Block comment',
436 'user' => 0,
437 'user_text' => 'Sysop',
438 'namespace' => NS_USER,
439 'title' => 'Logtestuser',
440 'params' => [
441 '5::duration' => 'infinite',
442 '6::flags' => 'anononly',
446 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
447 . ' indefinite (anonymous users only)',
448 'api' => [
449 'duration' => 'infinity',
450 'flags' => [ 'anononly' ],
455 // Legacy format
458 'type' => 'suppress',
459 'action' => 'reblock',
460 'comment' => 'Block comment',
461 'user' => 0,
462 'user_text' => 'Sysop',
463 'namespace' => NS_USER,
464 'title' => 'Logtestuser',
465 'params' => [
466 'infinite',
467 'anononly',
471 'legacy' => true,
472 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
473 . ' indefinite (anonymous users only)',
474 'api' => [
475 'duration' => 'infinity',
476 'flags' => [ 'anononly' ],
484 * @dataProvider provideSuppressBlockLogDatabaseRows
485 * @dataProvider provideSuppressReblockLogDatabaseRows
487 public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
488 $this->setGroupPermissions(
490 'oversight' => [
491 'viewsuppressed' => true,
492 'suppressionlog' => true,
496 $this->doTestLogFormatter( $row, $extra, [ 'oversight' ] );
500 * Provide different rows from the logging table to test
501 * for backward compatibility.
502 * Do not change the existing data, just add a new database row
504 public static function provideSuppressReblockLogDatabaseRowsNonPrivileged() {
505 return [
506 // Current log format
509 'type' => 'suppress',
510 'action' => 'reblock',
511 'comment' => 'Block comment',
512 'user' => 0,
513 'user_text' => 'Sysop',
514 'namespace' => NS_USER,
515 'title' => 'Logtestuser',
516 'params' => [
517 '5::duration' => 'infinite',
518 '6::flags' => 'anononly',
522 'text' => '(username removed) (log details removed)',
523 'api' => [
524 'duration' => 'infinity',
525 'flags' => [ 'anononly' ],
530 // Legacy format
533 'type' => 'suppress',
534 'action' => 'reblock',
535 'comment' => 'Block comment',
536 'user' => 0,
537 'user_text' => 'Sysop',
538 'namespace' => NS_USER,
539 'title' => 'Logtestuser',
540 'params' => [
541 'infinite',
542 'anononly',
546 'legacy' => true,
547 'text' => '(username removed) (log details removed)',
548 'api' => [
549 'duration' => 'infinity',
550 'flags' => [ 'anononly' ],
558 * @dataProvider provideSuppressReblockLogDatabaseRowsNonPrivileged
560 public function testSuppressReblockLogDatabaseRowsNonPrivileged( $row, $extra ) {
561 $this->doTestLogFormatter( $row, $extra );
564 public static function providePartialBlockLogDatabaseRows() {
565 return [
568 'type' => 'block',
569 'action' => 'block',
570 'comment' => 'Block comment',
571 'user' => 0,
572 'user_text' => 'Sysop',
573 'namespace' => NS_USER,
574 'title' => 'Logtestuser',
575 'params' => [
576 '5::duration' => 'infinite',
577 '6::flags' => 'anononly',
578 '7::restrictions' => [ 'pages' => [ 'User:Test1', 'Main Page' ] ],
579 'sitewide' => false,
583 'text' => 'Sysop blocked Logtestuser from the pages User:Test1 and Main Page'
584 . ' with an expiration time of indefinite (anonymous users only)',
585 'api' => [
586 'duration' => 'infinity',
587 'flags' => [ 'anononly' ],
588 'restrictions' => [
589 'pages' => [
591 'page_ns' => 2,
592 'page_title' => 'User:Test1',
593 ], [
594 'page_ns' => 0,
595 'page_title' => 'Main Page',
599 'sitewide' => false,
605 'type' => 'block',
606 'action' => 'block',
607 'comment' => 'Block comment',
608 'user' => 0,
609 'user_text' => 'Sysop',
610 'namespace' => NS_USER,
611 'title' => 'Logtestuser',
612 'params' => [
613 '5::duration' => 'infinite',
614 '6::flags' => 'anononly',
615 '7::restrictions' => [
616 'namespaces' => [ NS_USER ],
618 'sitewide' => false,
622 'text' => 'Sysop blocked Logtestuser from the namespace User'
623 . ' with an expiration time of indefinite (anonymous users only)',
624 'api' => [
625 'duration' => 'infinity',
626 'flags' => [ 'anononly' ],
627 'restrictions' => [
628 'namespaces' => [ NS_USER ],
630 'sitewide' => false,
636 'type' => 'block',
637 'action' => 'block',
638 'comment' => 'Block comment',
639 'user' => 0,
640 'user_text' => 'Sysop',
641 'namespace' => NS_USER,
642 'title' => 'Logtestuser',
643 'params' => [
644 '5::duration' => 'infinite',
645 '6::flags' => 'anononly',
646 '7::restrictions' => [
647 'pages' => [ 'Main Page' ],
648 'namespaces' => [ NS_USER, NS_MAIN ],
650 'sitewide' => false,
654 'text' => 'Sysop blocked Logtestuser from the page Main Page and the'
655 . ' namespaces User and (Main) with an expiration time of indefinite'
656 . ' (anonymous users only)',
657 'api' => [
658 'duration' => 'infinity',
659 'flags' => [ 'anononly' ],
660 'restrictions' => [
661 'pages' => [
663 'page_ns' => 0,
664 'page_title' => 'Main Page',
667 'namespaces' => [ NS_USER, NS_MAIN ],
669 'sitewide' => false,
675 'type' => 'block',
676 'action' => 'block',
677 'comment' => 'Block comment',
678 'user' => 0,
679 'user_text' => 'Sysop',
680 'namespace' => NS_USER,
681 'title' => 'Logtestuser',
682 'params' => [
683 '5::duration' => 'infinite',
684 '6::flags' => 'anononly',
685 'sitewide' => false,
689 'text' => 'Sysop blocked Logtestuser from specified non-editing actions'
690 . ' with an expiration time of indefinite (anonymous users only)',
691 'api' => [
692 'duration' => 'infinity',
693 'flags' => [ 'anononly' ],
694 'sitewide' => false,
702 * @dataProvider providePartialBlockLogDatabaseRows
704 public function testPartialBlockLogDatabaseRows( $row, $extra ) {
705 $this->doTestLogFormatter( $row, $extra );