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