Remove hard deprecation of PasswordPolicyChecks::checkPopularPasswordBlacklist
[lhc/web/wiklou.git] / tests / phpunit / includes / logging / DeleteLogFormatterTest.php
1 <?php
2
3 /**
4 * @covers DeleteLogFormatter
5 */
6 class DeleteLogFormatterTest 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 provideDeleteLogDatabaseRows() {
14 return [
15 // Current format
16 [
17 [
18 'type' => 'delete',
19 'action' => 'delete',
20 'comment' => 'delete comment',
21 'namespace' => NS_MAIN,
22 'title' => 'Page',
23 'params' => [],
24 ],
25 [
26 'text' => 'User deleted page Page',
27 'api' => [],
28 ],
29 ],
30
31 // Legacy format
32 [
33 [
34 'type' => 'delete',
35 'action' => 'delete',
36 'comment' => 'delete comment',
37 'namespace' => NS_MAIN,
38 'title' => 'Page',
39 'params' => [],
40 ],
41 [
42 'legacy' => true,
43 'text' => 'User deleted page Page',
44 'api' => [],
45 ],
46 ],
47 ];
48 }
49
50 /**
51 * @dataProvider provideDeleteLogDatabaseRows
52 */
53 public function testDeleteLogDatabaseRows( $row, $extra ) {
54 $this->doTestLogFormatter( $row, $extra );
55 }
56
57 /**
58 * Provide different rows from the logging table to test
59 * for backward compatibility.
60 * Do not change the existing data, just add a new database row
61 */
62 public static function provideRestoreLogDatabaseRows() {
63 return [
64 // Current format
65 [
66 [
67 'type' => 'delete',
68 'action' => 'restore',
69 'comment' => 'delete comment',
70 'namespace' => NS_MAIN,
71 'title' => 'Page',
72 'params' => [
73 ':assoc:count' => [
74 'revisions' => 2,
75 'files' => 1,
76 ],
77 ],
78 ],
79 [
80 'text' => 'User restored page Page (2 revisions and 1 file)',
81 'api' => [
82 'count' => [
83 'revisions' => 2,
84 'files' => 1,
85 ],
86 ],
87 ],
88 ],
89
90 // Legacy format without counts
91 [
92 [
93 'type' => 'delete',
94 'action' => 'restore',
95 'comment' => 'delete comment',
96 'namespace' => NS_MAIN,
97 'title' => 'Page',
98 'params' => [],
99 ],
100 [
101 'text' => 'User restored page Page',
102 'api' => [],
103 ],
104 ],
105
106 // Legacy format
107 [
108 [
109 'type' => 'delete',
110 'action' => 'restore',
111 'comment' => 'delete comment',
112 'namespace' => NS_MAIN,
113 'title' => 'Page',
114 'params' => [],
115 ],
116 [
117 'legacy' => true,
118 'text' => 'User restored page Page',
119 'api' => [],
120 ],
121 ],
122 ];
123 }
124
125 /**
126 * @dataProvider provideRestoreLogDatabaseRows
127 */
128 public function testRestoreLogDatabaseRows( $row, $extra ) {
129 $this->doTestLogFormatter( $row, $extra );
130 }
131
132 /**
133 * Provide different rows from the logging table to test
134 * for backward compatibility.
135 * Do not change the existing data, just add a new database row
136 */
137 public static function provideRevisionLogDatabaseRows() {
138 return [
139 // Current format
140 [
141 [
142 'type' => 'delete',
143 'action' => 'revision',
144 'comment' => 'delete comment',
145 'namespace' => NS_MAIN,
146 'title' => 'Page',
147 'params' => [
148 '4::type' => 'archive',
149 '5::ids' => [ '1', '3', '4' ],
150 '6::ofield' => '1',
151 '7::nfield' => '2',
152 ],
153 ],
154 [
155 'text' => 'User changed visibility of 3 revisions on page Page: edit summary '
156 . 'hidden and content unhidden',
157 'api' => [
158 'type' => 'archive',
159 'ids' => [ '1', '3', '4' ],
160 'old' => [
161 'bitmask' => 1,
162 'content' => true,
163 'comment' => false,
164 'user' => false,
165 'restricted' => false,
166 ],
167 'new' => [
168 'bitmask' => 2,
169 'content' => false,
170 'comment' => true,
171 'user' => false,
172 'restricted' => false,
173 ],
174 ],
175 ],
176 ],
177
178 // Legacy format
179 [
180 [
181 'type' => 'delete',
182 'action' => 'revision',
183 'comment' => 'delete comment',
184 'namespace' => NS_MAIN,
185 'title' => 'Page',
186 'params' => [
187 'archive',
188 '1,3,4',
189 'ofield=1',
190 'nfield=2',
191 ],
192 ],
193 [
194 'legacy' => true,
195 'text' => 'User changed visibility of 3 revisions on page Page: edit summary '
196 . 'hidden and content unhidden',
197 'api' => [
198 'type' => 'archive',
199 'ids' => [ '1', '3', '4' ],
200 'old' => [
201 'bitmask' => 1,
202 'content' => true,
203 'comment' => false,
204 'user' => false,
205 'restricted' => false,
206 ],
207 'new' => [
208 'bitmask' => 2,
209 'content' => false,
210 'comment' => true,
211 'user' => false,
212 'restricted' => false,
213 ],
214 ],
215 ],
216 ],
217 ];
218 }
219
220 /**
221 * @dataProvider provideRevisionLogDatabaseRows
222 */
223 public function testRevisionLogDatabaseRows( $row, $extra ) {
224 $this->doTestLogFormatter( $row, $extra );
225 }
226
227 /**
228 * Provide different rows from the logging table to test
229 * for backward compatibility.
230 * Do not change the existing data, just add a new database row
231 */
232 public static function provideEventLogDatabaseRows() {
233 return [
234 // Current format
235 [
236 [
237 'type' => 'delete',
238 'action' => 'event',
239 'comment' => 'delete comment',
240 'namespace' => NS_MAIN,
241 'title' => 'Page',
242 'params' => [
243 '4::ids' => [ '1', '3', '4' ],
244 '5::ofield' => '1',
245 '6::nfield' => '2',
246 ],
247 ],
248 [
249 'text' => 'User changed visibility of 3 log events on Page: edit summary hidden '
250 . 'and content unhidden',
251 'api' => [
252 'type' => 'logging',
253 'ids' => [ '1', '3', '4' ],
254 'old' => [
255 'bitmask' => 1,
256 'content' => true,
257 'comment' => false,
258 'user' => false,
259 'restricted' => false,
260 ],
261 'new' => [
262 'bitmask' => 2,
263 'content' => false,
264 'comment' => true,
265 'user' => false,
266 'restricted' => false,
267 ],
268 ],
269 ],
270 ],
271
272 // Legacy format
273 [
274 [
275 'type' => 'delete',
276 'action' => 'event',
277 'comment' => 'delete comment',
278 'namespace' => NS_MAIN,
279 'title' => 'Page',
280 'params' => [
281 '1,3,4',
282 'ofield=1',
283 'nfield=2',
284 ],
285 ],
286 [
287 'legacy' => true,
288 'text' => 'User changed visibility of 3 log events on Page: edit summary hidden '
289 . 'and content unhidden',
290 'api' => [
291 'type' => 'logging',
292 'ids' => [ '1', '3', '4' ],
293 'old' => [
294 'bitmask' => 1,
295 'content' => true,
296 'comment' => false,
297 'user' => false,
298 'restricted' => false,
299 ],
300 'new' => [
301 'bitmask' => 2,
302 'content' => false,
303 'comment' => true,
304 'user' => false,
305 'restricted' => false,
306 ],
307 ],
308 ],
309 ],
310 ];
311 }
312
313 /**
314 * @dataProvider provideEventLogDatabaseRows
315 */
316 public function testEventLogDatabaseRows( $row, $extra ) {
317 $this->doTestLogFormatter( $row, $extra );
318 }
319
320 /**
321 * Provide different rows from the logging table to test
322 * for backward compatibility.
323 * Do not change the existing data, just add a new database row
324 */
325 public static function provideSuppressRevisionLogDatabaseRows() {
326 return [
327 // Current format
328 [
329 [
330 'type' => 'suppress',
331 'action' => 'revision',
332 'comment' => 'Suppress comment',
333 'namespace' => NS_MAIN,
334 'title' => 'Page',
335 'params' => [
336 '4::type' => 'archive',
337 '5::ids' => [ '1', '3', '4' ],
338 '6::ofield' => '1',
339 '7::nfield' => '10',
340 ],
341 ],
342 [
343 'text' => 'User secretly changed visibility of 3 revisions on page Page: edit '
344 . 'summary hidden, content unhidden and applied restrictions to administrators',
345 'api' => [
346 'type' => 'archive',
347 'ids' => [ '1', '3', '4' ],
348 'old' => [
349 'bitmask' => 1,
350 'content' => true,
351 'comment' => false,
352 'user' => false,
353 'restricted' => false,
354 ],
355 'new' => [
356 'bitmask' => 10,
357 'content' => false,
358 'comment' => true,
359 'user' => false,
360 'restricted' => true,
361 ],
362 ],
363 ],
364 ],
365
366 // Legacy format
367 [
368 [
369 'type' => 'suppress',
370 'action' => 'revision',
371 'comment' => 'Suppress comment',
372 'namespace' => NS_MAIN,
373 'title' => 'Page',
374 'params' => [
375 'archive',
376 '1,3,4',
377 'ofield=1',
378 'nfield=10',
379 ],
380 ],
381 [
382 'legacy' => true,
383 'text' => 'User secretly changed visibility of 3 revisions on page Page: edit '
384 . 'summary hidden, content unhidden and applied restrictions to administrators',
385 'api' => [
386 'type' => 'archive',
387 'ids' => [ '1', '3', '4' ],
388 'old' => [
389 'bitmask' => 1,
390 'content' => true,
391 'comment' => false,
392 'user' => false,
393 'restricted' => false,
394 ],
395 'new' => [
396 'bitmask' => 10,
397 'content' => false,
398 'comment' => true,
399 'user' => false,
400 'restricted' => true,
401 ],
402 ],
403 ],
404 ],
405 ];
406 }
407
408 /**
409 * @dataProvider provideSuppressRevisionLogDatabaseRows
410 */
411 public function testSuppressRevisionLogDatabaseRows( $row, $extra ) {
412 $this->setMwGlobals(
413 'wgGroupPermissions',
414 [
415 'oversight' => [
416 'viewsuppressed' => true,
417 'suppressionlog' => true,
418 ],
419 ]
420 );
421 $this->doTestLogFormatter( $row, $extra, [ 'oversight' ] );
422 }
423
424 /**
425 * Provide different rows from the logging table to test
426 * for backward compatibility.
427 * Do not change the existing data, just add a new database row
428 */
429 public static function provideSuppressRevisionLogDatabaseRowsNonPrivileged() {
430 return [
431 // Current format
432 [
433 [
434 'type' => 'suppress',
435 'action' => 'revision',
436 'comment' => 'Suppress comment',
437 'namespace' => NS_MAIN,
438 'title' => 'Page',
439 'params' => [
440 '4::type' => 'archive',
441 '5::ids' => [ '1', '3', '4' ],
442 '6::ofield' => '1',
443 '7::nfield' => '10',
444 ],
445 ],
446 [
447 'text' => '(username removed) (log details removed)',
448 'api' => [
449 'type' => 'archive',
450 'ids' => [ '1', '3', '4' ],
451 'old' => [
452 'bitmask' => 1,
453 'content' => true,
454 'comment' => false,
455 'user' => false,
456 'restricted' => false,
457 ],
458 'new' => [
459 'bitmask' => 10,
460 'content' => false,
461 'comment' => true,
462 'user' => false,
463 'restricted' => true,
464 ],
465 ],
466 ],
467 ],
468
469 // Legacy format
470 [
471 [
472 'type' => 'suppress',
473 'action' => 'revision',
474 'comment' => 'Suppress comment',
475 'namespace' => NS_MAIN,
476 'title' => 'Page',
477 'params' => [
478 'archive',
479 '1,3,4',
480 'ofield=1',
481 'nfield=10',
482 ],
483 ],
484 [
485 'legacy' => true,
486 'text' => '(username removed) (log details removed)',
487 'api' => [
488 'type' => 'archive',
489 'ids' => [ '1', '3', '4' ],
490 'old' => [
491 'bitmask' => 1,
492 'content' => true,
493 'comment' => false,
494 'user' => false,
495 'restricted' => false,
496 ],
497 'new' => [
498 'bitmask' => 10,
499 'content' => false,
500 'comment' => true,
501 'user' => false,
502 'restricted' => true,
503 ],
504 ],
505 ],
506 ],
507 ];
508 }
509
510 /**
511 * @dataProvider provideSuppressRevisionLogDatabaseRowsNonPrivileged
512 */
513 public function testSuppressRevisionLogDatabaseRowsNonPrivileged( $row, $extra ) {
514 $this->user = $this->getTestUser()->getUser();
515 $this->doTestLogFormatter( $row, $extra );
516 }
517
518 /**
519 * Provide different rows from the logging table to test
520 * for backward compatibility.
521 * Do not change the existing data, just add a new database row
522 */
523 public static function provideSuppressEventLogDatabaseRows() {
524 return [
525 // Current format
526 [
527 [
528 'type' => 'suppress',
529 'action' => 'event',
530 'comment' => 'Suppress comment',
531 'namespace' => NS_MAIN,
532 'title' => 'Page',
533 'params' => [
534 '4::ids' => [ '1', '3', '4' ],
535 '5::ofield' => '1',
536 '6::nfield' => '10',
537 ],
538 ],
539 [
540 'text' => 'User secretly changed visibility of 3 log events on Page: edit '
541 . 'summary hidden, content unhidden and applied restrictions to administrators',
542 'api' => [
543 'type' => 'logging',
544 'ids' => [ '1', '3', '4' ],
545 'old' => [
546 'bitmask' => 1,
547 'content' => true,
548 'comment' => false,
549 'user' => false,
550 'restricted' => false,
551 ],
552 'new' => [
553 'bitmask' => 10,
554 'content' => false,
555 'comment' => true,
556 'user' => false,
557 'restricted' => true,
558 ],
559 ],
560 ],
561 ],
562
563 // Legacy formats
564 [
565 [
566 'type' => 'suppress',
567 'action' => 'event',
568 'comment' => 'Suppress comment',
569 'namespace' => NS_MAIN,
570 'title' => 'Page',
571 'params' => [
572 '1,3,4',
573 'ofield=1',
574 'nfield=10',
575 ],
576 ],
577 [
578 'legacy' => true,
579 'text' => 'User secretly changed visibility of 3 log events on Page: edit '
580 . 'summary hidden, content unhidden and applied restrictions to administrators',
581 'api' => [
582 'type' => 'logging',
583 'ids' => [ '1', '3', '4' ],
584 'old' => [
585 'bitmask' => 1,
586 'content' => true,
587 'comment' => false,
588 'user' => false,
589 'restricted' => false,
590 ],
591 'new' => [
592 'bitmask' => 10,
593 'content' => false,
594 'comment' => true,
595 'user' => false,
596 'restricted' => true,
597 ],
598 ],
599 ],
600 ],
601 [
602 [
603 'type' => 'delete',
604 'action' => 'revision',
605 'comment' => 'Old rows might lack ofield/nfield (T224815)',
606 'namespace' => NS_MAIN,
607 'title' => 'Page',
608 'params' => [
609 'oldid',
610 '1234',
611 ],
612 ],
613 [
614 'legacy' => true,
615 'text' => 'User changed visibility of revisions on page Page',
616 'api' => [
617 'type' => 'oldid',
618 'ids' => [ '1234' ],
619 ],
620 ],
621 ]
622 ];
623 }
624
625 /**
626 * @dataProvider provideSuppressEventLogDatabaseRows
627 */
628 public function testSuppressEventLogDatabaseRows( $row, $extra ) {
629 $this->setMwGlobals(
630 'wgGroupPermissions',
631 [
632 'oversight' => [
633 'viewsuppressed' => true,
634 'suppressionlog' => true,
635 ],
636 ]
637 );
638 $this->doTestLogFormatter( $row, $extra, [ 'oversight' ] );
639 }
640
641 /**
642 * Provide different rows from the logging table to test
643 * for backward compatibility.
644 * Do not change the existing data, just add a new database row
645 */
646 public static function provideSuppressEventLogDatabaseRowsNonPrivileged() {
647 return [
648 // Current format
649 [
650 [
651 'type' => 'suppress',
652 'action' => 'event',
653 'comment' => 'Suppress comment',
654 'namespace' => NS_MAIN,
655 'title' => 'Page',
656 'params' => [
657 '4::ids' => [ '1', '3', '4' ],
658 '5::ofield' => '1',
659 '6::nfield' => '10',
660 ],
661 ],
662 [
663 'text' => '(username removed) (log details removed)',
664 'api' => [
665 'type' => 'logging',
666 'ids' => [ '1', '3', '4' ],
667 'old' => [
668 'bitmask' => 1,
669 'content' => true,
670 'comment' => false,
671 'user' => false,
672 'restricted' => false,
673 ],
674 'new' => [
675 'bitmask' => 10,
676 'content' => false,
677 'comment' => true,
678 'user' => false,
679 'restricted' => true,
680 ],
681 ],
682 ],
683 ],
684
685 // Legacy format
686 [
687 [
688 'type' => 'suppress',
689 'action' => 'event',
690 'comment' => 'Suppress comment',
691 'namespace' => NS_MAIN,
692 'title' => 'Page',
693 'params' => [
694 '1,3,4',
695 'ofield=1',
696 'nfield=10',
697 ],
698 ],
699 [
700 'legacy' => true,
701 'text' => '(username removed) (log details removed)',
702 'api' => [
703 'type' => 'logging',
704 'ids' => [ '1', '3', '4' ],
705 'old' => [
706 'bitmask' => 1,
707 'content' => true,
708 'comment' => false,
709 'user' => false,
710 'restricted' => false,
711 ],
712 'new' => [
713 'bitmask' => 10,
714 'content' => false,
715 'comment' => true,
716 'user' => false,
717 'restricted' => true,
718 ],
719 ],
720 ],
721 ],
722 ];
723 }
724
725 /**
726 * @dataProvider provideSuppressEventLogDatabaseRowsNonPrivileged
727 */
728 public function testSuppressEventLogDatabaseRowsNonPrivileged( $row, $extra ) {
729 $this->user = $this->getTestUser()->getUser();
730 $this->doTestLogFormatter( $row, $extra );
731 }
732
733 /**
734 * Provide different rows from the logging table to test
735 * for backward compatibility.
736 * Do not change the existing data, just add a new database row
737 */
738 public static function provideSuppressDeleteLogDatabaseRows() {
739 return [
740 // Current format
741 [
742 [
743 'type' => 'suppress',
744 'action' => 'delete',
745 'comment' => 'delete comment',
746 'namespace' => NS_MAIN,
747 'title' => 'Page',
748 'params' => [],
749 ],
750 [
751 'text' => 'User suppressed page Page',
752 'api' => [],
753 ],
754 ],
755
756 // Legacy format
757 [
758 [
759 'type' => 'suppress',
760 'action' => 'delete',
761 'comment' => 'delete comment',
762 'namespace' => NS_MAIN,
763 'title' => 'Page',
764 'params' => [],
765 ],
766 [
767 'legacy' => true,
768 'text' => 'User suppressed page Page',
769 'api' => [],
770 ],
771 ],
772 ];
773 }
774
775 /**
776 * @dataProvider provideSuppressDeleteLogDatabaseRows
777 */
778 public function testSuppressDeleteLogDatabaseRows( $row, $extra ) {
779 $this->setMwGlobals(
780 'wgGroupPermissions',
781 [
782 'oversight' => [
783 'viewsuppressed' => true,
784 'suppressionlog' => true,
785 ],
786 ]
787 );
788 $this->doTestLogFormatter( $row, $extra, [ 'oversight' ] );
789 }
790
791 /**
792 * Provide different rows from the logging table to test
793 * for backward compatibility.
794 * Do not change the existing data, just add a new database row
795 */
796 public static function provideSuppressDeleteLogDatabaseRowsNonPrivileged() {
797 return [
798 // Current format
799 [
800 [
801 'type' => 'suppress',
802 'action' => 'delete',
803 'comment' => 'delete comment',
804 'namespace' => NS_MAIN,
805 'title' => 'Page',
806 'params' => [],
807 ],
808 [
809 'text' => '(username removed) (log details removed)',
810 'api' => [],
811 ],
812 ],
813
814 // Legacy format
815 [
816 [
817 'type' => 'suppress',
818 'action' => 'delete',
819 'comment' => 'delete comment',
820 'namespace' => NS_MAIN,
821 'title' => 'Page',
822 'params' => [],
823 ],
824 [
825 'legacy' => true,
826 'text' => '(username removed) (log details removed)',
827 'api' => [],
828 ],
829 ],
830 ];
831 }
832
833 /**
834 * @dataProvider provideSuppressDeleteLogDatabaseRowsNonPrivileged
835 */
836 public function testSuppressDeleteLogDatabaseRowsNonPrivileged( $row, $extra ) {
837 $this->user = $this->getTestUser()->getUser();
838 $this->doTestLogFormatter( $row, $extra );
839 }
840 }