3 use MediaWiki\Title\TitleValue
;
6 * @covers \BlockLogFormatter
8 class BlockLogFormatterTest
extends LogFormatterTestCase
{
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() {
22 'comment' => 'Block comment',
24 'user_text' => 'Sysop',
25 'namespace' => NS_USER
,
26 'title' => 'Logtestuser',
28 '5::duration' => 'infinity',
29 '6::flags' => 'anononly',
33 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
34 . ' (anonymous users only)',
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'
48 'comment' => 'Block comment',
50 'user_text' => 'Sysop',
51 'namespace' => NS_USER
,
52 'title' => 'Logtestuser',
54 '5::duration' => 'infinite',
55 '6::flags' => 'anononly',
59 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
60 . ' (anonymous users only)',
62 'duration' => 'infinity',
63 'flags' => [ 'anononly' ],
65 'preload' => [ new TitleValue( NS_USER_TALK
, 'Logtestuser' ) ],
69 // With blank page title (T224811)
74 'comment' => 'Block comment',
76 'user_text' => 'Sysop',
77 'namespace' => NS_USER
,
82 'text' => 'Sysop blocked (no username available) '
83 . 'with an expiration time of indefinite',
85 'duration' => 'infinity',
97 'comment' => 'Block comment',
99 'user_text' => 'Sysop',
100 'namespace' => NS_USER
,
101 'title' => 'Logtestuser',
109 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
110 . ' (anonymous users only)',
112 'duration' => 'infinity',
113 'flags' => [ 'anononly' ],
118 // Old legacy log without flag
123 'comment' => 'Block comment',
125 'user_text' => 'Sysop',
126 'namespace' => NS_USER
,
127 'title' => 'Logtestuser',
134 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
136 'duration' => 'infinity',
142 // Very old legacy log without duration
147 'comment' => 'Block comment',
149 'user_text' => 'Sysop',
150 'namespace' => NS_USER
,
151 'title' => 'Logtestuser',
156 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
158 'duration' => 'infinity',
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() {
180 // Current log format
184 'action' => 'reblock',
185 'comment' => 'Block comment',
187 'user_text' => 'Sysop',
188 'namespace' => NS_USER
,
189 'title' => 'Logtestuser',
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)',
199 'duration' => 'infinity',
200 'flags' => [ 'anononly' ],
209 'action' => 'reblock',
210 'comment' => 'Block comment',
212 'user_text' => 'Sysop',
213 'namespace' => NS_USER
,
214 'title' => 'Logtestuser',
222 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
223 . ' indefinite (anonymous users only)',
225 'duration' => 'infinity',
226 'flags' => [ 'anononly' ],
231 // Older log without flag
235 'action' => 'reblock',
236 'comment' => 'Block comment',
238 'user_text' => 'Sysop',
239 'namespace' => NS_USER
,
240 'title' => 'Logtestuser',
247 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of indefinite',
249 'duration' => 'infinity',
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() {
271 // Current log format
275 'action' => 'unblock',
276 'comment' => 'Block comment',
278 'user_text' => 'Sysop',
279 'namespace' => NS_USER
,
280 'title' => 'Logtestuser',
284 'text' => 'Sysop unblocked Logtestuser',
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() {
305 // Current log format
308 'type' => 'suppress',
310 'comment' => 'Block comment',
312 'user_text' => 'Sysop',
313 'namespace' => NS_USER
,
314 'title' => 'Logtestuser',
316 '5::duration' => 'infinite',
317 '6::flags' => 'anononly',
321 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
322 . ' (anonymous users only)',
324 'duration' => 'infinity',
325 'flags' => [ 'anononly' ],
333 'type' => 'suppress',
335 'comment' => 'Block comment',
337 'user_text' => 'Sysop',
338 'namespace' => NS_USER
,
339 'title' => 'Logtestuser',
347 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
348 . ' (anonymous users only)',
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() {
365 // Current log format
368 'type' => 'suppress',
370 'comment' => 'Block comment',
372 'user_text' => 'Sysop',
373 'namespace' => NS_USER
,
374 'title' => 'Logtestuser',
376 '5::duration' => 'infinite',
377 '6::flags' => 'anononly',
381 'text' => '(username removed) (log details removed)',
383 'duration' => 'infinity',
384 'flags' => [ 'anononly' ],
392 'type' => 'suppress',
394 'comment' => 'Block comment',
396 'user_text' => 'Sysop',
397 'namespace' => NS_USER
,
398 'title' => 'Logtestuser',
406 'text' => '(username removed) (log details removed)',
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() {
430 // Current log format
433 'type' => 'suppress',
434 'action' => 'reblock',
435 'comment' => 'Block comment',
437 'user_text' => 'Sysop',
438 'namespace' => NS_USER
,
439 'title' => 'Logtestuser',
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)',
449 'duration' => 'infinity',
450 'flags' => [ 'anononly' ],
458 'type' => 'suppress',
459 'action' => 'reblock',
460 'comment' => 'Block comment',
462 'user_text' => 'Sysop',
463 'namespace' => NS_USER
,
464 'title' => 'Logtestuser',
472 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
473 . ' indefinite (anonymous users only)',
475 'duration' => 'infinity',
476 'flags' => [ 'anononly' ],
484 * @dataProvider provideSuppressBlockLogDatabaseRows
485 * @dataProvider provideSuppressReblockLogDatabaseRows
487 public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
488 $this->setGroupPermissions(
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() {
506 // Current log format
509 'type' => 'suppress',
510 'action' => 'reblock',
511 'comment' => 'Block comment',
513 'user_text' => 'Sysop',
514 'namespace' => NS_USER
,
515 'title' => 'Logtestuser',
517 '5::duration' => 'infinite',
518 '6::flags' => 'anononly',
522 'text' => '(username removed) (log details removed)',
524 'duration' => 'infinity',
525 'flags' => [ 'anononly' ],
533 'type' => 'suppress',
534 'action' => 'reblock',
535 'comment' => 'Block comment',
537 'user_text' => 'Sysop',
538 'namespace' => NS_USER
,
539 'title' => 'Logtestuser',
547 'text' => '(username removed) (log details removed)',
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() {
570 'comment' => 'Block comment',
572 'user_text' => 'Sysop',
573 'namespace' => NS_USER
,
574 'title' => 'Logtestuser',
576 '5::duration' => 'infinite',
577 '6::flags' => 'anononly',
578 '7::restrictions' => [ 'pages' => [ 'User:Test1', 'Main Page' ] ],
583 'text' => 'Sysop blocked Logtestuser from the pages User:Test1 and Main Page'
584 . ' with an expiration time of indefinite (anonymous users only)',
586 'duration' => 'infinity',
587 'flags' => [ 'anononly' ],
592 'page_title' => 'User:Test1',
595 'page_title' => 'Main Page',
607 'comment' => 'Block comment',
609 'user_text' => 'Sysop',
610 'namespace' => NS_USER
,
611 'title' => 'Logtestuser',
613 '5::duration' => 'infinite',
614 '6::flags' => 'anononly',
615 '7::restrictions' => [
616 'namespaces' => [ NS_USER
],
622 'text' => 'Sysop blocked Logtestuser from the namespace User'
623 . ' with an expiration time of indefinite (anonymous users only)',
625 'duration' => 'infinity',
626 'flags' => [ 'anononly' ],
628 'namespaces' => [ NS_USER
],
638 'comment' => 'Block comment',
640 'user_text' => 'Sysop',
641 'namespace' => NS_USER
,
642 'title' => 'Logtestuser',
644 '5::duration' => 'infinite',
645 '6::flags' => 'anononly',
646 '7::restrictions' => [
647 'pages' => [ 'Main Page' ],
648 'namespaces' => [ NS_USER
, NS_MAIN
],
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)',
658 'duration' => 'infinity',
659 'flags' => [ 'anononly' ],
664 'page_title' => 'Main Page',
667 'namespaces' => [ NS_USER
, NS_MAIN
],
677 'comment' => 'Block comment',
679 'user_text' => 'Sysop',
680 'namespace' => NS_USER
,
681 'title' => 'Logtestuser',
683 '5::duration' => 'infinite',
684 '6::flags' => 'anononly',
689 'text' => 'Sysop blocked Logtestuser from specified non-editing actions'
690 . ' with an expiration time of indefinite (anonymous users only)',
692 'duration' => 'infinity',
693 'flags' => [ 'anononly' ],
702 * @dataProvider providePartialBlockLogDatabaseRows
704 public function testPartialBlockLogDatabaseRows( $row, $extra ) {
705 $this->doTestLogFormatter( $row, $extra );