3 namespace MediaWiki\Tests\Maintenance
;
5 use MediaWiki\MediaWikiServices
;
11 class MaintenanceTest
extends MediaWikiTestCase
{
14 * The main Maintenance instance that is used for testing.
16 * @var MaintenanceFixup
20 protected function setUp() {
22 $this->m
= new MaintenanceFixup( $this );
25 protected function tearDown() {
27 $this->m
->simulateShutdown();
34 * asserts the output before and after simulating shutdown
36 * This function simulates shutdown of self::m.
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.
45 private function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
46 $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
47 "Output before shutdown simulation" );
49 $this->m
->simulateShutdown();
52 $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ?
"\n" : "" );
53 $this->expectOutputString( $postShutdownOutput );
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.
61 function testOutputEmpty() {
62 $this->m
->output( "" );
63 $this->assertOutputPrePostShutdown( "", false );
66 function testOutputString() {
67 $this->m
->output( "foo" );
68 $this->assertOutputPrePostShutdown( "foo", false );
71 function testOutputStringString() {
72 $this->m
->output( "foo" );
73 $this->m
->output( "bar" );
74 $this->assertOutputPrePostShutdown( "foobar", false );
77 function testOutputStringNL() {
78 $this->m
->output( "foo\n" );
79 $this->assertOutputPrePostShutdown( "foo\n", false );
82 function testOutputStringNLNL() {
83 $this->m
->output( "foo\n\n" );
84 $this->assertOutputPrePostShutdown( "foo\n\n", false );
87 function testOutputStringNLString() {
88 $this->m
->output( "foo\nbar" );
89 $this->assertOutputPrePostShutdown( "foo\nbar", false );
92 function testOutputStringNLStringNL() {
93 $this->m
->output( "foo\nbar\n" );
94 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
97 function testOutputStringNLStringNLLinewise() {
98 $this->m
->output( "foo\n" );
99 $this->m
->output( "bar\n" );
100 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
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 );
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 );
125 function testOutputWNullChannelEmpty() {
126 $this->m
->output( "", null );
127 $this->assertOutputPrePostShutdown( "", false );
130 function testOutputWNullChannelString() {
131 $this->m
->output( "foo", null );
132 $this->assertOutputPrePostShutdown( "foo", false );
135 function testOutputWNullChannelStringString() {
136 $this->m
->output( "foo", null );
137 $this->m
->output( "bar", null );
138 $this->assertOutputPrePostShutdown( "foobar", false );
141 function testOutputWNullChannelStringNL() {
142 $this->m
->output( "foo\n", null );
143 $this->assertOutputPrePostShutdown( "foo\n", false );
146 function testOutputWNullChannelStringNLNL() {
147 $this->m
->output( "foo\n\n", null );
148 $this->assertOutputPrePostShutdown( "foo\n\n", false );
151 function testOutputWNullChannelStringNLString() {
152 $this->m
->output( "foo\nbar", null );
153 $this->assertOutputPrePostShutdown( "foo\nbar", false );
156 function testOutputWNullChannelStringNLStringNL() {
157 $this->m
->output( "foo\nbar\n", null );
158 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
161 function testOutputWNullChannelStringNLStringNLLinewise() {
162 $this->m
->output( "foo\n", null );
163 $this->m
->output( "bar\n", null );
164 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
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 );
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 );
189 function testOutputWChannelString() {
190 $this->m
->output( "foo", "bazChannel" );
191 $this->assertOutputPrePostShutdown( "foo", true );
194 function testOutputWChannelStringNL() {
195 $this->m
->output( "foo\n", "bazChannel" );
196 $this->assertOutputPrePostShutdown( "foo", true );
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 );
208 function testOutputWChannelStringNLString() {
209 $this->m
->output( "foo\nbar", "bazChannel" );
210 $this->assertOutputPrePostShutdown( "foo\nbar", true );
213 function testOutputWChannelStringNLStringNL() {
214 $this->m
->output( "foo\nbar\n", "bazChannel" );
215 $this->assertOutputPrePostShutdown( "foo\nbar", true );
218 function testOutputWChannelStringNLStringNLLinewise() {
219 $this->m
->output( "foo\n", "bazChannel" );
220 $this->m
->output( "bar\n", "bazChannel" );
221 $this->assertOutputPrePostShutdown( "foobar", true );
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 );
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 );
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 );
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 );
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 );
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 );
278 function testOutputWChannelTypeSwitch() {
279 $this->m
->output( "foo", 1 );
280 $this->m
->output( "bar", 1.0 );
281 $this->assertOutputPrePostShutdown( "foo\nbar", true );
284 function testOutputIntermittentEmpty() {
285 $this->m
->output( "foo" );
286 $this->m
->output( "" );
287 $this->m
->output( "bar" );
288 $this->assertOutputPrePostShutdown( "foobar", false );
291 function testOutputIntermittentFalse() {
292 $this->m
->output( "foo" );
293 $this->m
->output( false );
294 $this->m
->output( "bar" );
295 $this->assertOutputPrePostShutdown( "foobar", false );
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 );
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 );
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 );
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 );
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 );
334 // Note that (per documentation) outputChanneled does take strings that end
335 // in \n, hence we do not test such strings.
337 function testOutputChanneledEmpty() {
338 $this->m
->outputChanneled( "" );
339 $this->assertOutputPrePostShutdown( "\n", false );
342 function testOutputChanneledString() {
343 $this->m
->outputChanneled( "foo" );
344 $this->assertOutputPrePostShutdown( "foo\n", false );
347 function testOutputChanneledStringString() {
348 $this->m
->outputChanneled( "foo" );
349 $this->m
->outputChanneled( "bar" );
350 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
353 function testOutputChanneledStringNLString() {
354 $this->m
->outputChanneled( "foo\nbar" );
355 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
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 );
369 function testOutputChanneledWNullChannelEmpty() {
370 $this->m
->outputChanneled( "", null );
371 $this->assertOutputPrePostShutdown( "\n", false );
374 function testOutputChanneledWNullChannelString() {
375 $this->m
->outputChanneled( "foo", null );
376 $this->assertOutputPrePostShutdown( "foo\n", false );
379 function testOutputChanneledWNullChannelStringString() {
380 $this->m
->outputChanneled( "foo", null );
381 $this->m
->outputChanneled( "bar", null );
382 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
385 function testOutputChanneledWNullChannelStringNLString() {
386 $this->m
->outputChanneled( "foo\nbar", null );
387 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
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 );
401 function testOutputChanneledWChannelString() {
402 $this->m
->outputChanneled( "foo", "bazChannel" );
403 $this->assertOutputPrePostShutdown( "foo", true );
406 function testOutputChanneledWChannelStringNLString() {
407 $this->m
->outputChanneled( "foo\nbar", "bazChannel" );
408 $this->assertOutputPrePostShutdown( "foo\nbar", true );
411 function testOutputChanneledWChannelStringString() {
412 $this->m
->outputChanneled( "foo", "bazChannel" );
413 $this->m
->outputChanneled( "bar", "bazChannel" );
414 $this->assertOutputPrePostShutdown( "foobar", true );
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 );
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 );
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 );
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 );
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 );
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 );
468 function testOutputChanneledWChannelTypeSwitch() {
469 $this->m
->outputChanneled( "foo", 1 );
470 $this->m
->outputChanneled( "bar", 1.0 );
471 $this->assertOutputPrePostShutdown( "foo\nbar", true );
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 );
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 );
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 );
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 );
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 );
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 );
516 function testCleanupChanneledClean() {
517 $this->m
->cleanupChanneled();
518 $this->assertOutputPrePostShutdown( "", false );
521 function testCleanupChanneledAfterOutput() {
522 $this->m
->output( "foo" );
523 $this->m
->cleanupChanneled();
524 $this->assertOutputPrePostShutdown( "foo", false );
527 function testCleanupChanneledAfterOutputWNullChannel() {
528 $this->m
->output( "foo", null );
529 $this->m
->cleanupChanneled();
530 $this->assertOutputPrePostShutdown( "foo", false );
533 function testCleanupChanneledAfterOutputWChannel() {
534 $this->m
->output( "foo", "bazChannel" );
535 $this->m
->cleanupChanneled();
536 $this->assertOutputPrePostShutdown( "foo\n", false );
539 function testCleanupChanneledAfterNLOutput() {
540 $this->m
->output( "foo\n" );
541 $this->m
->cleanupChanneled();
542 $this->assertOutputPrePostShutdown( "foo\n", false );
545 function testCleanupChanneledAfterNLOutputWNullChannel() {
546 $this->m
->output( "foo\n", null );
547 $this->m
->cleanupChanneled();
548 $this->assertOutputPrePostShutdown( "foo\n", false );
551 function testCleanupChanneledAfterNLOutputWChannel() {
552 $this->m
->output( "foo\n", "bazChannel" );
553 $this->m
->cleanupChanneled();
554 $this->assertOutputPrePostShutdown( "foo\n", false );
557 function testCleanupChanneledAfterOutputChanneledWOChannel() {
558 $this->m
->outputChanneled( "foo" );
559 $this->m
->cleanupChanneled();
560 $this->assertOutputPrePostShutdown( "foo\n", false );
563 function testCleanupChanneledAfterOutputChanneledWNullChannel() {
564 $this->m
->outputChanneled( "foo", null );
565 $this->m
->cleanupChanneled();
566 $this->assertOutputPrePostShutdown( "foo\n", false );
569 function testCleanupChanneledAfterOutputChanneledWChannel() {
570 $this->m
->outputChanneled( "foo", "bazChannel" );
571 $this->m
->cleanupChanneled();
572 $this->assertOutputPrePostShutdown( "foo\n", false );
575 function testMultipleMaintenanceObjectsInteractionOutput() {
576 $m2 = new MaintenanceFixup( $this );
578 $this->m
->output( "foo" );
579 $m2->output( "bar" );
581 $this->assertEquals( "foobar", $this->getActualOutput(),
582 "Output before shutdown simulation (m2)" );
583 $m2->simulateShutdown();
584 $this->assertOutputPrePostShutdown( "foobar", false );
587 function testMultipleMaintenanceObjectsInteractionOutputWNullChannel() {
588 $m2 = new MaintenanceFixup( $this );
590 $this->m
->output( "foo", null );
591 $m2->output( "bar", null );
593 $this->assertEquals( "foobar", $this->getActualOutput(),
594 "Output before shutdown simulation (m2)" );
595 $m2->simulateShutdown();
596 $this->assertOutputPrePostShutdown( "foobar", false );
599 function testMultipleMaintenanceObjectsInteractionOutputWChannel() {
600 $m2 = new MaintenanceFixup( $this );
602 $this->m
->output( "foo", "bazChannel" );
603 $m2->output( "bar", "bazChannel" );
605 $this->assertEquals( "foobar", $this->getActualOutput(),
606 "Output before shutdown simulation (m2)" );
607 $m2->simulateShutdown();
608 $this->assertOutputPrePostShutdown( "foobar\n", true );
611 function testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL() {
612 $m2 = new MaintenanceFixup( $this );
614 $this->m
->output( "foo\n", null );
615 $m2->output( "bar\n", null );
617 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
618 "Output before shutdown simulation (m2)" );
619 $m2->simulateShutdown();
620 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
623 function testMultipleMaintenanceObjectsInteractionOutputWChannelNL() {
624 $m2 = new MaintenanceFixup( $this );
626 $this->m
->output( "foo\n", "bazChannel" );
627 $m2->output( "bar\n", "bazChannel" );
629 $this->assertEquals( "foobar", $this->getActualOutput(),
630 "Output before shutdown simulation (m2)" );
631 $m2->simulateShutdown();
632 $this->assertOutputPrePostShutdown( "foobar\n", true );
635 function testMultipleMaintenanceObjectsInteractionOutputChanneled() {
636 $m2 = new MaintenanceFixup( $this );
638 $this->m
->outputChanneled( "foo" );
639 $m2->outputChanneled( "bar" );
641 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
642 "Output before shutdown simulation (m2)" );
643 $m2->simulateShutdown();
644 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
647 function testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel() {
648 $m2 = new MaintenanceFixup( $this );
650 $this->m
->outputChanneled( "foo", null );
651 $m2->outputChanneled( "bar", null );
653 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
654 "Output before shutdown simulation (m2)" );
655 $m2->simulateShutdown();
656 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
659 function testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel() {
660 $m2 = new MaintenanceFixup( $this );
662 $this->m
->outputChanneled( "foo", "bazChannel" );
663 $m2->outputChanneled( "bar", "bazChannel" );
665 $this->assertEquals( "foobar", $this->getActualOutput(),
666 "Output before shutdown simulation (m2)" );
667 $m2->simulateShutdown();
668 $this->assertOutputPrePostShutdown( "foobar\n", true );
671 function testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel() {
672 $m2 = new MaintenanceFixup( $this );
674 $this->m
->outputChanneled( "foo", "bazChannel" );
675 $m2->outputChanneled( "bar", "bazChannel" );
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" );
686 $m2->simulateShutdown();
687 $this->assertOutputPrePostShutdown( "foobar\n\n", false );
691 * @covers Maintenance::getConfig
693 public function testGetConfig() {
694 $this->assertInstanceOf( 'Config', $this->m
->getConfig() );
696 MediaWikiServices
::getInstance()->getMainConfig(),
697 $this->m
->getConfig()
702 * @covers Maintenance::setConfig
704 public function testSetConfig() {
705 $conf = $this->createMock( 'Config' );
706 $this->m
->setConfig( $conf );
707 $this->assertSame( $conf, $this->m
->getConfig() );
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' ] );
716 $this->assertEquals( [ 'this1', 'this2' ], $m2->getOption( 'multi' ) );
717 $this->assertEquals( [ [ 'multi', 'this1' ], [ 'multi', 'this2' ] ],
718 $m2->orderedOptions
);
720 $m2->simulateShutdown();
722 $m2 = new MaintenanceFixup( $this );
724 $m2->addOption( 'multi', 'This option does stuff', false, false, false, true );
725 $m2->loadWithArgv( [ '--multi', '--multi' ] );
727 $this->assertEquals( [ 1, 1 ], $m2->getOption( 'multi' ) );
728 $this->assertEquals( [ [ 'multi', 1 ], [ 'multi', 1 ] ], $m2->orderedOptions
);
730 $m2->simulateShutdown();
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' ] );
737 $this->assertEquals( 'yo', $m2->getOption( 'multi' ) );
738 $this->assertEquals( [ [ 'multi', 'yo' ] ], $m2->orderedOptions
);
740 $m2->simulateShutdown();