Fix Generic.Files.LineLength phpcs check in files under phpunit/includes
[lhc/web/wiklou.git] / tests / phpunit / includes / logging / ProtectLogFormatterTest.php
1 <?php
2
3 class ProtectLogFormatterTest 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 provideProtectLogDatabaseRows() {
11 return array(
12 // Current format
13 array(
14 array(
15 'type' => 'protect',
16 'action' => 'protect',
17 'comment' => 'protect comment',
18 'namespace' => NS_MAIN,
19 'title' => 'ProtectPage',
20 'params' => array(
21 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
22 '5:bool:cascade' => false,
23 'details' => array(
24 array(
25 'type' => 'edit',
26 'level' => 'sysop',
27 'expiry' => 'infinity',
28 'cascade' => false,
29 ),
30 array(
31 'type' => 'move',
32 'level' => 'sysop',
33 'expiry' => 'infinity',
34 'cascade' => false,
35 ),
36 ),
37 ),
38 ),
39 array(
40 'text' => 'User protected ProtectPage [Edit=Allow only administrators] ' .
41 '(indefinite) [Move=Allow only administrators] (indefinite)',
42 'api' => array(
43 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
44 'cascade' => false,
45 'details' => array(
46 array(
47 'type' => 'edit',
48 'level' => 'sysop',
49 'expiry' => 'infinite',
50 'cascade' => false,
51 ),
52 array(
53 'type' => 'move',
54 'level' => 'sysop',
55 'expiry' => 'infinite',
56 'cascade' => false,
57 ),
58 ),
59 ),
60 ),
61 ),
62
63 // Current format with cascade
64 array(
65 array(
66 'type' => 'protect',
67 'action' => 'protect',
68 'comment' => 'protect comment',
69 'namespace' => NS_MAIN,
70 'title' => 'ProtectPage',
71 'params' => array(
72 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
73 '5:bool:cascade' => true,
74 'details' => array(
75 array(
76 'type' => 'edit',
77 'level' => 'sysop',
78 'expiry' => 'infinity',
79 'cascade' => true,
80 ),
81 array(
82 'type' => 'move',
83 'level' => 'sysop',
84 'expiry' => 'infinity',
85 'cascade' => false,
86 ),
87 ),
88 ),
89 ),
90 array(
91 'text' => 'User protected ProtectPage [Edit=Allow only administrators] ' .
92 '(indefinite) [Move=Allow only administrators] (indefinite) [cascading]',
93 'api' => array(
94 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
95 'cascade' => true,
96 'details' => array(
97 array(
98 'type' => 'edit',
99 'level' => 'sysop',
100 'expiry' => 'infinite',
101 'cascade' => true,
102 ),
103 array(
104 'type' => 'move',
105 'level' => 'sysop',
106 'expiry' => 'infinite',
107 'cascade' => false,
108 ),
109 ),
110 ),
111 ),
112 ),
113
114 // Legacy format
115 array(
116 array(
117 'type' => 'protect',
118 'action' => 'protect',
119 'comment' => 'protect comment',
120 'namespace' => NS_MAIN,
121 'title' => 'ProtectPage',
122 'params' => array(
123 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
124 '',
125 ),
126 ),
127 array(
128 'legacy' => true,
129 'text' => 'User protected ProtectPage [edit=sysop] (indefinite)[move=sysop] (indefinite)',
130 'api' => array(
131 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
132 'cascade' => false,
133 ),
134 ),
135 ),
136
137 // Legacy format with cascade
138 array(
139 array(
140 'type' => 'protect',
141 'action' => 'protect',
142 'comment' => 'protect comment',
143 'namespace' => NS_MAIN,
144 'title' => 'ProtectPage',
145 'params' => array(
146 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
147 'cascade',
148 ),
149 ),
150 array(
151 'legacy' => true,
152 'text' => 'User protected ProtectPage [edit=sysop] ' .
153 '(indefinite)[move=sysop] (indefinite) [cascading]',
154 'api' => array(
155 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
156 'cascade' => true,
157 ),
158 ),
159 ),
160 );
161 }
162
163
164 /**
165 * @dataProvider provideProtectLogDatabaseRows
166 */
167 public function testProtectLogDatabaseRows( $row, $extra ) {
168 $this->doTestLogFormatter( $row, $extra );
169 }
170
171 /**
172 * Provide different rows from the logging table to test
173 * for backward compatibility.
174 * Do not change the existing data, just add a new database row
175 */
176 public static function provideModifyLogDatabaseRows() {
177 return array(
178 // Current format
179 array(
180 array(
181 'type' => 'protect',
182 'action' => 'modify',
183 'comment' => 'protect comment',
184 'namespace' => NS_MAIN,
185 'title' => 'ProtectPage',
186 'params' => array(
187 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
188 '5:bool:cascade' => false,
189 'details' => array(
190 array(
191 'type' => 'edit',
192 'level' => 'sysop',
193 'expiry' => 'infinity',
194 'cascade' => false,
195 ),
196 array(
197 'type' => 'move',
198 'level' => 'sysop',
199 'expiry' => 'infinity',
200 'cascade' => false,
201 ),
202 ),
203 ),
204 ),
205 array(
206 'text' => 'User changed protection level for ProtectPage ' .
207 '[Edit=Allow only administrators] ' .
208 '(indefinite) [Move=Allow only administrators] (indefinite)',
209 'api' => array(
210 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
211 'cascade' => false,
212 'details' => array(
213 array(
214 'type' => 'edit',
215 'level' => 'sysop',
216 'expiry' => 'infinite',
217 'cascade' => false,
218 ),
219 array(
220 'type' => 'move',
221 'level' => 'sysop',
222 'expiry' => 'infinite',
223 'cascade' => false,
224 ),
225 ),
226 ),
227 ),
228 ),
229
230 // Current format with cascade
231 array(
232 array(
233 'type' => 'protect',
234 'action' => 'modify',
235 'comment' => 'protect comment',
236 'namespace' => NS_MAIN,
237 'title' => 'ProtectPage',
238 'params' => array(
239 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
240 '5:bool:cascade' => true,
241 'details' => array(
242 array(
243 'type' => 'edit',
244 'level' => 'sysop',
245 'expiry' => 'infinity',
246 'cascade' => true,
247 ),
248 array(
249 'type' => 'move',
250 'level' => 'sysop',
251 'expiry' => 'infinity',
252 'cascade' => false,
253 ),
254 ),
255 ),
256 ),
257 array(
258 'text' => 'User changed protection level for ProtectPage [Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [cascading]',
259 'api' => array(
260 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
261 'cascade' => true,
262 'details' => array(
263 array(
264 'type' => 'edit',
265 'level' => 'sysop',
266 'expiry' => 'infinite',
267 'cascade' => true,
268 ),
269 array(
270 'type' => 'move',
271 'level' => 'sysop',
272 'expiry' => 'infinite',
273 'cascade' => false,
274 ),
275 ),
276 ),
277 ),
278 ),
279
280 // Legacy format
281 array(
282 array(
283 'type' => 'protect',
284 'action' => 'modify',
285 'comment' => 'protect comment',
286 'namespace' => NS_MAIN,
287 'title' => 'ProtectPage',
288 'params' => array(
289 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
290 '',
291 ),
292 ),
293 array(
294 'legacy' => true,
295 'text' => 'User changed protection level for ProtectPage ' .
296 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
297 'api' => array(
298 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
299 'cascade' => false,
300 ),
301 ),
302 ),
303
304 // Legacy format with cascade
305 array(
306 array(
307 'type' => 'protect',
308 'action' => 'modify',
309 'comment' => 'protect comment',
310 'namespace' => NS_MAIN,
311 'title' => 'ProtectPage',
312 'params' => array(
313 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
314 'cascade',
315 ),
316 ),
317 array(
318 'legacy' => true,
319 'text' => 'User changed protection level for ProtectPage ' .
320 '[edit=sysop] (indefinite)[move=sysop] (indefinite) [cascading]',
321 'api' => array(
322 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
323 'cascade' => true,
324 ),
325 ),
326 ),
327 );
328 }
329
330
331 /**
332 * @dataProvider provideModifyLogDatabaseRows
333 */
334 public function testModifyLogDatabaseRows( $row, $extra ) {
335 $this->doTestLogFormatter( $row, $extra );
336 }
337
338 /**
339 * Provide different rows from the logging table to test
340 * for backward compatibility.
341 * Do not change the existing data, just add a new database row
342 */
343 public static function provideUnprotectLogDatabaseRows() {
344 return array(
345 // Current format
346 array(
347 array(
348 'type' => 'protect',
349 'action' => 'unprotect',
350 'comment' => 'unprotect comment',
351 'namespace' => NS_MAIN,
352 'title' => 'ProtectPage',
353 'params' => array(),
354 ),
355 array(
356 'text' => 'User removed protection from ProtectPage',
357 'api' => array(),
358 ),
359 ),
360 );
361 }
362
363
364 /**
365 * @dataProvider provideUnprotectLogDatabaseRows
366 */
367 public function testUnprotectLogDatabaseRows( $row, $extra ) {
368 $this->doTestLogFormatter( $row, $extra );
369 }
370
371 /**
372 * Provide different rows from the logging table to test
373 * for backward compatibility.
374 * Do not change the existing data, just add a new database row
375 */
376 public static function provideMoveProtLogDatabaseRows() {
377 return array(
378 // Current format
379 array(
380 array(
381 'type' => 'protect',
382 'action' => 'move_prot',
383 'comment' => 'Move comment',
384 'namespace' => NS_MAIN,
385 'title' => 'NewPage',
386 'params' => array(
387 '4::oldtitle' => 'OldPage',
388 ),
389 ),
390 array(
391 'text' => 'User moved protection settings from OldPage to NewPage',
392 'api' => array(
393 'oldtitle_ns' => 0,
394 'oldtitle_title' => 'OldPage',
395 ),
396 ),
397 ),
398
399 // Legacy format
400 array(
401 array(
402 'type' => 'protect',
403 'action' => 'move_prot',
404 'comment' => 'Move comment',
405 'namespace' => NS_MAIN,
406 'title' => 'NewPage',
407 'params' => array(
408 'OldPage',
409 ),
410 ),
411 array(
412 'legacy' => true,
413 'text' => 'User moved protection settings from OldPage to NewPage',
414 'api' => array(
415 'oldtitle_ns' => 0,
416 'oldtitle_title' => 'OldPage',
417 ),
418 ),
419 ),
420 );
421 }
422
423 /**
424 * @dataProvider provideMoveProtLogDatabaseRows
425 */
426 public function testMoveProtLogDatabaseRows( $row, $extra ) {
427 $this->doTestLogFormatter( $row, $extra );
428 }
429 }