Convert all array() syntax to []
[lhc/web/wiklou.git] / tests / phpunit / includes / logging / BlockLogFormatterTest.php
1 <?php
2
3 class BlockLogFormatterTest extends LogFormatterTestCase {
4
5 /**
6 * Provide different rows from the logging table to test
7 * for backward compatibility.
8 * Do not change the existing data, just add a new database row
9 */
10 public static function provideBlockLogDatabaseRows() {
11 return [
12 // Current log format
13 [
14 [
15 'type' => 'block',
16 'action' => 'block',
17 'comment' => 'Block comment',
18 'user' => 0,
19 'user_text' => 'Sysop',
20 'namespace' => NS_USER,
21 'title' => 'Logtestuser',
22 'params' => [
23 '5::duration' => 'infinite',
24 '6::flags' => 'anononly',
25 ],
26 ],
27 [
28 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
29 'api' => [
30 'duration' => 'infinite',
31 'flags' => [ 'anononly' ],
32 ],
33 ],
34 ],
35
36 // Old legacy log
37 [
38 [
39 'type' => 'block',
40 'action' => 'block',
41 'comment' => 'Block comment',
42 'user' => 0,
43 'user_text' => 'Sysop',
44 'namespace' => NS_USER,
45 'title' => 'Logtestuser',
46 'params' => [
47 'infinite',
48 'anononly',
49 ],
50 ],
51 [
52 'legacy' => true,
53 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
54 'api' => [
55 'duration' => 'infinite',
56 'flags' => [ 'anononly' ],
57 ],
58 ],
59 ],
60
61 // Old legacy log without flag
62 [
63 [
64 'type' => 'block',
65 'action' => 'block',
66 'comment' => 'Block comment',
67 'user' => 0,
68 'user_text' => 'Sysop',
69 'namespace' => NS_USER,
70 'title' => 'Logtestuser',
71 'params' => [
72 'infinite',
73 ],
74 ],
75 [
76 'legacy' => true,
77 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite',
78 'api' => [
79 'duration' => 'infinite',
80 'flags' => [],
81 ],
82 ],
83 ],
84
85 // Very old legacy log without duration
86 [
87 [
88 'type' => 'block',
89 'action' => 'block',
90 'comment' => 'Block comment',
91 'user' => 0,
92 'user_text' => 'Sysop',
93 'namespace' => NS_USER,
94 'title' => 'Logtestuser',
95 'params' => [],
96 ],
97 [
98 'legacy' => true,
99 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite',
100 'api' => [
101 'duration' => 'infinite',
102 'flags' => [],
103 ],
104 ],
105 ],
106 ];
107 }
108
109 /**
110 * @dataProvider provideBlockLogDatabaseRows
111 */
112 public function testBlockLogDatabaseRows( $row, $extra ) {
113 $this->doTestLogFormatter( $row, $extra );
114 }
115
116 /**
117 * Provide different rows from the logging table to test
118 * for backward compatibility.
119 * Do not change the existing data, just add a new database row
120 */
121 public static function provideReblockLogDatabaseRows() {
122 return [
123 // Current log format
124 [
125 [
126 'type' => 'block',
127 'action' => 'reblock',
128 'comment' => 'Block comment',
129 'user' => 0,
130 'user_text' => 'Sysop',
131 'namespace' => NS_USER,
132 'title' => 'Logtestuser',
133 'params' => [
134 '5::duration' => 'infinite',
135 '6::flags' => 'anononly',
136 ],
137 ],
138 [
139 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
140 . ' indefinite (anonymous users only)',
141 'api' => [
142 'duration' => 'infinite',
143 'flags' => [ 'anononly' ],
144 ],
145 ],
146 ],
147
148 // Old log
149 [
150 [
151 'type' => 'block',
152 'action' => 'reblock',
153 'comment' => 'Block comment',
154 'user' => 0,
155 'user_text' => 'Sysop',
156 'namespace' => NS_USER,
157 'title' => 'Logtestuser',
158 'params' => [
159 'infinite',
160 'anononly',
161 ],
162 ],
163 [
164 'legacy' => true,
165 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
166 . ' indefinite (anonymous users only)',
167 'api' => [
168 'duration' => 'infinite',
169 'flags' => [ 'anononly' ],
170 ],
171 ],
172 ],
173
174 // Older log without flag
175 [
176 [
177 'type' => 'block',
178 'action' => 'reblock',
179 'comment' => 'Block comment',
180 'user' => 0,
181 'user_text' => 'Sysop',
182 'namespace' => NS_USER,
183 'title' => 'Logtestuser',
184 'params' => [
185 'infinite',
186 ]
187 ],
188 [
189 'legacy' => true,
190 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of indefinite',
191 'api' => [
192 'duration' => 'infinite',
193 'flags' => [],
194 ],
195 ],
196 ],
197 ];
198 }
199
200 /**
201 * @dataProvider provideReblockLogDatabaseRows
202 */
203 public function testReblockLogDatabaseRows( $row, $extra ) {
204 $this->doTestLogFormatter( $row, $extra );
205 }
206
207 /**
208 * Provide different rows from the logging table to test
209 * for backward compatibility.
210 * Do not change the existing data, just add a new database row
211 */
212 public static function provideUnblockLogDatabaseRows() {
213 return [
214 // Current log format
215 [
216 [
217 'type' => 'block',
218 'action' => 'unblock',
219 'comment' => 'Block comment',
220 'user' => 0,
221 'user_text' => 'Sysop',
222 'namespace' => NS_USER,
223 'title' => 'Logtestuser',
224 'params' => [],
225 ],
226 [
227 'text' => 'Sysop unblocked Logtestuser',
228 'api' => [],
229 ],
230 ],
231 ];
232 }
233
234 /**
235 * @dataProvider provideUnblockLogDatabaseRows
236 */
237 public function testUnblockLogDatabaseRows( $row, $extra ) {
238 $this->doTestLogFormatter( $row, $extra );
239 }
240
241 /**
242 * Provide different rows from the logging table to test
243 * for backward compatibility.
244 * Do not change the existing data, just add a new database row
245 */
246 public static function provideSuppressBlockLogDatabaseRows() {
247 return [
248 // Current log format
249 [
250 [
251 'type' => 'suppress',
252 'action' => 'block',
253 'comment' => 'Block comment',
254 'user' => 0,
255 'user_text' => 'Sysop',
256 'namespace' => NS_USER,
257 'title' => 'Logtestuser',
258 'params' => [
259 '5::duration' => 'infinite',
260 '6::flags' => 'anononly',
261 ],
262 ],
263 [
264 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
265 'api' => [
266 'duration' => 'infinite',
267 'flags' => [ 'anononly' ],
268 ],
269 ],
270 ],
271
272 // legacy log
273 [
274 [
275 'type' => 'suppress',
276 'action' => 'block',
277 'comment' => 'Block comment',
278 'user' => 0,
279 'user_text' => 'Sysop',
280 'namespace' => NS_USER,
281 'title' => 'Logtestuser',
282 'params' => [
283 'infinite',
284 'anononly',
285 ],
286 ],
287 [
288 'legacy' => true,
289 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
290 'api' => [
291 'duration' => 'infinite',
292 'flags' => [ 'anononly' ],
293 ],
294 ],
295 ],
296 ];
297 }
298
299 /**
300 * @dataProvider provideSuppressBlockLogDatabaseRows
301 */
302 public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
303 $this->doTestLogFormatter( $row, $extra );
304 }
305
306 /**
307 * Provide different rows from the logging table to test
308 * for backward compatibility.
309 * Do not change the existing data, just add a new database row
310 */
311 public static function provideSuppressReblockLogDatabaseRows() {
312 return [
313 // Current log format
314 [
315 [
316 'type' => 'suppress',
317 'action' => 'reblock',
318 'comment' => 'Block comment',
319 'user' => 0,
320 'user_text' => 'Sysop',
321 'namespace' => NS_USER,
322 'title' => 'Logtestuser',
323 'params' => [
324 '5::duration' => 'infinite',
325 '6::flags' => 'anononly',
326 ],
327 ],
328 [
329 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
330 . ' indefinite (anonymous users only)',
331 'api' => [
332 'duration' => 'infinite',
333 'flags' => [ 'anononly' ],
334 ],
335 ],
336 ],
337
338 // Legacy format
339 [
340 [
341 'type' => 'suppress',
342 'action' => 'reblock',
343 'comment' => 'Block comment',
344 'user' => 0,
345 'user_text' => 'Sysop',
346 'namespace' => NS_USER,
347 'title' => 'Logtestuser',
348 'params' => [
349 'infinite',
350 'anononly',
351 ],
352 ],
353 [
354 'legacy' => true,
355 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
356 . ' indefinite (anonymous users only)',
357 'api' => [
358 'duration' => 'infinite',
359 'flags' => [ 'anononly' ],
360 ],
361 ],
362 ],
363 ];
364 }
365
366 /**
367 * @dataProvider provideSuppressReblockLogDatabaseRows
368 */
369 public function testSuppressReblockLogDatabaseRows( $row, $extra ) {
370 $this->doTestLogFormatter( $row, $extra );
371 }
372 }