MediaWiki  master
BlockLogFormatterTest.php
Go to the documentation of this file.
1 <?php
2 
7 
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  ],
38  ],
39 
40  // Old legacy log
41  [
42  [
43  'type' => 'block',
44  'action' => 'block',
45  'comment' => 'Block comment',
46  'user' => 0,
47  'user_text' => 'Sysop',
48  'namespace' => NS_USER,
49  'title' => 'Logtestuser',
50  'params' => [
51  'infinite',
52  'anononly',
53  ],
54  ],
55  [
56  'legacy' => true,
57  'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
58  . ' (anonymous users only)',
59  'api' => [
60  'duration' => 'infinite',
61  'flags' => [ 'anononly' ],
62  ],
63  ],
64  ],
65 
66  // Old legacy log without flag
67  [
68  [
69  'type' => 'block',
70  'action' => 'block',
71  'comment' => 'Block comment',
72  'user' => 0,
73  'user_text' => 'Sysop',
74  'namespace' => NS_USER,
75  'title' => 'Logtestuser',
76  'params' => [
77  'infinite',
78  ],
79  ],
80  [
81  'legacy' => true,
82  'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
83  'api' => [
84  'duration' => 'infinite',
85  'flags' => [],
86  ],
87  ],
88  ],
89 
90  // Very old legacy log without duration
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  ],
102  [
103  'legacy' => true,
104  'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
105  'api' => [
106  'duration' => 'infinite',
107  'flags' => [],
108  ],
109  ],
110  ],
111  ];
112  }
113 
117  public function testBlockLogDatabaseRows( $row, $extra ) {
118  $this->doTestLogFormatter( $row, $extra );
119  }
120 
126  public static function provideReblockLogDatabaseRows() {
127  return [
128  // Current log format
129  [
130  [
131  'type' => 'block',
132  'action' => 'reblock',
133  'comment' => 'Block comment',
134  'user' => 0,
135  'user_text' => 'Sysop',
136  'namespace' => NS_USER,
137  'title' => 'Logtestuser',
138  'params' => [
139  '5::duration' => 'infinite',
140  '6::flags' => 'anononly',
141  ],
142  ],
143  [
144  'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
145  . ' indefinite (anonymous users only)',
146  'api' => [
147  'duration' => 'infinite',
148  'flags' => [ 'anononly' ],
149  ],
150  ],
151  ],
152 
153  // Old log
154  [
155  [
156  'type' => 'block',
157  'action' => 'reblock',
158  'comment' => 'Block comment',
159  'user' => 0,
160  'user_text' => 'Sysop',
161  'namespace' => NS_USER,
162  'title' => 'Logtestuser',
163  'params' => [
164  'infinite',
165  'anononly',
166  ],
167  ],
168  [
169  'legacy' => true,
170  'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
171  . ' indefinite (anonymous users only)',
172  'api' => [
173  'duration' => 'infinite',
174  'flags' => [ 'anononly' ],
175  ],
176  ],
177  ],
178 
179  // Older log without flag
180  [
181  [
182  'type' => 'block',
183  'action' => 'reblock',
184  'comment' => 'Block comment',
185  'user' => 0,
186  'user_text' => 'Sysop',
187  'namespace' => NS_USER,
188  'title' => 'Logtestuser',
189  'params' => [
190  'infinite',
191  ]
192  ],
193  [
194  'legacy' => true,
195  'text' => 'Sysop changed block settings for Logtestuser with an expiration time of indefinite',
196  'api' => [
197  'duration' => 'infinite',
198  'flags' => [],
199  ],
200  ],
201  ],
202  ];
203  }
204 
208  public function testReblockLogDatabaseRows( $row, $extra ) {
209  $this->doTestLogFormatter( $row, $extra );
210  }
211 
217  public static function provideUnblockLogDatabaseRows() {
218  return [
219  // Current log format
220  [
221  [
222  'type' => 'block',
223  'action' => 'unblock',
224  'comment' => 'Block comment',
225  'user' => 0,
226  'user_text' => 'Sysop',
227  'namespace' => NS_USER,
228  'title' => 'Logtestuser',
229  'params' => [],
230  ],
231  [
232  'text' => 'Sysop unblocked Logtestuser',
233  'api' => [],
234  ],
235  ],
236  ];
237  }
238 
242  public function testUnblockLogDatabaseRows( $row, $extra ) {
243  $this->doTestLogFormatter( $row, $extra );
244  }
245 
251  public static function provideSuppressBlockLogDatabaseRows() {
252  return [
253  // Current log format
254  [
255  [
256  'type' => 'suppress',
257  'action' => 'block',
258  'comment' => 'Block comment',
259  'user' => 0,
260  'user_text' => 'Sysop',
261  'namespace' => NS_USER,
262  'title' => 'Logtestuser',
263  'params' => [
264  '5::duration' => 'infinite',
265  '6::flags' => 'anononly',
266  ],
267  ],
268  [
269  'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
270  . ' (anonymous users only)',
271  'api' => [
272  'duration' => 'infinite',
273  'flags' => [ 'anononly' ],
274  ],
275  ],
276  ],
277 
278  // legacy log
279  [
280  [
281  'type' => 'suppress',
282  'action' => 'block',
283  'comment' => 'Block comment',
284  'user' => 0,
285  'user_text' => 'Sysop',
286  'namespace' => NS_USER,
287  'title' => 'Logtestuser',
288  'params' => [
289  'infinite',
290  'anononly',
291  ],
292  ],
293  [
294  'legacy' => true,
295  'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
296  . ' (anonymous users only)',
297  'api' => [
298  'duration' => 'infinite',
299  'flags' => [ 'anononly' ],
300  ],
301  ],
302  ],
303  ];
304  }
305 
309  public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
310  $this->doTestLogFormatter( $row, $extra );
311  }
312 
318  public static function provideSuppressReblockLogDatabaseRows() {
319  return [
320  // Current log format
321  [
322  [
323  'type' => 'suppress',
324  'action' => 'reblock',
325  'comment' => 'Block comment',
326  'user' => 0,
327  'user_text' => 'Sysop',
328  'namespace' => NS_USER,
329  'title' => 'Logtestuser',
330  'params' => [
331  '5::duration' => 'infinite',
332  '6::flags' => 'anononly',
333  ],
334  ],
335  [
336  'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
337  . ' indefinite (anonymous users only)',
338  'api' => [
339  'duration' => 'infinite',
340  'flags' => [ 'anononly' ],
341  ],
342  ],
343  ],
344 
345  // Legacy format
346  [
347  [
348  'type' => 'suppress',
349  'action' => 'reblock',
350  'comment' => 'Block comment',
351  'user' => 0,
352  'user_text' => 'Sysop',
353  'namespace' => NS_USER,
354  'title' => 'Logtestuser',
355  'params' => [
356  'infinite',
357  'anononly',
358  ],
359  ],
360  [
361  'legacy' => true,
362  'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
363  . ' indefinite (anonymous users only)',
364  'api' => [
365  'duration' => 'infinite',
366  'flags' => [ 'anononly' ],
367  ],
368  ],
369  ],
370  ];
371  }
372 
376  public function testSuppressReblockLogDatabaseRows( $row, $extra ) {
377  $this->doTestLogFormatter( $row, $extra );
378  }
379 
381  return [
382  [
383  [
384  'type' => 'block',
385  'action' => 'block',
386  'comment' => 'Block comment',
387  'user' => 0,
388  'user_text' => 'Sysop',
389  'namespace' => NS_USER,
390  'title' => 'Logtestuser',
391  'params' => [
392  '5::duration' => 'infinite',
393  '6::flags' => 'anononly',
394  '7::restrictions' => [ 'pages' => [ 'User:Test1', 'Main Page' ] ],
395  'sitewide' => false,
396  ],
397  ],
398  [
399  'text' => 'Sysop blocked Logtestuser from editing the pages User:Test1 and Main Page'
400  . ' with an expiration time of indefinite (anonymous users only)',
401  'api' => [
402  'duration' => 'infinite',
403  'flags' => [ 'anononly' ],
404  'restrictions' => [
405  'pages' => [
406  [
407  'page_ns' => 2,
408  'page_title' => 'User:Test1',
409  ], [
410  'page_ns' => 0,
411  'page_title' => 'Main Page',
412  ],
413  ],
414  ],
415  'sitewide' => false,
416  ],
417  ],
418  ],
419  [
420  [
421  'type' => 'block',
422  'action' => 'block',
423  'comment' => 'Block comment',
424  'user' => 0,
425  'user_text' => 'Sysop',
426  'namespace' => NS_USER,
427  'title' => 'Logtestuser',
428  'params' => [
429  '5::duration' => 'infinite',
430  '6::flags' => 'anononly',
431  '7::restrictions' => [
432  'namespaces' => [ NS_USER ],
433  ],
434  'sitewide' => false,
435  ],
436  ],
437  [
438  'text' => 'Sysop blocked Logtestuser from editing the namespace User'
439  . ' with an expiration time of indefinite (anonymous users only)',
440  'api' => [
441  'duration' => 'infinite',
442  'flags' => [ 'anononly' ],
443  'restrictions' => [
444  'namespaces' => [ NS_USER ],
445  ],
446  'sitewide' => false,
447  ],
448  ],
449  ],
450  [
451  [
452  'type' => 'block',
453  'action' => 'block',
454  'comment' => 'Block comment',
455  'user' => 0,
456  'user_text' => 'Sysop',
457  'namespace' => NS_USER,
458  'title' => 'Logtestuser',
459  'params' => [
460  '5::duration' => 'infinite',
461  '6::flags' => 'anononly',
462  '7::restrictions' => [
463  'pages' => [ 'Main Page' ],
464  'namespaces' => [ NS_USER, NS_MAIN ],
465  ],
466  'sitewide' => false,
467  ],
468  ],
469  [
470  'text' => 'Sysop blocked Logtestuser from editing the page Main Page and the'
471  . ' namespaces User and (Main) with an expiration time of indefinite'
472  . ' (anonymous users only)',
473  'api' => [
474  'duration' => 'infinite',
475  'flags' => [ 'anononly' ],
476  'restrictions' => [
477  'pages' => [
478  [
479  'page_ns' => 0,
480  'page_title' => 'Main Page',
481  ],
482  ],
483  'namespaces' => [ NS_USER, NS_MAIN ],
484  ],
485  'sitewide' => false,
486  ],
487  ],
488  ],
489  [
490  [
491  'type' => 'block',
492  'action' => 'block',
493  'comment' => 'Block comment',
494  'user' => 0,
495  'user_text' => 'Sysop',
496  'namespace' => NS_USER,
497  'title' => 'Logtestuser',
498  'params' => [
499  '5::duration' => 'infinite',
500  '6::flags' => 'anononly',
501  'sitewide' => false,
502  ],
503  ],
504  [
505  'text' => 'Sysop blocked Logtestuser from specified non-editing actions'
506  . ' with an expiration time of indefinite (anonymous users only)',
507  'api' => [
508  'duration' => 'infinite',
509  'flags' => [ 'anononly' ],
510  'sitewide' => false,
511  ],
512  ],
513  ],
514  ];
515  }
516 
520  public function testPartialBlockLogDatabaseRows( $row, $extra ) {
521  $this->doTestLogFormatter( $row, $extra );
522  }
523 }
testPartialBlockLogDatabaseRows( $row, $extra)
providePartialBlockLogDatabaseRows
testReblockLogDatabaseRows( $row, $extra)
provideReblockLogDatabaseRows
const NS_MAIN
Definition: Defines.php:60
static provideUnblockLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility. ...
testUnblockLogDatabaseRows( $row, $extra)
provideUnblockLogDatabaseRows
testSuppressBlockLogDatabaseRows( $row, $extra)
provideSuppressBlockLogDatabaseRows
doTestLogFormatter( $row, $extra)
static provideBlockLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility. ...
static provideReblockLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility. ...
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
testSuppressReblockLogDatabaseRows( $row, $extra)
provideSuppressReblockLogDatabaseRows
testBlockLogDatabaseRows( $row, $extra)
provideBlockLogDatabaseRows
static provideSuppressBlockLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility. ...
static provideSuppressReblockLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility. ...