Debian Codegraph @

tests/phpunit/includes/logging/BlockLogFormatterTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Title\TitleValue;
4
5 /**
6 * @covers \BlockLogFormatter
7 */
8 class BlockLogFormatterTest extends LogFormatterTestCase {
9
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
14 */
15 public static function provideBlockLogDatabaseRows() {
16 return [
17 // Current log format
18 [
19 [
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',
30 ],
31 ],
32 [
33 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
34 . ' (anonymous users only)',
35 'api' => [
36 'duration' => 'infinity',
37 'flags' => [ 'anononly' ],
38 ],
39 'preload' => [ new TitleValue( NS_USER_TALK, 'Logtestuser' ) ],
40 ],
41 ],
42
43 // Old log format with one of the 4 values for 'infinity'
44 [
45 [
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',
56 ],
57 ],
58 [
59 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
60 . ' (anonymous users only)',
61 'api' => [
62 'duration' => 'infinity',
63 'flags' => [ 'anononly' ],
64 ],
65 'preload' => [ new TitleValue( NS_USER_TALK, 'Logtestuser' ) ],
66 ],
67 ],
68
69 // With blank page title (T224811)
70 [
71 [
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' => [],
80 ],
81 [
82 'text' => 'Sysop blocked (no username available) '
83 . 'with an expiration time of indefinite',
84 'api' => [
85 'duration' => 'infinity',
86 'flags' => [],
87 ],
88 'preload' => [],
89 ],
90 ],
91
92 // Old legacy log
93 [
94 [
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',
105 ],
106 ],
107 [
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' ],
114 ],
115 ],
116 ],
117
118 // Old legacy log without flag
119 [
120 [
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',
130 ],
131 ],
132 [
133 'legacy' => true,
134 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
135 'api' => [
136 'duration' => 'infinity',
137 'flags' => [],
138 ],
139 ],
140 ],
141
142 // Very old legacy log without duration
143 [
144 [
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' => [],
153 ],
154 [
155 'legacy' => true,
156 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
157 'api' => [
158 'duration' => 'infinity',
159 'flags' => [],
160 ],
161 ],
162 ],
163 ];
164 }
165
166 /**
167 * @dataProvider provideBlockLogDatabaseRows
168 */
169 public function testBlockLogDatabaseRows( $row, $extra ) {
170 $this->doTestLogFormatter( $row, $extra );
171 }
172
173 /**
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
177 */
178 public static function provideReblockLogDatabaseRows() {
179 return [
180 // Current log format
181 [
182 [
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',
193 ],
194 ],
195 [
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' ],
201 ],
202 ],
203 ],
204
205 // Old log
206 [
207 [
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',
218 ],
219 ],
220 [
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' ],
227 ],
228 ],
229 ],
230
231 // Older log without flag
232 [
233 [
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',
243 ]
244 ],
245 [
246 'legacy' => true,
247 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of indefinite',
248 'api' => [
249 'duration' => 'infinity',
250 'flags' => [],
251 ],
252 ],
253 ],
254 ];
255 }
256
257 /**
258 * @dataProvider provideReblockLogDatabaseRows
259 */
260 public function testReblockLogDatabaseRows( $row, $extra ) {
261 $this->doTestLogFormatter( $row, $extra );
262 }
263
264 /**
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
268 */
269 public static function provideUnblockLogDatabaseRows() {
270 return [
271 // Current log format
272 [
273 [
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' => [],
282 ],
283 [
284 'text' => 'Sysop unblocked Logtestuser',
285 'api' => [],
286 ],
287 ],
288 ];
289 }
290
291 /**
292 * @dataProvider provideUnblockLogDatabaseRows
293 */
294 public function testUnblockLogDatabaseRows( $row, $extra ) {
295 $this->doTestLogFormatter( $row, $extra );
296 }
297
298 /**
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
302 */
303 public static function provideSuppressBlockLogDatabaseRows() {
304 return [
305 // Current log format
306 [
307 [
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',
318 ],
319 ],
320 [
321 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
322 . ' (anonymous users only)',
323 'api' => [
324 'duration' => 'infinity',
325 'flags' => [ 'anononly' ],
326 ],
327 ],
328 ],
329
330 // legacy log
331 [
332 [
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',
343 ],
344 ],
345 [
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' ],
352 ],
353 ],
354 ],
355 ];
356 }
357
358 /**
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
362 */
363 public static function provideSuppressBlockLogDatabaseRowsNonPrivileged() {
364 return [
365 // Current log format
366 [
367 [
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',
378 ],
379 ],
380 [
381 'text' => '(username removed) (log details removed)',
382 'api' => [
383 'duration' => 'infinity',
384 'flags' => [ 'anononly' ],
385 ],
386 ],
387 ],
388
389 // legacy log
390 [
391 [
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',
402 ],
403 ],
404 [
405 'legacy' => true,
406 'text' => '(username removed) (log details removed)',
407 'api' => [
408 'duration' => 'infinity',
409 'flags' => [ 'anononly' ],
410 ],
411 ],
412 ],
413 ];
414 }
415
416 /**
417 * @dataProvider provideSuppressBlockLogDatabaseRowsNonPrivileged
418 */
419 public function testSuppressBlockLogDatabaseRowsNonPrivileged( $row, $extra ) {
420 $this->doTestLogFormatter( $row, $extra );
421 }
422
423 /**
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
427 */
428 public static function provideSuppressReblockLogDatabaseRows() {
429 return [
430 // Current log format
431 [
432 [
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',
443 ],
444 ],
445 [
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' ],
451 ],
452 ],
453 ],
454
455 // Legacy format
456 [
457 [
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',
468 ],
469 ],
470 [
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' ],
477 ],
478 ],
479 ],
480 ];
481 }
482
483 /**
484 * @dataProvider provideSuppressBlockLogDatabaseRows
485 * @dataProvider provideSuppressReblockLogDatabaseRows
486 */
487 public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
488 $this->setGroupPermissions(
489 [
490 'oversight' => [
491 'viewsuppressed' => true,
492 'suppressionlog' => true,
493 ],
494 ]
495 );
496 $this->doTestLogFormatter( $row, $extra, [ 'oversight' ] );
497 }
498
499 /**
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
503 */
504 public static function provideSuppressReblockLogDatabaseRowsNonPrivileged() {
505 return [
506 // Current log format
507 [
508 [
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',
519 ],
520 ],
521 [
522 'text' => '(username removed) (log details removed)',
523 'api' => [
524 'duration' => 'infinity',
525 'flags' => [ 'anononly' ],
526 ],
527 ],
528 ],
529
530 // Legacy format
531 [
532 [
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',
543 ],
544 ],
545 [
546 'legacy' => true,
547 'text' => '(username removed) (log details removed)',
548 'api' => [
549 'duration' => 'infinity',
550 'flags' => [ 'anononly' ],
551 ],
552 ],
553 ],
554 ];
555 }
556
557 /**
558 * @dataProvider provideSuppressReblockLogDatabaseRowsNonPrivileged
559 */
560 public function testSuppressReblockLogDatabaseRowsNonPrivileged( $row, $extra ) {
561 $this->doTestLogFormatter( $row, $extra );
562 }
563
564 public static function providePartialBlockLogDatabaseRows() {
565 return [
566 [
567 [
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,
580 ],
581 ],
582 [
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' => [
590 [
591 'page_ns' => 2,
592 'page_title' => 'User:Test1',
593 ], [
594 'page_ns' => 0,
595 'page_title' => 'Main Page',
596 ],
597 ],
598 ],
599 'sitewide' => false,
600 ],
601 ],
602 ],
603 [
604 [
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 ],
617 ],
618 'sitewide' => false,
619 ],
620 ],
621 [
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 ],
629 ],
630 'sitewide' => false,
631 ],
632 ],
633 ],
634 [
635 [
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 ],
649 ],
650 'sitewide' => false,
651 ],
652 ],
653 [
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' => [
662 [
663 'page_ns' => 0,
664 'page_title' => 'Main Page',
665 ],
666 ],
667 'namespaces' => [ NS_USER, NS_MAIN ],
668 ],
669 'sitewide' => false,
670 ],
671 ],
672 ],
673 [
674 [
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,
686 ],
687 ],
688 [
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,
695 ],
696 ],
697 ],
698 ];
699 }
700
701 /**
702 * @dataProvider providePartialBlockLogDatabaseRows
703 */
704 public function testPartialBlockLogDatabaseRows( $row, $extra ) {
705 $this->doTestLogFormatter( $row, $extra );
706 }
707 }