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