ecb4f34a83ef797a5ce85287ec2c03beb61cff12
[lhc/web/wiklou.git] / tests / phpunit / maintenance / MaintenanceTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Maintenance;
4
5 use MediaWiki\MediaWikiServices;
6 use MediaWikiTestCase;
7
8 /**
9 * @covers Maintenance
10 */
11 class MaintenanceTest extends MediaWikiTestCase {
12
13 /**
14 * The main Maintenance instance that is used for testing.
15 *
16 * @var MaintenanceFixup
17 */
18 private $m;
19
20 protected function setUp() {
21 parent::setUp();
22 $this->m = new MaintenanceFixup( $this );
23 }
24
25 protected function tearDown() {
26 if ( $this->m ) {
27 $this->m->simulateShutdown();
28 $this->m = null;
29 }
30 parent::tearDown();
31 }
32
33 /**
34 * asserts the output before and after simulating shutdown
35 *
36 * This function simulates shutdown of self::m.
37 *
38 * @param string $preShutdownOutput Expected output before simulating shutdown
39 * @param bool $expectNLAppending Whether or not shutdown simulation is expected
40 * to add a newline to the output. If false, $preShutdownOutput is the
41 * expected output after shutdown simulation. Otherwise,
42 * $preShutdownOutput with an appended newline is the expected output
43 * after shutdown simulation.
44 */
45 private function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
46 $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
47 "Output before shutdown simulation" );
48
49 $this->m->simulateShutdown();
50 $this->m = null;
51
52 $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ? "\n" : "" );
53 $this->expectOutputString( $postShutdownOutput );
54 }
55
56 // Although the following tests do not seem to be too consistent (compare for
57 // example the newlines within the test.*StringString tests, or the
58 // test.*Intermittent.* tests), the objective of these tests is not to describe
59 // consistent behavior, but rather currently existing behavior.
60
61 function testOutputEmpty() {
62 $this->m->output( "" );
63 $this->assertOutputPrePostShutdown( "", false );
64 }
65
66 function testOutputString() {
67 $this->m->output( "foo" );
68 $this->assertOutputPrePostShutdown( "foo", false );
69 }
70
71 function testOutputStringString() {
72 $this->m->output( "foo" );
73 $this->m->output( "bar" );
74 $this->assertOutputPrePostShutdown( "foobar", false );
75 }
76
77 function testOutputStringNL() {
78 $this->m->output( "foo\n" );
79 $this->assertOutputPrePostShutdown( "foo\n", false );
80 }
81
82 function testOutputStringNLNL() {
83 $this->m->output( "foo\n\n" );
84 $this->assertOutputPrePostShutdown( "foo\n\n", false );
85 }
86
87 function testOutputStringNLString() {
88 $this->m->output( "foo\nbar" );
89 $this->assertOutputPrePostShutdown( "foo\nbar", false );
90 }
91
92 function testOutputStringNLStringNL() {
93 $this->m->output( "foo\nbar\n" );
94 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
95 }
96
97 function testOutputStringNLStringNLLinewise() {
98 $this->m->output( "foo\n" );
99 $this->m->output( "bar\n" );
100 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
101 }
102
103 function testOutputStringNLStringNLArbitrary() {
104 $this->m->output( "" );
105 $this->m->output( "foo" );
106 $this->m->output( "" );
107 $this->m->output( "\n" );
108 $this->m->output( "ba" );
109 $this->m->output( "" );
110 $this->m->output( "r\n" );
111 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
112 }
113
114 function testOutputStringNLStringNLArbitraryAgain() {
115 $this->m->output( "" );
116 $this->m->output( "foo" );
117 $this->m->output( "" );
118 $this->m->output( "\nb" );
119 $this->m->output( "a" );
120 $this->m->output( "" );
121 $this->m->output( "r\n" );
122 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
123 }
124
125 function testOutputWNullChannelEmpty() {
126 $this->m->output( "", null );
127 $this->assertOutputPrePostShutdown( "", false );
128 }
129
130 function testOutputWNullChannelString() {
131 $this->m->output( "foo", null );
132 $this->assertOutputPrePostShutdown( "foo", false );
133 }
134
135 function testOutputWNullChannelStringString() {
136 $this->m->output( "foo", null );
137 $this->m->output( "bar", null );
138 $this->assertOutputPrePostShutdown( "foobar", false );
139 }
140
141 function testOutputWNullChannelStringNL() {
142 $this->m->output( "foo\n", null );
143 $this->assertOutputPrePostShutdown( "foo\n", false );
144 }
145
146 function testOutputWNullChannelStringNLNL() {
147 $this->m->output( "foo\n\n", null );
148 $this->assertOutputPrePostShutdown( "foo\n\n", false );
149 }
150
151 function testOutputWNullChannelStringNLString() {
152 $this->m->output( "foo\nbar", null );
153 $this->assertOutputPrePostShutdown( "foo\nbar", false );
154 }
155
156 function testOutputWNullChannelStringNLStringNL() {
157 $this->m->output( "foo\nbar\n", null );
158 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
159 }
160
161 function testOutputWNullChannelStringNLStringNLLinewise() {
162 $this->m->output( "foo\n", null );
163 $this->m->output( "bar\n", null );
164 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
165 }
166
167 function testOutputWNullChannelStringNLStringNLArbitrary() {
168 $this->m->output( "", null );
169 $this->m->output( "foo", null );
170 $this->m->output( "", null );
171 $this->m->output( "\n", null );
172 $this->m->output( "ba", null );
173 $this->m->output( "", null );
174 $this->m->output( "r\n", null );
175 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
176 }
177
178 function testOutputWNullChannelStringNLStringNLArbitraryAgain() {
179 $this->m->output( "", null );
180 $this->m->output( "foo", null );
181 $this->m->output( "", null );
182 $this->m->output( "\nb", null );
183 $this->m->output( "a", null );
184 $this->m->output( "", null );
185 $this->m->output( "r\n", null );
186 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
187 }
188
189 function testOutputWChannelString() {
190 $this->m->output( "foo", "bazChannel" );
191 $this->assertOutputPrePostShutdown( "foo", true );
192 }
193
194 function testOutputWChannelStringNL() {
195 $this->m->output( "foo\n", "bazChannel" );
196 $this->assertOutputPrePostShutdown( "foo", true );
197 }
198
199 function testOutputWChannelStringNLNL() {
200 // If this test fails, note that output takes strings with double line
201 // endings (although output's implementation in this situation calls
202 // outputChanneled with a string ending in a nl ... which is not allowed
203 // according to the documentation of outputChanneled)
204 $this->m->output( "foo\n\n", "bazChannel" );
205 $this->assertOutputPrePostShutdown( "foo\n", true );
206 }
207
208 function testOutputWChannelStringNLString() {
209 $this->m->output( "foo\nbar", "bazChannel" );
210 $this->assertOutputPrePostShutdown( "foo\nbar", true );
211 }
212
213 function testOutputWChannelStringNLStringNL() {
214 $this->m->output( "foo\nbar\n", "bazChannel" );
215 $this->assertOutputPrePostShutdown( "foo\nbar", true );
216 }
217
218 function testOutputWChannelStringNLStringNLLinewise() {
219 $this->m->output( "foo\n", "bazChannel" );
220 $this->m->output( "bar\n", "bazChannel" );
221 $this->assertOutputPrePostShutdown( "foobar", true );
222 }
223
224 function testOutputWChannelStringNLStringNLArbitrary() {
225 $this->m->output( "", "bazChannel" );
226 $this->m->output( "foo", "bazChannel" );
227 $this->m->output( "", "bazChannel" );
228 $this->m->output( "\n", "bazChannel" );
229 $this->m->output( "ba", "bazChannel" );
230 $this->m->output( "", "bazChannel" );
231 $this->m->output( "r\n", "bazChannel" );
232 $this->assertOutputPrePostShutdown( "foobar", true );
233 }
234
235 function testOutputWChannelStringNLStringNLArbitraryAgain() {
236 $this->m->output( "", "bazChannel" );
237 $this->m->output( "foo", "bazChannel" );
238 $this->m->output( "", "bazChannel" );
239 $this->m->output( "\nb", "bazChannel" );
240 $this->m->output( "a", "bazChannel" );
241 $this->m->output( "", "bazChannel" );
242 $this->m->output( "r\n", "bazChannel" );
243 $this->assertOutputPrePostShutdown( "foo\nbar", true );
244 }
245
246 function testOutputWMultipleChannelsChannelChange() {
247 $this->m->output( "foo", "bazChannel" );
248 $this->m->output( "bar", "bazChannel" );
249 $this->m->output( "qux", "quuxChannel" );
250 $this->m->output( "corge", "bazChannel" );
251 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
252 }
253
254 function testOutputWMultipleChannelsChannelChangeNL() {
255 $this->m->output( "foo", "bazChannel" );
256 $this->m->output( "bar\n", "bazChannel" );
257 $this->m->output( "qux\n", "quuxChannel" );
258 $this->m->output( "corge", "bazChannel" );
259 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
260 }
261
262 function testOutputWAndWOChannelStringStartWO() {
263 $this->m->output( "foo" );
264 $this->m->output( "bar", "bazChannel" );
265 $this->m->output( "qux" );
266 $this->m->output( "quux", "bazChannel" );
267 $this->assertOutputPrePostShutdown( "foobar\nquxquux", true );
268 }
269
270 function testOutputWAndWOChannelStringStartW() {
271 $this->m->output( "foo", "bazChannel" );
272 $this->m->output( "bar" );
273 $this->m->output( "qux", "bazChannel" );
274 $this->m->output( "quux" );
275 $this->assertOutputPrePostShutdown( "foo\nbarqux\nquux", false );
276 }
277
278 function testOutputWChannelTypeSwitch() {
279 $this->m->output( "foo", 1 );
280 $this->m->output( "bar", 1.0 );
281 $this->assertOutputPrePostShutdown( "foo\nbar", true );
282 }
283
284 function testOutputIntermittentEmpty() {
285 $this->m->output( "foo" );
286 $this->m->output( "" );
287 $this->m->output( "bar" );
288 $this->assertOutputPrePostShutdown( "foobar", false );
289 }
290
291 function testOutputIntermittentFalse() {
292 $this->m->output( "foo" );
293 $this->m->output( false );
294 $this->m->output( "bar" );
295 $this->assertOutputPrePostShutdown( "foobar", false );
296 }
297
298 function testOutputIntermittentFalseAfterOtherChannel() {
299 $this->m->output( "qux", "quuxChannel" );
300 $this->m->output( "foo" );
301 $this->m->output( false );
302 $this->m->output( "bar" );
303 $this->assertOutputPrePostShutdown( "qux\nfoobar", false );
304 }
305
306 function testOutputWNullChannelIntermittentEmpty() {
307 $this->m->output( "foo", null );
308 $this->m->output( "", null );
309 $this->m->output( "bar", null );
310 $this->assertOutputPrePostShutdown( "foobar", false );
311 }
312
313 function testOutputWNullChannelIntermittentFalse() {
314 $this->m->output( "foo", null );
315 $this->m->output( false, null );
316 $this->m->output( "bar", null );
317 $this->assertOutputPrePostShutdown( "foobar", false );
318 }
319
320 function testOutputWChannelIntermittentEmpty() {
321 $this->m->output( "foo", "bazChannel" );
322 $this->m->output( "", "bazChannel" );
323 $this->m->output( "bar", "bazChannel" );
324 $this->assertOutputPrePostShutdown( "foobar", true );
325 }
326
327 function testOutputWChannelIntermittentFalse() {
328 $this->m->output( "foo", "bazChannel" );
329 $this->m->output( false, "bazChannel" );
330 $this->m->output( "bar", "bazChannel" );
331 $this->assertOutputPrePostShutdown( "foobar", true );
332 }
333
334 // Note that (per documentation) outputChanneled does take strings that end
335 // in \n, hence we do not test such strings.
336
337 function testOutputChanneledEmpty() {
338 $this->m->outputChanneled( "" );
339 $this->assertOutputPrePostShutdown( "\n", false );
340 }
341
342 function testOutputChanneledString() {
343 $this->m->outputChanneled( "foo" );
344 $this->assertOutputPrePostShutdown( "foo\n", false );
345 }
346
347 function testOutputChanneledStringString() {
348 $this->m->outputChanneled( "foo" );
349 $this->m->outputChanneled( "bar" );
350 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
351 }
352
353 function testOutputChanneledStringNLString() {
354 $this->m->outputChanneled( "foo\nbar" );
355 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
356 }
357
358 function testOutputChanneledStringNLStringNLArbitraryAgain() {
359 $this->m->outputChanneled( "" );
360 $this->m->outputChanneled( "foo" );
361 $this->m->outputChanneled( "" );
362 $this->m->outputChanneled( "\nb" );
363 $this->m->outputChanneled( "a" );
364 $this->m->outputChanneled( "" );
365 $this->m->outputChanneled( "r" );
366 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
367 }
368
369 function testOutputChanneledWNullChannelEmpty() {
370 $this->m->outputChanneled( "", null );
371 $this->assertOutputPrePostShutdown( "\n", false );
372 }
373
374 function testOutputChanneledWNullChannelString() {
375 $this->m->outputChanneled( "foo", null );
376 $this->assertOutputPrePostShutdown( "foo\n", false );
377 }
378
379 function testOutputChanneledWNullChannelStringString() {
380 $this->m->outputChanneled( "foo", null );
381 $this->m->outputChanneled( "bar", null );
382 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
383 }
384
385 function testOutputChanneledWNullChannelStringNLString() {
386 $this->m->outputChanneled( "foo\nbar", null );
387 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
388 }
389
390 function testOutputChanneledWNullChannelStringNLStringNLArbitraryAgain() {
391 $this->m->outputChanneled( "", null );
392 $this->m->outputChanneled( "foo", null );
393 $this->m->outputChanneled( "", null );
394 $this->m->outputChanneled( "\nb", null );
395 $this->m->outputChanneled( "a", null );
396 $this->m->outputChanneled( "", null );
397 $this->m->outputChanneled( "r", null );
398 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
399 }
400
401 function testOutputChanneledWChannelString() {
402 $this->m->outputChanneled( "foo", "bazChannel" );
403 $this->assertOutputPrePostShutdown( "foo", true );
404 }
405
406 function testOutputChanneledWChannelStringNLString() {
407 $this->m->outputChanneled( "foo\nbar", "bazChannel" );
408 $this->assertOutputPrePostShutdown( "foo\nbar", true );
409 }
410
411 function testOutputChanneledWChannelStringString() {
412 $this->m->outputChanneled( "foo", "bazChannel" );
413 $this->m->outputChanneled( "bar", "bazChannel" );
414 $this->assertOutputPrePostShutdown( "foobar", true );
415 }
416
417 function testOutputChanneledWChannelStringNLStringNLArbitraryAgain() {
418 $this->m->outputChanneled( "", "bazChannel" );
419 $this->m->outputChanneled( "foo", "bazChannel" );
420 $this->m->outputChanneled( "", "bazChannel" );
421 $this->m->outputChanneled( "\nb", "bazChannel" );
422 $this->m->outputChanneled( "a", "bazChannel" );
423 $this->m->outputChanneled( "", "bazChannel" );
424 $this->m->outputChanneled( "r", "bazChannel" );
425 $this->assertOutputPrePostShutdown( "foo\nbar", true );
426 }
427
428 function testOutputChanneledWMultipleChannelsChannelChange() {
429 $this->m->outputChanneled( "foo", "bazChannel" );
430 $this->m->outputChanneled( "bar", "bazChannel" );
431 $this->m->outputChanneled( "qux", "quuxChannel" );
432 $this->m->outputChanneled( "corge", "bazChannel" );
433 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
434 }
435
436 function testOutputChanneledWMultipleChannelsChannelChangeEnclosedNull() {
437 $this->m->outputChanneled( "foo", "bazChannel" );
438 $this->m->outputChanneled( "bar", null );
439 $this->m->outputChanneled( "qux", null );
440 $this->m->outputChanneled( "corge", "bazChannel" );
441 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
442 }
443
444 function testOutputChanneledWMultipleChannelsChannelAfterNullChange() {
445 $this->m->outputChanneled( "foo", "bazChannel" );
446 $this->m->outputChanneled( "bar", null );
447 $this->m->outputChanneled( "qux", null );
448 $this->m->outputChanneled( "corge", "quuxChannel" );
449 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
450 }
451
452 function testOutputChanneledWAndWOChannelStringStartWO() {
453 $this->m->outputChanneled( "foo" );
454 $this->m->outputChanneled( "bar", "bazChannel" );
455 $this->m->outputChanneled( "qux" );
456 $this->m->outputChanneled( "quux", "bazChannel" );
457 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux", true );
458 }
459
460 function testOutputChanneledWAndWOChannelStringStartW() {
461 $this->m->outputChanneled( "foo", "bazChannel" );
462 $this->m->outputChanneled( "bar" );
463 $this->m->outputChanneled( "qux", "bazChannel" );
464 $this->m->outputChanneled( "quux" );
465 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux\n", false );
466 }
467
468 function testOutputChanneledWChannelTypeSwitch() {
469 $this->m->outputChanneled( "foo", 1 );
470 $this->m->outputChanneled( "bar", 1.0 );
471 $this->assertOutputPrePostShutdown( "foo\nbar", true );
472 }
473
474 function testOutputChanneledWOChannelIntermittentEmpty() {
475 $this->m->outputChanneled( "foo" );
476 $this->m->outputChanneled( "" );
477 $this->m->outputChanneled( "bar" );
478 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
479 }
480
481 function testOutputChanneledWOChannelIntermittentFalse() {
482 $this->m->outputChanneled( "foo" );
483 $this->m->outputChanneled( false );
484 $this->m->outputChanneled( "bar" );
485 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
486 }
487
488 function testOutputChanneledWNullChannelIntermittentEmpty() {
489 $this->m->outputChanneled( "foo", null );
490 $this->m->outputChanneled( "", null );
491 $this->m->outputChanneled( "bar", null );
492 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
493 }
494
495 function testOutputChanneledWNullChannelIntermittentFalse() {
496 $this->m->outputChanneled( "foo", null );
497 $this->m->outputChanneled( false, null );
498 $this->m->outputChanneled( "bar", null );
499 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
500 }
501
502 function testOutputChanneledWChannelIntermittentEmpty() {
503 $this->m->outputChanneled( "foo", "bazChannel" );
504 $this->m->outputChanneled( "", "bazChannel" );
505 $this->m->outputChanneled( "bar", "bazChannel" );
506 $this->assertOutputPrePostShutdown( "foobar", true );
507 }
508
509 function testOutputChanneledWChannelIntermittentFalse() {
510 $this->m->outputChanneled( "foo", "bazChannel" );
511 $this->m->outputChanneled( false, "bazChannel" );
512 $this->m->outputChanneled( "bar", "bazChannel" );
513 $this->assertOutputPrePostShutdown( "foo\nbar", true );
514 }
515
516 function testCleanupChanneledClean() {
517 $this->m->cleanupChanneled();
518 $this->assertOutputPrePostShutdown( "", false );
519 }
520
521 function testCleanupChanneledAfterOutput() {
522 $this->m->output( "foo" );
523 $this->m->cleanupChanneled();
524 $this->assertOutputPrePostShutdown( "foo", false );
525 }
526
527 function testCleanupChanneledAfterOutputWNullChannel() {
528 $this->m->output( "foo", null );
529 $this->m->cleanupChanneled();
530 $this->assertOutputPrePostShutdown( "foo", false );
531 }
532
533 function testCleanupChanneledAfterOutputWChannel() {
534 $this->m->output( "foo", "bazChannel" );
535 $this->m->cleanupChanneled();
536 $this->assertOutputPrePostShutdown( "foo\n", false );
537 }
538
539 function testCleanupChanneledAfterNLOutput() {
540 $this->m->output( "foo\n" );
541 $this->m->cleanupChanneled();
542 $this->assertOutputPrePostShutdown( "foo\n", false );
543 }
544
545 function testCleanupChanneledAfterNLOutputWNullChannel() {
546 $this->m->output( "foo\n", null );
547 $this->m->cleanupChanneled();
548 $this->assertOutputPrePostShutdown( "foo\n", false );
549 }
550
551 function testCleanupChanneledAfterNLOutputWChannel() {
552 $this->m->output( "foo\n", "bazChannel" );
553 $this->m->cleanupChanneled();
554 $this->assertOutputPrePostShutdown( "foo\n", false );
555 }
556
557 function testCleanupChanneledAfterOutputChanneledWOChannel() {
558 $this->m->outputChanneled( "foo" );
559 $this->m->cleanupChanneled();
560 $this->assertOutputPrePostShutdown( "foo\n", false );
561 }
562
563 function testCleanupChanneledAfterOutputChanneledWNullChannel() {
564 $this->m->outputChanneled( "foo", null );
565 $this->m->cleanupChanneled();
566 $this->assertOutputPrePostShutdown( "foo\n", false );
567 }
568
569 function testCleanupChanneledAfterOutputChanneledWChannel() {
570 $this->m->outputChanneled( "foo", "bazChannel" );
571 $this->m->cleanupChanneled();
572 $this->assertOutputPrePostShutdown( "foo\n", false );
573 }
574
575 function testMultipleMaintenanceObjectsInteractionOutput() {
576 $m2 = new MaintenanceFixup( $this );
577
578 $this->m->output( "foo" );
579 $m2->output( "bar" );
580
581 $this->assertEquals( "foobar", $this->getActualOutput(),
582 "Output before shutdown simulation (m2)" );
583 $m2->simulateShutdown();
584 $this->assertOutputPrePostShutdown( "foobar", false );
585 }
586
587 function testMultipleMaintenanceObjectsInteractionOutputWNullChannel() {
588 $m2 = new MaintenanceFixup( $this );
589
590 $this->m->output( "foo", null );
591 $m2->output( "bar", null );
592
593 $this->assertEquals( "foobar", $this->getActualOutput(),
594 "Output before shutdown simulation (m2)" );
595 $m2->simulateShutdown();
596 $this->assertOutputPrePostShutdown( "foobar", false );
597 }
598
599 function testMultipleMaintenanceObjectsInteractionOutputWChannel() {
600 $m2 = new MaintenanceFixup( $this );
601
602 $this->m->output( "foo", "bazChannel" );
603 $m2->output( "bar", "bazChannel" );
604
605 $this->assertEquals( "foobar", $this->getActualOutput(),
606 "Output before shutdown simulation (m2)" );
607 $m2->simulateShutdown();
608 $this->assertOutputPrePostShutdown( "foobar\n", true );
609 }
610
611 function testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL() {
612 $m2 = new MaintenanceFixup( $this );
613
614 $this->m->output( "foo\n", null );
615 $m2->output( "bar\n", null );
616
617 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
618 "Output before shutdown simulation (m2)" );
619 $m2->simulateShutdown();
620 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
621 }
622
623 function testMultipleMaintenanceObjectsInteractionOutputWChannelNL() {
624 $m2 = new MaintenanceFixup( $this );
625
626 $this->m->output( "foo\n", "bazChannel" );
627 $m2->output( "bar\n", "bazChannel" );
628
629 $this->assertEquals( "foobar", $this->getActualOutput(),
630 "Output before shutdown simulation (m2)" );
631 $m2->simulateShutdown();
632 $this->assertOutputPrePostShutdown( "foobar\n", true );
633 }
634
635 function testMultipleMaintenanceObjectsInteractionOutputChanneled() {
636 $m2 = new MaintenanceFixup( $this );
637
638 $this->m->outputChanneled( "foo" );
639 $m2->outputChanneled( "bar" );
640
641 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
642 "Output before shutdown simulation (m2)" );
643 $m2->simulateShutdown();
644 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
645 }
646
647 function testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel() {
648 $m2 = new MaintenanceFixup( $this );
649
650 $this->m->outputChanneled( "foo", null );
651 $m2->outputChanneled( "bar", null );
652
653 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
654 "Output before shutdown simulation (m2)" );
655 $m2->simulateShutdown();
656 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
657 }
658
659 function testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel() {
660 $m2 = new MaintenanceFixup( $this );
661
662 $this->m->outputChanneled( "foo", "bazChannel" );
663 $m2->outputChanneled( "bar", "bazChannel" );
664
665 $this->assertEquals( "foobar", $this->getActualOutput(),
666 "Output before shutdown simulation (m2)" );
667 $m2->simulateShutdown();
668 $this->assertOutputPrePostShutdown( "foobar\n", true );
669 }
670
671 function testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel() {
672 $m2 = new MaintenanceFixup( $this );
673
674 $this->m->outputChanneled( "foo", "bazChannel" );
675 $m2->outputChanneled( "bar", "bazChannel" );
676
677 $this->assertEquals( "foobar", $this->getActualOutput(),
678 "Output before first cleanup" );
679 $this->m->cleanupChanneled();
680 $this->assertEquals( "foobar\n", $this->getActualOutput(),
681 "Output after first cleanup" );
682 $m2->cleanupChanneled();
683 $this->assertEquals( "foobar\n\n", $this->getActualOutput(),
684 "Output after second cleanup" );
685
686 $m2->simulateShutdown();
687 $this->assertOutputPrePostShutdown( "foobar\n\n", false );
688 }
689
690 /**
691 * @covers Maintenance::getConfig
692 */
693 public function testGetConfig() {
694 $this->assertInstanceOf( 'Config', $this->m->getConfig() );
695 $this->assertSame(
696 MediaWikiServices::getInstance()->getMainConfig(),
697 $this->m->getConfig()
698 );
699 }
700
701 /**
702 * @covers Maintenance::setConfig
703 */
704 public function testSetConfig() {
705 $conf = $this->createMock( 'Config' );
706 $this->m->setConfig( $conf );
707 $this->assertSame( $conf, $this->m->getConfig() );
708 }
709
710 function testParseArgs() {
711 $m2 = new MaintenanceFixup( $this );
712 // Create an option with an argument allowed to be specified multiple times
713 $m2->addOption( 'multi', 'This option does stuff', false, true, false, true );
714 $m2->loadWithArgv( [ '--multi', 'this1', '--multi', 'this2' ] );
715
716 $this->assertEquals( [ 'this1', 'this2' ], $m2->getOption( 'multi' ) );
717 $this->assertEquals( [ [ 'multi', 'this1' ], [ 'multi', 'this2' ] ],
718 $m2->orderedOptions );
719
720 $m2->simulateShutdown();
721
722 $m2 = new MaintenanceFixup( $this );
723
724 $m2->addOption( 'multi', 'This option does stuff', false, false, false, true );
725 $m2->loadWithArgv( [ '--multi', '--multi' ] );
726
727 $this->assertEquals( [ 1, 1 ], $m2->getOption( 'multi' ) );
728 $this->assertEquals( [ [ 'multi', 1 ], [ 'multi', 1 ] ], $m2->orderedOptions );
729
730 $m2->simulateShutdown();
731
732 $m2 = new MaintenanceFixup( $this );
733 // Create an option with an argument allowed to be specified multiple times
734 $m2->addOption( 'multi', 'This option doesn\'t actually support multiple occurrences' );
735 $m2->loadWithArgv( [ '--multi=yo' ] );
736
737 $this->assertEquals( 'yo', $m2->getOption( 'multi' ) );
738 $this->assertEquals( [ [ 'multi', 'yo' ] ], $m2->orderedOptions );
739
740 $m2->simulateShutdown();
741 }
742 }