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