Declare visibility on Autoloader::$autoloadLocalClassesLower
[lhc/web/wiklou.git] / tests / phpunit / maintenance / MaintenanceTest.php
1 <?php
2
3 // It would be great if we were able to use PHPUnit's getMockForAbstractClass
4 // instead of the MaintenanceFixup hack below. However, we cannot do
5 // without changing the visibility and without working around hacks in
6 // Maintenance.php
7 //
8 // For the same reason, we cannot just use FakeMaintenance.
9
10 /**
11 * makes parts of the API of Maintenance that is hidden by protected visibily
12 * visible for testing, and makes up for a stream closing hack in Maintenance.php.
13 *
14 * This class is solely used for being able to test Maintenance right now
15 * without having to apply major refactorings to fix some design issues in
16 * Maintenance.php. Before adding more functions here, please consider whether
17 * this approach is correct, or a refactoring Maintenance to separate concers
18 * is more appropriate.
19 *
20 * Upon refactoring, keep in mind that besides the maintenance scrits themselves
21 * and tests right here, also at least Extension:Maintenance make use of
22 * Maintenance.
23 *
24 * Due to a hack in Maintenance.php using register_shutdown_function, be sure to
25 * finally call simulateShutdown on MaintenanceFixup instance before a test
26 * ends.
27 *
28 */
29 class MaintenanceFixup extends Maintenance {
30
31 // --- Making up for the register_shutdown_function hack in Maintenance.php
32
33 /**
34 * The test case that generated this instance.
35 *
36 * This member is motivated by allowing the destructor to check whether or not
37 * the test failed, in order to avoid unnecessary nags about omitted shutdown
38 * simulation.
39 * But as it is already available, we also usi it to flagging tests as failed
40 *
41 * @var MediaWikiTestCase
42 */
43 private $testCase;
44
45 /**
46 * shutdownSimulated === true if simulateShutdown has done it's work
47 *
48 * @var bool
49 */
50 private $shutdownSimulated = false;
51
52 /**
53 * Simulates what Maintenance wants to happen at script's end.
54 */
55 public function simulateShutdown() {
56
57 if ( $this->shutdownSimulated ) {
58 $this->testCase->fail( __METHOD__ . " called more than once" );
59 }
60
61 // The cleanup action.
62 $this->outputChanneled( false );
63
64 // Bookkeeping that we simulated the clean up.
65 $this->shutdownSimulated = true;
66 }
67
68 // Note that the "public" here does not change visibility
69 public function outputChanneled( $msg, $channel = null ) {
70 if ( $this->shutdownSimulated ) {
71 if ( $msg !== false ) {
72 $this->testCase->fail( "Already past simulated shutdown, but msg is "
73 . "not false. Did the hack in Maintenance.php change? Please "
74 . "adapt the test case or Maintenance.php" );
75 }
76
77 // The current call is the one registered via register_shutdown_function.
78 // We can safely ignore it, as we simulated this one via simulateShutdown
79 // before (if we did not, the destructor of this instance will warn about
80 // it)
81 return;
82 }
83
84 return call_user_func_array( array( "parent", __FUNCTION__ ), func_get_args() );
85 }
86
87 /**
88 * Safety net around register_shutdown_function of Maintenance.php
89 */
90 public function __destruct() {
91 if ( !$this->shutdownSimulated ) {
92 // Someone generated a MaintenanceFixup instance without calling
93 // simulateShutdown. We'd have to raise a PHPUnit exception to correctly
94 // flag this illegal usage. However, we are already in a destruktor, which
95 // would trigger undefined behavior. Hence, we can only report to the
96 // error output :( Hopefully people read the PHPUnit output.
97 $name = $this->testCase->getName();
98 fwrite( STDERR, "ERROR! Instance of " . __CLASS__ . " for test $name "
99 . "destructed without calling simulateShutdown method. Call "
100 . "simulateShutdown on the instance before it gets destructed." );
101 }
102
103 // The following guard is required, as PHP does not offer default destructors :(
104 if ( is_callable( "parent::__destruct" ) ) {
105 parent::__destruct();
106 }
107 }
108
109 public function __construct( MediaWikiTestCase $testCase ) {
110 parent::__construct();
111 $this->testCase = $testCase;
112 }
113
114
115 // --- Making protected functions visible for test
116
117 public function output( $out, $channel = null ) {
118 // Just to make PHP not nag about signature mismatches, we copied
119 // Maintenance::output signature. However, we do not use (or rely on)
120 // those variables. Instead we pass to Maintenance::output whatever we
121 // receive at runtime.
122 return call_user_func_array( array( "parent", __FUNCTION__ ), func_get_args() );
123 }
124
125
126 // --- Requirements for getting instance of abstract class
127
128 public function execute() {
129 $this->testCase->fail( __METHOD__ . " called unexpectedly" );
130 }
131 }
132
133 /**
134 * @covers Maintenance
135 */
136 class MaintenanceTest extends MediaWikiTestCase {
137
138
139 /**
140 * The main Maintenance instance that is used for testing.
141 *
142 * @var MaintenanceFixup
143 */
144 private $m;
145
146
147 protected function setUp() {
148 parent::setUp();
149 $this->m = new MaintenanceFixup( $this );
150 }
151
152 protected function tearDown() {
153 if ( $this->m ) {
154 $this->m->simulateShutdown();
155 $this->m = null;
156 }
157 parent::tearDown();
158 }
159
160
161 /**
162 * asserts the output before and after simulating shutdown
163 *
164 * This function simulates shutdown of self::m.
165 *
166 * @param $preShutdownOutput string: expected output before simulating shutdown
167 * @param $expectNLAppending bool: Whether or not shutdown simulation is expected
168 * to add a newline to the output. If false, $preShutdownOutput is the
169 * expected output after shutdown simulation. Otherwise,
170 * $preShutdownOutput with an appended newline is the expected output
171 * after shutdown simulation.
172 */
173 private function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
174
175 $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
176 "Output before shutdown simulation" );
177
178 $this->m->simulateShutdown();
179 $this->m = null;
180
181 $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ? "\n" : "" );
182 $this->expectOutputString( $postShutdownOutput );
183 }
184
185
186 // Although the following tests do not seem to be too consistent (compare for
187 // example the newlines within the test.*StringString tests, or the
188 // test.*Intermittent.* tests), the objective of these tests is not to describe
189 // consistent behavior, but rather currently existing behavior.
190
191 function testOutputEmpty() {
192 $this->m->output( "" );
193 $this->assertOutputPrePostShutdown( "", false );
194 }
195
196 function testOutputString() {
197 $this->m->output( "foo" );
198 $this->assertOutputPrePostShutdown( "foo", false );
199 }
200
201 function testOutputStringString() {
202 $this->m->output( "foo" );
203 $this->m->output( "bar" );
204 $this->assertOutputPrePostShutdown( "foobar", false );
205 }
206
207 function testOutputStringNL() {
208 $this->m->output( "foo\n" );
209 $this->assertOutputPrePostShutdown( "foo\n", false );
210 }
211
212 function testOutputStringNLNL() {
213 $this->m->output( "foo\n\n" );
214 $this->assertOutputPrePostShutdown( "foo\n\n", false );
215 }
216
217 function testOutputStringNLString() {
218 $this->m->output( "foo\nbar" );
219 $this->assertOutputPrePostShutdown( "foo\nbar", false );
220 }
221
222 function testOutputStringNLStringNL() {
223 $this->m->output( "foo\nbar\n" );
224 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
225 }
226
227 function testOutputStringNLStringNLLinewise() {
228 $this->m->output( "foo\n" );
229 $this->m->output( "bar\n" );
230 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
231 }
232
233 function testOutputStringNLStringNLArbitrary() {
234 $this->m->output( "" );
235 $this->m->output( "foo" );
236 $this->m->output( "" );
237 $this->m->output( "\n" );
238 $this->m->output( "ba" );
239 $this->m->output( "" );
240 $this->m->output( "r\n" );
241 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
242 }
243
244 function testOutputStringNLStringNLArbitraryAgain() {
245 $this->m->output( "" );
246 $this->m->output( "foo" );
247 $this->m->output( "" );
248 $this->m->output( "\nb" );
249 $this->m->output( "a" );
250 $this->m->output( "" );
251 $this->m->output( "r\n" );
252 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
253 }
254
255 function testOutputWNullChannelEmpty() {
256 $this->m->output( "", null );
257 $this->assertOutputPrePostShutdown( "", false );
258 }
259
260 function testOutputWNullChannelString() {
261 $this->m->output( "foo", null );
262 $this->assertOutputPrePostShutdown( "foo", false );
263 }
264
265 function testOutputWNullChannelStringString() {
266 $this->m->output( "foo", null );
267 $this->m->output( "bar", null );
268 $this->assertOutputPrePostShutdown( "foobar", false );
269 }
270
271 function testOutputWNullChannelStringNL() {
272 $this->m->output( "foo\n", null );
273 $this->assertOutputPrePostShutdown( "foo\n", false );
274 }
275
276 function testOutputWNullChannelStringNLNL() {
277 $this->m->output( "foo\n\n", null );
278 $this->assertOutputPrePostShutdown( "foo\n\n", false );
279 }
280
281 function testOutputWNullChannelStringNLString() {
282 $this->m->output( "foo\nbar", null );
283 $this->assertOutputPrePostShutdown( "foo\nbar", false );
284 }
285
286 function testOutputWNullChannelStringNLStringNL() {
287 $this->m->output( "foo\nbar\n", null );
288 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
289 }
290
291 function testOutputWNullChannelStringNLStringNLLinewise() {
292 $this->m->output( "foo\n", null );
293 $this->m->output( "bar\n", null );
294 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
295 }
296
297 function testOutputWNullChannelStringNLStringNLArbitrary() {
298 $this->m->output( "", null );
299 $this->m->output( "foo", null );
300 $this->m->output( "", null );
301 $this->m->output( "\n", null );
302 $this->m->output( "ba", null );
303 $this->m->output( "", null );
304 $this->m->output( "r\n", null );
305 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
306 }
307
308 function testOutputWNullChannelStringNLStringNLArbitraryAgain() {
309 $this->m->output( "", null );
310 $this->m->output( "foo", null );
311 $this->m->output( "", null );
312 $this->m->output( "\nb", null );
313 $this->m->output( "a", null );
314 $this->m->output( "", null );
315 $this->m->output( "r\n", null );
316 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
317 }
318
319 function testOutputWChannelString() {
320 $this->m->output( "foo", "bazChannel" );
321 $this->assertOutputPrePostShutdown( "foo", true );
322 }
323
324 function testOutputWChannelStringNL() {
325 $this->m->output( "foo\n", "bazChannel" );
326 $this->assertOutputPrePostShutdown( "foo", true );
327 }
328
329 function testOutputWChannelStringNLNL() {
330 // If this test fails, note that output takes strings with double line
331 // endings (although output's implementation in this situation calls
332 // outputChanneled with a string ending in a nl ... which is not allowed
333 // according to the documentation of outputChanneled)
334 $this->m->output( "foo\n\n", "bazChannel" );
335 $this->assertOutputPrePostShutdown( "foo\n", true );
336 }
337
338 function testOutputWChannelStringNLString() {
339 $this->m->output( "foo\nbar", "bazChannel" );
340 $this->assertOutputPrePostShutdown( "foo\nbar", true );
341 }
342
343 function testOutputWChannelStringNLStringNL() {
344 $this->m->output( "foo\nbar\n", "bazChannel" );
345 $this->assertOutputPrePostShutdown( "foo\nbar", true );
346 }
347
348 function testOutputWChannelStringNLStringNLLinewise() {
349 $this->m->output( "foo\n", "bazChannel" );
350 $this->m->output( "bar\n", "bazChannel" );
351 $this->assertOutputPrePostShutdown( "foobar", true );
352 }
353
354 function testOutputWChannelStringNLStringNLArbitrary() {
355 $this->m->output( "", "bazChannel" );
356 $this->m->output( "foo", "bazChannel" );
357 $this->m->output( "", "bazChannel" );
358 $this->m->output( "\n", "bazChannel" );
359 $this->m->output( "ba", "bazChannel" );
360 $this->m->output( "", "bazChannel" );
361 $this->m->output( "r\n", "bazChannel" );
362 $this->assertOutputPrePostShutdown( "foobar", true );
363 }
364
365 function testOutputWChannelStringNLStringNLArbitraryAgain() {
366 $this->m->output( "", "bazChannel" );
367 $this->m->output( "foo", "bazChannel" );
368 $this->m->output( "", "bazChannel" );
369 $this->m->output( "\nb", "bazChannel" );
370 $this->m->output( "a", "bazChannel" );
371 $this->m->output( "", "bazChannel" );
372 $this->m->output( "r\n", "bazChannel" );
373 $this->assertOutputPrePostShutdown( "foo\nbar", true );
374 }
375
376 function testOutputWMultipleChannelsChannelChange() {
377 $this->m->output( "foo", "bazChannel" );
378 $this->m->output( "bar", "bazChannel" );
379 $this->m->output( "qux", "quuxChannel" );
380 $this->m->output( "corge", "bazChannel" );
381 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
382 }
383
384 function testOutputWMultipleChannelsChannelChangeNL() {
385 $this->m->output( "foo", "bazChannel" );
386 $this->m->output( "bar\n", "bazChannel" );
387 $this->m->output( "qux\n", "quuxChannel" );
388 $this->m->output( "corge", "bazChannel" );
389 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
390 }
391
392 function testOutputWAndWOChannelStringStartWO() {
393 $this->m->output( "foo" );
394 $this->m->output( "bar", "bazChannel" );
395 $this->m->output( "qux" );
396 $this->m->output( "quux", "bazChannel" );
397 $this->assertOutputPrePostShutdown( "foobar\nquxquux", true );
398 }
399
400 function testOutputWAndWOChannelStringStartW() {
401 $this->m->output( "foo", "bazChannel" );
402 $this->m->output( "bar" );
403 $this->m->output( "qux", "bazChannel" );
404 $this->m->output( "quux" );
405 $this->assertOutputPrePostShutdown( "foo\nbarqux\nquux", false );
406 }
407
408 function testOutputWChannelTypeSwitch() {
409 $this->m->output( "foo", 1 );
410 $this->m->output( "bar", 1.0 );
411 $this->assertOutputPrePostShutdown( "foo\nbar", true );
412 }
413
414 function testOutputIntermittentEmpty() {
415 $this->m->output( "foo" );
416 $this->m->output( "" );
417 $this->m->output( "bar" );
418 $this->assertOutputPrePostShutdown( "foobar", false );
419 }
420
421 function testOutputIntermittentFalse() {
422 $this->m->output( "foo" );
423 $this->m->output( false );
424 $this->m->output( "bar" );
425 $this->assertOutputPrePostShutdown( "foobar", false );
426 }
427
428 function testOutputIntermittentFalseAfterOtherChannel() {
429 $this->m->output( "qux", "quuxChannel" );
430 $this->m->output( "foo" );
431 $this->m->output( false );
432 $this->m->output( "bar" );
433 $this->assertOutputPrePostShutdown( "qux\nfoobar", false );
434 }
435
436 function testOutputWNullChannelIntermittentEmpty() {
437 $this->m->output( "foo", null );
438 $this->m->output( "", null );
439 $this->m->output( "bar", null );
440 $this->assertOutputPrePostShutdown( "foobar", false );
441 }
442
443 function testOutputWNullChannelIntermittentFalse() {
444 $this->m->output( "foo", null );
445 $this->m->output( false, null );
446 $this->m->output( "bar", null );
447 $this->assertOutputPrePostShutdown( "foobar", false );
448 }
449
450 function testOutputWChannelIntermittentEmpty() {
451 $this->m->output( "foo", "bazChannel" );
452 $this->m->output( "", "bazChannel" );
453 $this->m->output( "bar", "bazChannel" );
454 $this->assertOutputPrePostShutdown( "foobar", true );
455 }
456
457 function testOutputWChannelIntermittentFalse() {
458 $this->m->output( "foo", "bazChannel" );
459 $this->m->output( false, "bazChannel" );
460 $this->m->output( "bar", "bazChannel" );
461 $this->assertOutputPrePostShutdown( "foobar", true );
462 }
463
464 // Note that (per documentation) outputChanneled does take strings that end
465 // in \n, hence we do not test such strings.
466
467 function testOutputChanneledEmpty() {
468 $this->m->outputChanneled( "" );
469 $this->assertOutputPrePostShutdown( "\n", false );
470 }
471
472 function testOutputChanneledString() {
473 $this->m->outputChanneled( "foo" );
474 $this->assertOutputPrePostShutdown( "foo\n", false );
475 }
476
477 function testOutputChanneledStringString() {
478 $this->m->outputChanneled( "foo" );
479 $this->m->outputChanneled( "bar" );
480 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
481 }
482
483 function testOutputChanneledStringNLString() {
484 $this->m->outputChanneled( "foo\nbar" );
485 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
486 }
487
488 function testOutputChanneledStringNLStringNLArbitraryAgain() {
489 $this->m->outputChanneled( "" );
490 $this->m->outputChanneled( "foo" );
491 $this->m->outputChanneled( "" );
492 $this->m->outputChanneled( "\nb" );
493 $this->m->outputChanneled( "a" );
494 $this->m->outputChanneled( "" );
495 $this->m->outputChanneled( "r" );
496 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
497 }
498
499 function testOutputChanneledWNullChannelEmpty() {
500 $this->m->outputChanneled( "", null );
501 $this->assertOutputPrePostShutdown( "\n", false );
502 }
503
504 function testOutputChanneledWNullChannelString() {
505 $this->m->outputChanneled( "foo", null );
506 $this->assertOutputPrePostShutdown( "foo\n", false );
507 }
508
509 function testOutputChanneledWNullChannelStringString() {
510 $this->m->outputChanneled( "foo", null );
511 $this->m->outputChanneled( "bar", null );
512 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
513 }
514
515 function testOutputChanneledWNullChannelStringNLString() {
516 $this->m->outputChanneled( "foo\nbar", null );
517 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
518 }
519
520 function testOutputChanneledWNullChannelStringNLStringNLArbitraryAgain() {
521 $this->m->outputChanneled( "", null );
522 $this->m->outputChanneled( "foo", null );
523 $this->m->outputChanneled( "", null );
524 $this->m->outputChanneled( "\nb", null );
525 $this->m->outputChanneled( "a", null );
526 $this->m->outputChanneled( "", null );
527 $this->m->outputChanneled( "r", null );
528 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
529 }
530
531 function testOutputChanneledWChannelString() {
532 $this->m->outputChanneled( "foo", "bazChannel" );
533 $this->assertOutputPrePostShutdown( "foo", true );
534 }
535
536 function testOutputChanneledWChannelStringNLString() {
537 $this->m->outputChanneled( "foo\nbar", "bazChannel" );
538 $this->assertOutputPrePostShutdown( "foo\nbar", true );
539 }
540
541 function testOutputChanneledWChannelStringString() {
542 $this->m->outputChanneled( "foo", "bazChannel" );
543 $this->m->outputChanneled( "bar", "bazChannel" );
544 $this->assertOutputPrePostShutdown( "foobar", true );
545 }
546
547 function testOutputChanneledWChannelStringNLStringNLArbitraryAgain() {
548 $this->m->outputChanneled( "", "bazChannel" );
549 $this->m->outputChanneled( "foo", "bazChannel" );
550 $this->m->outputChanneled( "", "bazChannel" );
551 $this->m->outputChanneled( "\nb", "bazChannel" );
552 $this->m->outputChanneled( "a", "bazChannel" );
553 $this->m->outputChanneled( "", "bazChannel" );
554 $this->m->outputChanneled( "r", "bazChannel" );
555 $this->assertOutputPrePostShutdown( "foo\nbar", true );
556 }
557
558 function testOutputChanneledWMultipleChannelsChannelChange() {
559 $this->m->outputChanneled( "foo", "bazChannel" );
560 $this->m->outputChanneled( "bar", "bazChannel" );
561 $this->m->outputChanneled( "qux", "quuxChannel" );
562 $this->m->outputChanneled( "corge", "bazChannel" );
563 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
564 }
565
566 function testOutputChanneledWMultipleChannelsChannelChangeEnclosedNull() {
567 $this->m->outputChanneled( "foo", "bazChannel" );
568 $this->m->outputChanneled( "bar", null );
569 $this->m->outputChanneled( "qux", null );
570 $this->m->outputChanneled( "corge", "bazChannel" );
571 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
572 }
573
574 function testOutputChanneledWMultipleChannelsChannelAfterNullChange() {
575 $this->m->outputChanneled( "foo", "bazChannel" );
576 $this->m->outputChanneled( "bar", null );
577 $this->m->outputChanneled( "qux", null );
578 $this->m->outputChanneled( "corge", "quuxChannel" );
579 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
580 }
581
582 function testOutputChanneledWAndWOChannelStringStartWO() {
583 $this->m->outputChanneled( "foo" );
584 $this->m->outputChanneled( "bar", "bazChannel" );
585 $this->m->outputChanneled( "qux" );
586 $this->m->outputChanneled( "quux", "bazChannel" );
587 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux", true );
588 }
589
590 function testOutputChanneledWAndWOChannelStringStartW() {
591 $this->m->outputChanneled( "foo", "bazChannel" );
592 $this->m->outputChanneled( "bar" );
593 $this->m->outputChanneled( "qux", "bazChannel" );
594 $this->m->outputChanneled( "quux" );
595 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux\n", false );
596 }
597
598 function testOutputChanneledWChannelTypeSwitch() {
599 $this->m->outputChanneled( "foo", 1 );
600 $this->m->outputChanneled( "bar", 1.0 );
601 $this->assertOutputPrePostShutdown( "foo\nbar", true );
602 }
603
604 function testOutputChanneledWOChannelIntermittentEmpty() {
605 $this->m->outputChanneled( "foo" );
606 $this->m->outputChanneled( "" );
607 $this->m->outputChanneled( "bar" );
608 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
609 }
610
611 function testOutputChanneledWOChannelIntermittentFalse() {
612 $this->m->outputChanneled( "foo" );
613 $this->m->outputChanneled( false );
614 $this->m->outputChanneled( "bar" );
615 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
616 }
617
618 function testOutputChanneledWNullChannelIntermittentEmpty() {
619 $this->m->outputChanneled( "foo", null );
620 $this->m->outputChanneled( "", null );
621 $this->m->outputChanneled( "bar", null );
622 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
623 }
624
625 function testOutputChanneledWNullChannelIntermittentFalse() {
626 $this->m->outputChanneled( "foo", null );
627 $this->m->outputChanneled( false, null );
628 $this->m->outputChanneled( "bar", null );
629 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
630 }
631
632 function testOutputChanneledWChannelIntermittentEmpty() {
633 $this->m->outputChanneled( "foo", "bazChannel" );
634 $this->m->outputChanneled( "", "bazChannel" );
635 $this->m->outputChanneled( "bar", "bazChannel" );
636 $this->assertOutputPrePostShutdown( "foobar", true );
637 }
638
639 function testOutputChanneledWChannelIntermittentFalse() {
640 $this->m->outputChanneled( "foo", "bazChannel" );
641 $this->m->outputChanneled( false, "bazChannel" );
642 $this->m->outputChanneled( "bar", "bazChannel" );
643 $this->assertOutputPrePostShutdown( "foo\nbar", true );
644 }
645
646 function testCleanupChanneledClean() {
647 $this->m->cleanupChanneled();
648 $this->assertOutputPrePostShutdown( "", false );
649 }
650
651 function testCleanupChanneledAfterOutput() {
652 $this->m->output( "foo" );
653 $this->m->cleanupChanneled();
654 $this->assertOutputPrePostShutdown( "foo", false );
655 }
656
657 function testCleanupChanneledAfterOutputWNullChannel() {
658 $this->m->output( "foo", null );
659 $this->m->cleanupChanneled();
660 $this->assertOutputPrePostShutdown( "foo", false );
661 }
662
663 function testCleanupChanneledAfterOutputWChannel() {
664 $this->m->output( "foo", "bazChannel" );
665 $this->m->cleanupChanneled();
666 $this->assertOutputPrePostShutdown( "foo\n", false );
667 }
668
669 function testCleanupChanneledAfterNLOutput() {
670 $this->m->output( "foo\n" );
671 $this->m->cleanupChanneled();
672 $this->assertOutputPrePostShutdown( "foo\n", false );
673 }
674
675 function testCleanupChanneledAfterNLOutputWNullChannel() {
676 $this->m->output( "foo\n", null );
677 $this->m->cleanupChanneled();
678 $this->assertOutputPrePostShutdown( "foo\n", false );
679 }
680
681 function testCleanupChanneledAfterNLOutputWChannel() {
682 $this->m->output( "foo\n", "bazChannel" );
683 $this->m->cleanupChanneled();
684 $this->assertOutputPrePostShutdown( "foo\n", false );
685 }
686
687 function testCleanupChanneledAfterOutputChanneledWOChannel() {
688 $this->m->outputChanneled( "foo" );
689 $this->m->cleanupChanneled();
690 $this->assertOutputPrePostShutdown( "foo\n", false );
691 }
692
693 function testCleanupChanneledAfterOutputChanneledWNullChannel() {
694 $this->m->outputChanneled( "foo", null );
695 $this->m->cleanupChanneled();
696 $this->assertOutputPrePostShutdown( "foo\n", false );
697 }
698
699 function testCleanupChanneledAfterOutputChanneledWChannel() {
700 $this->m->outputChanneled( "foo", "bazChannel" );
701 $this->m->cleanupChanneled();
702 $this->assertOutputPrePostShutdown( "foo\n", false );
703 }
704
705 function testMultipleMaintenanceObjectsInteractionOutput() {
706 $m2 = new MaintenanceFixup( $this );
707
708 $this->m->output( "foo" );
709 $m2->output( "bar" );
710
711 $this->assertEquals( "foobar", $this->getActualOutput(),
712 "Output before shutdown simulation (m2)" );
713 $m2->simulateShutdown();
714 $this->assertOutputPrePostShutdown( "foobar", false );
715 }
716
717 function testMultipleMaintenanceObjectsInteractionOutputWNullChannel() {
718 $m2 = new MaintenanceFixup( $this );
719
720 $this->m->output( "foo", null );
721 $m2->output( "bar", null );
722
723 $this->assertEquals( "foobar", $this->getActualOutput(),
724 "Output before shutdown simulation (m2)" );
725 $m2->simulateShutdown();
726 $this->assertOutputPrePostShutdown( "foobar", false );
727 }
728
729 function testMultipleMaintenanceObjectsInteractionOutputWChannel() {
730 $m2 = new MaintenanceFixup( $this );
731
732 $this->m->output( "foo", "bazChannel" );
733 $m2->output( "bar", "bazChannel" );
734
735 $this->assertEquals( "foobar", $this->getActualOutput(),
736 "Output before shutdown simulation (m2)" );
737 $m2->simulateShutdown();
738 $this->assertOutputPrePostShutdown( "foobar\n", true );
739 }
740
741 function testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL() {
742 $m2 = new MaintenanceFixup( $this );
743
744 $this->m->output( "foo\n", null );
745 $m2->output( "bar\n", null );
746
747 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
748 "Output before shutdown simulation (m2)" );
749 $m2->simulateShutdown();
750 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
751 }
752
753 function testMultipleMaintenanceObjectsInteractionOutputWChannelNL() {
754 $m2 = new MaintenanceFixup( $this );
755
756 $this->m->output( "foo\n", "bazChannel" );
757 $m2->output( "bar\n", "bazChannel" );
758
759 $this->assertEquals( "foobar", $this->getActualOutput(),
760 "Output before shutdown simulation (m2)" );
761 $m2->simulateShutdown();
762 $this->assertOutputPrePostShutdown( "foobar\n", true );
763 }
764
765 function testMultipleMaintenanceObjectsInteractionOutputChanneled() {
766 $m2 = new MaintenanceFixup( $this );
767
768 $this->m->outputChanneled( "foo" );
769 $m2->outputChanneled( "bar" );
770
771 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
772 "Output before shutdown simulation (m2)" );
773 $m2->simulateShutdown();
774 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
775 }
776
777 function testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel() {
778 $m2 = new MaintenanceFixup( $this );
779
780 $this->m->outputChanneled( "foo", null );
781 $m2->outputChanneled( "bar", null );
782
783 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
784 "Output before shutdown simulation (m2)" );
785 $m2->simulateShutdown();
786 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
787 }
788
789 function testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel() {
790 $m2 = new MaintenanceFixup( $this );
791
792 $this->m->outputChanneled( "foo", "bazChannel" );
793 $m2->outputChanneled( "bar", "bazChannel" );
794
795 $this->assertEquals( "foobar", $this->getActualOutput(),
796 "Output before shutdown simulation (m2)" );
797 $m2->simulateShutdown();
798 $this->assertOutputPrePostShutdown( "foobar\n", true );
799 }
800
801 function testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel() {
802 $m2 = new MaintenanceFixup( $this );
803
804 $this->m->outputChanneled( "foo", "bazChannel" );
805 $m2->outputChanneled( "bar", "bazChannel" );
806
807 $this->assertEquals( "foobar", $this->getActualOutput(),
808 "Output before first cleanup" );
809 $this->m->cleanupChanneled();
810 $this->assertEquals( "foobar\n", $this->getActualOutput(),
811 "Output after first cleanup" );
812 $m2->cleanupChanneled();
813 $this->assertEquals( "foobar\n\n", $this->getActualOutput(),
814 "Output after second cleanup" );
815
816 $m2->simulateShutdown();
817 $this->assertOutputPrePostShutdown( "foobar\n\n", false );
818 }
819 }