Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / logging / ProtectLogFormatterTest.php
blob8010b77383f877977887cf1ba138d74e5acde7a9
1 <?php
3 class ProtectLogFormatterTest extends LogFormatterTestCase {
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,
30 array(
31 'type' => 'move',
32 'level' => 'sysop',
33 'expiry' => 'infinity',
34 'cascade' => false,
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,
52 array(
53 'type' => 'move',
54 'level' => 'sysop',
55 'expiry' => 'infinite',
56 'cascade' => false,
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,
81 array(
82 'type' => 'move',
83 'level' => 'sysop',
84 'expiry' => 'infinity',
85 'cascade' => false,
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,
103 array(
104 'type' => 'move',
105 'level' => 'sysop',
106 'expiry' => 'infinite',
107 'cascade' => false,
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)',
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,
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',
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,
164 * @dataProvider provideProtectLogDatabaseRows
166 public function testProtectLogDatabaseRows( $row, $extra ) {
167 $this->doTestLogFormatter( $row, $extra );
171 * Provide different rows from the logging table to test
172 * for backward compatibility.
173 * Do not change the existing data, just add a new database row
175 public static function provideModifyLogDatabaseRows() {
176 return array(
177 // Current format
178 array(
179 array(
180 'type' => 'protect',
181 'action' => 'modify',
182 'comment' => 'protect comment',
183 'namespace' => NS_MAIN,
184 'title' => 'ProtectPage',
185 'params' => array(
186 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
187 '5:bool:cascade' => false,
188 'details' => array(
189 array(
190 'type' => 'edit',
191 'level' => 'sysop',
192 'expiry' => 'infinity',
193 'cascade' => false,
195 array(
196 'type' => 'move',
197 'level' => 'sysop',
198 'expiry' => 'infinity',
199 'cascade' => false,
204 array(
205 'text' => 'User changed protection level for ProtectPage ' .
206 '[Edit=Allow only administrators] ' .
207 '(indefinite) [Move=Allow only administrators] (indefinite)',
208 'api' => array(
209 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
210 'cascade' => false,
211 'details' => array(
212 array(
213 'type' => 'edit',
214 'level' => 'sysop',
215 'expiry' => 'infinite',
216 'cascade' => false,
218 array(
219 'type' => 'move',
220 'level' => 'sysop',
221 'expiry' => 'infinite',
222 'cascade' => false,
229 // Current format with cascade
230 array(
231 array(
232 'type' => 'protect',
233 'action' => 'modify',
234 'comment' => 'protect comment',
235 'namespace' => NS_MAIN,
236 'title' => 'ProtectPage',
237 'params' => array(
238 '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
239 '5:bool:cascade' => true,
240 'details' => array(
241 array(
242 'type' => 'edit',
243 'level' => 'sysop',
244 'expiry' => 'infinity',
245 'cascade' => true,
247 array(
248 'type' => 'move',
249 'level' => 'sysop',
250 'expiry' => 'infinity',
251 'cascade' => false,
256 array(
257 'text' => 'User changed protection level for ProtectPage ' .
258 '[Edit=Allow only administrators] (indefinite) ' .
259 '[Move=Allow only administrators] (indefinite) [cascading]',
260 'api' => array(
261 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
262 'cascade' => true,
263 'details' => array(
264 array(
265 'type' => 'edit',
266 'level' => 'sysop',
267 'expiry' => 'infinite',
268 'cascade' => true,
270 array(
271 'type' => 'move',
272 'level' => 'sysop',
273 'expiry' => 'infinite',
274 'cascade' => false,
281 // Legacy format
282 array(
283 array(
284 'type' => 'protect',
285 'action' => 'modify',
286 'comment' => 'protect comment',
287 'namespace' => NS_MAIN,
288 'title' => 'ProtectPage',
289 'params' => array(
290 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
294 array(
295 'legacy' => true,
296 'text' => 'User changed protection level for ProtectPage ' .
297 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
298 'api' => array(
299 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
300 'cascade' => false,
305 // Legacy format with cascade
306 array(
307 array(
308 'type' => 'protect',
309 'action' => 'modify',
310 'comment' => 'protect comment',
311 'namespace' => NS_MAIN,
312 'title' => 'ProtectPage',
313 'params' => array(
314 '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
315 'cascade',
318 array(
319 'legacy' => true,
320 'text' => 'User changed protection level for ProtectPage ' .
321 '[edit=sysop] (indefinite)[move=sysop] (indefinite) [cascading]',
322 'api' => array(
323 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
324 'cascade' => true,
332 * @dataProvider provideModifyLogDatabaseRows
334 public function testModifyLogDatabaseRows( $row, $extra ) {
335 $this->doTestLogFormatter( $row, $extra );
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
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(),
355 array(
356 'text' => 'User removed protection from ProtectPage',
357 'api' => array(),
364 * @dataProvider provideUnprotectLogDatabaseRows
366 public function testUnprotectLogDatabaseRows( $row, $extra ) {
367 $this->doTestLogFormatter( $row, $extra );
371 * Provide different rows from the logging table to test
372 * for backward compatibility.
373 * Do not change the existing data, just add a new database row
375 public static function provideMoveProtLogDatabaseRows() {
376 return array(
377 // Current format
378 array(
379 array(
380 'type' => 'protect',
381 'action' => 'move_prot',
382 'comment' => 'Move comment',
383 'namespace' => NS_MAIN,
384 'title' => 'NewPage',
385 'params' => array(
386 '4::oldtitle' => 'OldPage',
389 array(
390 'text' => 'User moved protection settings from OldPage to NewPage',
391 'api' => array(
392 'oldtitle_ns' => 0,
393 'oldtitle_title' => 'OldPage',
398 // Legacy format
399 array(
400 array(
401 'type' => 'protect',
402 'action' => 'move_prot',
403 'comment' => 'Move comment',
404 'namespace' => NS_MAIN,
405 'title' => 'NewPage',
406 'params' => array(
407 'OldPage',
410 array(
411 'legacy' => true,
412 'text' => 'User moved protection settings from OldPage to NewPage',
413 'api' => array(
414 'oldtitle_ns' => 0,
415 'oldtitle_title' => 'OldPage',
423 * @dataProvider provideMoveProtLogDatabaseRows
425 public function testMoveProtLogDatabaseRows( $row, $extra ) {
426 $this->doTestLogFormatter( $row, $extra );