Merge "Normalise documentation in tests/selenium"
[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 iff 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 class MaintenanceTest extends MediaWikiTestCase {
135
136
137 /**
138 * The main Maintenance instance that is used for testing.
139 *
140 * @var MaintenanceFixup
141 */
142 private $m;
143
144
145 protected function setUp() {
146 parent::setUp();
147 $this->m = new MaintenanceFixup( $this );
148 }
149
150 protected function tearDown() {
151 if ( $this->m ) {
152 $this->m->simulateShutdown();
153 $this->m = null;
154 }
155 parent::tearDown();
156 }
157
158
159 /**
160 * asserts the output before and after simulating shutdown
161 *
162 * This function simulates shutdown of self::m.
163 *
164 * @param $preShutdownOutput string: expected output before simulating shutdown
165 * @param $expectNLAppending bool: Whether or not shutdown simulation is expected
166 * to add a newline to the output. If false, $preShutdownOutput is the
167 * expected output after shutdown simulation. Otherwise,
168 * $preShutdownOutput with an appended newline is the expected output
169 * after shutdown simulation.
170 */
171 private function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
172
173 $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
174 "Output before shutdown simulation" );
175
176 $this->m->simulateShutdown();
177 $this->m = null;
178
179 $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ? "\n" : "" );
180 $this->expectOutputString( $postShutdownOutput );
181 }
182
183
184 // Although the following tests do not seem to be too consistent (compare for
185 // example the newlines within the test.*StringString tests, or the
186 // test.*Intermittent.* tests), the objective of these tests is not to describe
187 // consistent behavior, but rather currently existing behavior.
188
189
190 function testOutputEmpty() {
191 $this->m->output( "" );
192 $this->assertOutputPrePostShutdown( "", false );
193 }
194
195 function testOutputString() {
196 $this->m->output( "foo" );
197 $this->assertOutputPrePostShutdown( "foo", false );
198 }
199
200 function testOutputStringString() {
201 $this->m->output( "foo" );
202 $this->m->output( "bar" );
203 $this->assertOutputPrePostShutdown( "foobar", false );
204 }
205
206 function testOutputStringNL() {
207 $this->m->output( "foo\n" );
208 $this->assertOutputPrePostShutdown( "foo\n", false );
209 }
210
211 function testOutputStringNLNL() {
212 $this->m->output( "foo\n\n" );
213 $this->assertOutputPrePostShutdown( "foo\n\n", false );
214 }
215
216 function testOutputStringNLString() {
217 $this->m->output( "foo\nbar" );
218 $this->assertOutputPrePostShutdown( "foo\nbar", false );
219 }
220
221 function testOutputStringNLStringNL() {
222 $this->m->output( "foo\nbar\n" );
223 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
224 }
225
226 function testOutputStringNLStringNLLinewise() {
227 $this->m->output( "foo\n" );
228 $this->m->output( "bar\n" );
229 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
230 }
231
232 function testOutputStringNLStringNLArbitrary() {
233 $this->m->output( "" );
234 $this->m->output( "foo" );
235 $this->m->output( "" );
236 $this->m->output( "\n" );
237 $this->m->output( "ba" );
238 $this->m->output( "" );
239 $this->m->output( "r\n" );
240 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
241 }
242
243 function testOutputStringNLStringNLArbitraryAgain() {
244 $this->m->output( "" );
245 $this->m->output( "foo" );
246 $this->m->output( "" );
247 $this->m->output( "\nb" );
248 $this->m->output( "a" );
249 $this->m->output( "" );
250 $this->m->output( "r\n" );
251 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
252 }
253
254 function testOutputWNullChannelEmpty() {
255 $this->m->output( "", null );
256 $this->assertOutputPrePostShutdown( "", false );
257 }
258
259 function testOutputWNullChannelString() {
260 $this->m->output( "foo", null );
261 $this->assertOutputPrePostShutdown( "foo", false );
262 }
263
264 function testOutputWNullChannelStringString() {
265 $this->m->output( "foo", null );
266 $this->m->output( "bar", null );
267 $this->assertOutputPrePostShutdown( "foobar", false );
268 }
269
270 function testOutputWNullChannelStringNL() {
271 $this->m->output( "foo\n", null );
272 $this->assertOutputPrePostShutdown( "foo\n", false );
273 }
274
275 function testOutputWNullChannelStringNLNL() {
276 $this->m->output( "foo\n\n", null );
277 $this->assertOutputPrePostShutdown( "foo\n\n", false );
278 }
279
280 function testOutputWNullChannelStringNLString() {
281 $this->m->output( "foo\nbar", null );
282 $this->assertOutputPrePostShutdown( "foo\nbar", false );
283 }
284
285 function testOutputWNullChannelStringNLStringNL() {
286 $this->m->output( "foo\nbar\n", null );
287 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
288 }
289
290 function testOutputWNullChannelStringNLStringNLLinewise() {
291 $this->m->output( "foo\n", null );
292 $this->m->output( "bar\n", null );
293 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
294 }
295
296 function testOutputWNullChannelStringNLStringNLArbitrary() {
297 $this->m->output( "", null );
298 $this->m->output( "foo", null );
299 $this->m->output( "", null );
300 $this->m->output( "\n", null );
301 $this->m->output( "ba", null );
302 $this->m->output( "", null );
303 $this->m->output( "r\n", null );
304 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
305 }
306
307 function testOutputWNullChannelStringNLStringNLArbitraryAgain() {
308 $this->m->output( "", null );
309 $this->m->output( "foo", null );
310 $this->m->output( "", null );
311 $this->m->output( "\nb", null );
312 $this->m->output( "a", null );
313 $this->m->output( "", null );
314 $this->m->output( "r\n", null );
315 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
316 }
317
318 function testOutputWChannelString() {
319 $this->m->output( "foo", "bazChannel" );
320 $this->assertOutputPrePostShutdown( "foo", true );
321 }
322
323 function testOutputWChannelStringNL() {
324 $this->m->output( "foo\n", "bazChannel" );
325 $this->assertOutputPrePostShutdown( "foo", true );
326 }
327
328 function testOutputWChannelStringNLNL() {
329 // If this test fails, note that output takes strings with double line
330 // endings (although output's implementation in this situation calls
331 // outputChanneled with a string ending in a nl ... which is not allowed
332 // according to the documentation of outputChanneled)
333 $this->m->output( "foo\n\n", "bazChannel" );
334 $this->assertOutputPrePostShutdown( "foo\n", true );
335 }
336
337 function testOutputWChannelStringNLString() {
338 $this->m->output( "foo\nbar", "bazChannel" );
339 $this->assertOutputPrePostShutdown( "foo\nbar", true );
340 }
341
342 function testOutputWChannelStringNLStringNL() {
343 $this->m->output( "foo\nbar\n", "bazChannel" );
344 $this->assertOutputPrePostShutdown( "foo\nbar", true );
345 }
346
347 function testOutputWChannelStringNLStringNLLinewise() {
348 $this->m->output( "foo\n", "bazChannel" );
349 $this->m->output( "bar\n", "bazChannel" );
350 $this->assertOutputPrePostShutdown( "foobar", true );
351 }
352
353 function testOutputWChannelStringNLStringNLArbitrary() {
354 $this->m->output( "", "bazChannel" );
355 $this->m->output( "foo", "bazChannel" );
356 $this->m->output( "", "bazChannel" );
357 $this->m->output( "\n", "bazChannel" );
358 $this->m->output( "ba", "bazChannel" );
359 $this->m->output( "", "bazChannel" );
360 $this->m->output( "r\n", "bazChannel" );
361 $this->assertOutputPrePostShutdown( "foobar", true );
362 }
363
364 function testOutputWChannelStringNLStringNLArbitraryAgain() {
365 $this->m->output( "", "bazChannel" );
366 $this->m->output( "foo", "bazChannel" );
367 $this->m->output( "", "bazChannel" );
368 $this->m->output( "\nb", "bazChannel" );
369 $this->m->output( "a", "bazChannel" );
370 $this->m->output( "", "bazChannel" );
371 $this->m->output( "r\n", "bazChannel" );
372 $this->assertOutputPrePostShutdown( "foo\nbar", true );
373 }
374
375 function testOutputWMultipleChannelsChannelChange() {
376 $this->m->output( "foo", "bazChannel" );
377 $this->m->output( "bar", "bazChannel" );
378 $this->m->output( "qux", "quuxChannel" );
379 $this->m->output( "corge", "bazChannel" );
380 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
381 }
382
383 function testOutputWMultipleChannelsChannelChangeNL() {
384 $this->m->output( "foo", "bazChannel" );
385 $this->m->output( "bar\n", "bazChannel" );
386 $this->m->output( "qux\n", "quuxChannel" );
387 $this->m->output( "corge", "bazChannel" );
388 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
389 }
390
391 function testOutputWAndWOChannelStringStartWO() {
392 $this->m->output( "foo" );
393 $this->m->output( "bar", "bazChannel" );
394 $this->m->output( "qux" );
395 $this->m->output( "quux", "bazChannel" );
396 $this->assertOutputPrePostShutdown( "foobar\nquxquux", true );
397 }
398
399 function testOutputWAndWOChannelStringStartW() {
400 $this->m->output( "foo", "bazChannel" );
401 $this->m->output( "bar" );
402 $this->m->output( "qux", "bazChannel" );
403 $this->m->output( "quux" );
404 $this->assertOutputPrePostShutdown( "foo\nbarqux\nquux", false );
405 }
406
407 function testOutputWChannelTypeSwitch() {
408 $this->m->output( "foo", 1 );
409 $this->m->output( "bar", 1.0 );
410 $this->assertOutputPrePostShutdown( "foo\nbar", true );
411 }
412
413 function testOutputIntermittentEmpty() {
414 $this->m->output( "foo" );
415 $this->m->output( "" );
416 $this->m->output( "bar" );
417 $this->assertOutputPrePostShutdown( "foobar", false );
418 }
419
420 function testOutputIntermittentFalse() {
421 $this->m->output( "foo" );
422 $this->m->output( false );
423 $this->m->output( "bar" );
424 $this->assertOutputPrePostShutdown( "foobar", false );
425 }
426
427 function testOutputIntermittentFalseAfterOtherChannel() {
428 $this->m->output( "qux", "quuxChannel" );
429 $this->m->output( "foo" );
430 $this->m->output( false );
431 $this->m->output( "bar" );
432 $this->assertOutputPrePostShutdown( "qux\nfoobar", false );
433 }
434
435 function testOutputWNullChannelIntermittentEmpty() {
436 $this->m->output( "foo", null );
437 $this->m->output( "", null );
438 $this->m->output( "bar", null );
439 $this->assertOutputPrePostShutdown( "foobar", false );
440 }
441
442 function testOutputWNullChannelIntermittentFalse() {
443 $this->m->output( "foo", null );
444 $this->m->output( false, null );
445 $this->m->output( "bar", null );
446 $this->assertOutputPrePostShutdown( "foobar", false );
447 }
448
449 function testOutputWChannelIntermittentEmpty() {
450 $this->m->output( "foo", "bazChannel" );
451 $this->m->output( "", "bazChannel" );
452 $this->m->output( "bar", "bazChannel" );
453 $this->assertOutputPrePostShutdown( "foobar", true );
454 }
455
456 function testOutputWChannelIntermittentFalse() {
457 $this->m->output( "foo", "bazChannel" );
458 $this->m->output( false, "bazChannel" );
459 $this->m->output( "bar", "bazChannel" );
460 $this->assertOutputPrePostShutdown( "foobar", true );
461 }
462
463 // Note that (per documentation) outputChanneled does take strings that end
464 // in \n, hence we do not test such strings.
465
466 function testOutputChanneledEmpty() {
467 $this->m->outputChanneled( "" );
468 $this->assertOutputPrePostShutdown( "\n", false );
469 }
470
471 function testOutputChanneledString() {
472 $this->m->outputChanneled( "foo" );
473 $this->assertOutputPrePostShutdown( "foo\n", false );
474 }
475
476 function testOutputChanneledStringString() {
477 $this->m->outputChanneled( "foo" );
478 $this->m->outputChanneled( "bar" );
479 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
480 }
481
482 function testOutputChanneledStringNLString() {
483 $this->m->outputChanneled( "foo\nbar" );
484 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
485 }
486
487 function testOutputChanneledStringNLStringNLArbitraryAgain() {
488 $this->m->outputChanneled( "" );
489 $this->m->outputChanneled( "foo" );
490 $this->m->outputChanneled( "" );
491 $this->m->outputChanneled( "\nb" );
492 $this->m->outputChanneled( "a" );
493 $this->m->outputChanneled( "" );
494 $this->m->outputChanneled( "r" );
495 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
496 }
497
498 function testOutputChanneledWNullChannelEmpty() {
499 $this->m->outputChanneled( "", null );
500 $this->assertOutputPrePostShutdown( "\n", false );
501 }
502
503 function testOutputChanneledWNullChannelString() {
504 $this->m->outputChanneled( "foo", null );
505 $this->assertOutputPrePostShutdown( "foo\n", false );
506 }
507
508 function testOutputChanneledWNullChannelStringString() {
509 $this->m->outputChanneled( "foo", null );
510 $this->m->outputChanneled( "bar", null );
511 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
512 }
513
514 function testOutputChanneledWNullChannelStringNLString() {
515 $this->m->outputChanneled( "foo\nbar", null );
516 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
517 }
518
519 function testOutputChanneledWNullChannelStringNLStringNLArbitraryAgain() {
520 $this->m->outputChanneled( "", null );
521 $this->m->outputChanneled( "foo", null );
522 $this->m->outputChanneled( "", null );
523 $this->m->outputChanneled( "\nb", null );
524 $this->m->outputChanneled( "a", null );
525 $this->m->outputChanneled( "", null );
526 $this->m->outputChanneled( "r", null );
527 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
528 }
529
530 function testOutputChanneledWChannelString() {
531 $this->m->outputChanneled( "foo", "bazChannel" );
532 $this->assertOutputPrePostShutdown( "foo", true );
533 }
534
535 function testOutputChanneledWChannelStringNLString() {
536 $this->m->outputChanneled( "foo\nbar", "bazChannel" );
537 $this->assertOutputPrePostShutdown( "foo\nbar", true );
538 }
539
540 function testOutputChanneledWChannelStringString() {
541 $this->m->outputChanneled( "foo", "bazChannel" );
542 $this->m->outputChanneled( "bar", "bazChannel" );
543 $this->assertOutputPrePostShutdown( "foobar", true );
544 }
545
546 function testOutputChanneledWChannelStringNLStringNLArbitraryAgain() {
547 $this->m->outputChanneled( "", "bazChannel" );
548 $this->m->outputChanneled( "foo", "bazChannel" );
549 $this->m->outputChanneled( "", "bazChannel" );
550 $this->m->outputChanneled( "\nb", "bazChannel" );
551 $this->m->outputChanneled( "a", "bazChannel" );
552 $this->m->outputChanneled( "", "bazChannel" );
553 $this->m->outputChanneled( "r", "bazChannel" );
554 $this->assertOutputPrePostShutdown( "foo\nbar", true );
555 }
556
557 function testOutputChanneledWMultipleChannelsChannelChange() {
558 $this->m->outputChanneled( "foo", "bazChannel" );
559 $this->m->outputChanneled( "bar", "bazChannel" );
560 $this->m->outputChanneled( "qux", "quuxChannel" );
561 $this->m->outputChanneled( "corge", "bazChannel" );
562 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
563 }
564
565 function testOutputChanneledWMultipleChannelsChannelChangeEnclosedNull() {
566 $this->m->outputChanneled( "foo", "bazChannel" );
567 $this->m->outputChanneled( "bar", null );
568 $this->m->outputChanneled( "qux", null );
569 $this->m->outputChanneled( "corge", "bazChannel" );
570 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
571 }
572
573 function testOutputChanneledWMultipleChannelsChannelAfterNullChange() {
574 $this->m->outputChanneled( "foo", "bazChannel" );
575 $this->m->outputChanneled( "bar", null );
576 $this->m->outputChanneled( "qux", null );
577 $this->m->outputChanneled( "corge", "quuxChannel" );
578 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
579 }
580
581 function testOutputChanneledWAndWOChannelStringStartWO() {
582 $this->m->outputChanneled( "foo" );
583 $this->m->outputChanneled( "bar", "bazChannel" );
584 $this->m->outputChanneled( "qux" );
585 $this->m->outputChanneled( "quux", "bazChannel" );
586 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux", true );
587 }
588
589 function testOutputChanneledWAndWOChannelStringStartW() {
590 $this->m->outputChanneled( "foo", "bazChannel" );
591 $this->m->outputChanneled( "bar" );
592 $this->m->outputChanneled( "qux", "bazChannel" );
593 $this->m->outputChanneled( "quux" );
594 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux\n", false );
595 }
596
597 function testOutputChanneledWChannelTypeSwitch() {
598 $this->m->outputChanneled( "foo", 1 );
599 $this->m->outputChanneled( "bar", 1.0 );
600 $this->assertOutputPrePostShutdown( "foo\nbar", true );
601 }
602
603 function testOutputChanneledWOChannelIntermittentEmpty() {
604 $this->m->outputChanneled( "foo" );
605 $this->m->outputChanneled( "" );
606 $this->m->outputChanneled( "bar" );
607 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
608 }
609
610 function testOutputChanneledWOChannelIntermittentFalse() {
611 $this->m->outputChanneled( "foo" );
612 $this->m->outputChanneled( false );
613 $this->m->outputChanneled( "bar" );
614 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
615 }
616
617 function testOutputChanneledWNullChannelIntermittentEmpty() {
618 $this->m->outputChanneled( "foo", null );
619 $this->m->outputChanneled( "", null );
620 $this->m->outputChanneled( "bar", null );
621 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
622 }
623
624 function testOutputChanneledWNullChannelIntermittentFalse() {
625 $this->m->outputChanneled( "foo", null );
626 $this->m->outputChanneled( false, null );
627 $this->m->outputChanneled( "bar", null );
628 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
629 }
630
631 function testOutputChanneledWChannelIntermittentEmpty() {
632 $this->m->outputChanneled( "foo", "bazChannel" );
633 $this->m->outputChanneled( "", "bazChannel" );
634 $this->m->outputChanneled( "bar", "bazChannel" );
635 $this->assertOutputPrePostShutdown( "foobar", true );
636 }
637
638 function testOutputChanneledWChannelIntermittentFalse() {
639 $this->m->outputChanneled( "foo", "bazChannel" );
640 $this->m->outputChanneled( false, "bazChannel" );
641 $this->m->outputChanneled( "bar", "bazChannel" );
642 $this->assertOutputPrePostShutdown( "foo\nbar", true );
643 }
644
645 function testCleanupChanneledClean() {
646 $this->m->cleanupChanneled();
647 $this->assertOutputPrePostShutdown( "", false );
648 }
649
650 function testCleanupChanneledAfterOutput() {
651 $this->m->output( "foo" );
652 $this->m->cleanupChanneled();
653 $this->assertOutputPrePostShutdown( "foo", false );
654 }
655
656 function testCleanupChanneledAfterOutputWNullChannel() {
657 $this->m->output( "foo", null );
658 $this->m->cleanupChanneled();
659 $this->assertOutputPrePostShutdown( "foo", false );
660 }
661
662 function testCleanupChanneledAfterOutputWChannel() {
663 $this->m->output( "foo", "bazChannel" );
664 $this->m->cleanupChanneled();
665 $this->assertOutputPrePostShutdown( "foo\n", false );
666 }
667
668 function testCleanupChanneledAfterNLOutput() {
669 $this->m->output( "foo\n" );
670 $this->m->cleanupChanneled();
671 $this->assertOutputPrePostShutdown( "foo\n", false );
672 }
673
674 function testCleanupChanneledAfterNLOutputWNullChannel() {
675 $this->m->output( "foo\n", null );
676 $this->m->cleanupChanneled();
677 $this->assertOutputPrePostShutdown( "foo\n", false );
678 }
679
680 function testCleanupChanneledAfterNLOutputWChannel() {
681 $this->m->output( "foo\n", "bazChannel" );
682 $this->m->cleanupChanneled();
683 $this->assertOutputPrePostShutdown( "foo\n", false );
684 }
685
686 function testCleanupChanneledAfterOutputChanneledWOChannel() {
687 $this->m->outputChanneled( "foo" );
688 $this->m->cleanupChanneled();
689 $this->assertOutputPrePostShutdown( "foo\n", false );
690 }
691
692 function testCleanupChanneledAfterOutputChanneledWNullChannel() {
693 $this->m->outputChanneled( "foo", null );
694 $this->m->cleanupChanneled();
695 $this->assertOutputPrePostShutdown( "foo\n", false );
696 }
697
698 function testCleanupChanneledAfterOutputChanneledWChannel() {
699 $this->m->outputChanneled( "foo", "bazChannel" );
700 $this->m->cleanupChanneled();
701 $this->assertOutputPrePostShutdown( "foo\n", false );
702 }
703
704 function testMultipleMaintenanceObjectsInteractionOutput() {
705 $m2 = new MaintenanceFixup( $this );
706
707 $this->m->output( "foo" );
708 $m2->output( "bar" );
709
710 $this->assertEquals( "foobar", $this->getActualOutput(),
711 "Output before shutdown simulation (m2)" );
712 $m2->simulateShutdown();
713 $this->assertOutputPrePostShutdown( "foobar", false );
714 }
715
716 function testMultipleMaintenanceObjectsInteractionOutputWNullChannel() {
717 $m2 = new MaintenanceFixup( $this );
718
719 $this->m->output( "foo", null );
720 $m2->output( "bar", null );
721
722 $this->assertEquals( "foobar", $this->getActualOutput(),
723 "Output before shutdown simulation (m2)" );
724 $m2->simulateShutdown();
725 $this->assertOutputPrePostShutdown( "foobar", false );
726 }
727
728 function testMultipleMaintenanceObjectsInteractionOutputWChannel() {
729 $m2 = new MaintenanceFixup( $this );
730
731 $this->m->output( "foo", "bazChannel" );
732 $m2->output( "bar", "bazChannel" );
733
734 $this->assertEquals( "foobar", $this->getActualOutput(),
735 "Output before shutdown simulation (m2)" );
736 $m2->simulateShutdown();
737 $this->assertOutputPrePostShutdown( "foobar\n", true );
738 }
739
740 function testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL() {
741 $m2 = new MaintenanceFixup( $this );
742
743 $this->m->output( "foo\n", null );
744 $m2->output( "bar\n", null );
745
746 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
747 "Output before shutdown simulation (m2)" );
748 $m2->simulateShutdown();
749 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
750 }
751
752 function testMultipleMaintenanceObjectsInteractionOutputWChannelNL() {
753 $m2 = new MaintenanceFixup( $this );
754
755 $this->m->output( "foo\n", "bazChannel" );
756 $m2->output( "bar\n", "bazChannel" );
757
758 $this->assertEquals( "foobar", $this->getActualOutput(),
759 "Output before shutdown simulation (m2)" );
760 $m2->simulateShutdown();
761 $this->assertOutputPrePostShutdown( "foobar\n", true );
762 }
763
764 function testMultipleMaintenanceObjectsInteractionOutputChanneled() {
765 $m2 = new MaintenanceFixup( $this );
766
767 $this->m->outputChanneled( "foo" );
768 $m2->outputChanneled( "bar" );
769
770 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
771 "Output before shutdown simulation (m2)" );
772 $m2->simulateShutdown();
773 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
774 }
775
776 function testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel() {
777 $m2 = new MaintenanceFixup( $this );
778
779 $this->m->outputChanneled( "foo", null );
780 $m2->outputChanneled( "bar", null );
781
782 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
783 "Output before shutdown simulation (m2)" );
784 $m2->simulateShutdown();
785 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
786 }
787
788 function testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel() {
789 $m2 = new MaintenanceFixup( $this );
790
791 $this->m->outputChanneled( "foo", "bazChannel" );
792 $m2->outputChanneled( "bar", "bazChannel" );
793
794 $this->assertEquals( "foobar", $this->getActualOutput(),
795 "Output before shutdown simulation (m2)" );
796 $m2->simulateShutdown();
797 $this->assertOutputPrePostShutdown( "foobar\n", true );
798 }
799
800 function testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel() {
801 $m2 = new MaintenanceFixup( $this );
802
803 $this->m->outputChanneled( "foo", "bazChannel" );
804 $m2->outputChanneled( "bar", "bazChannel" );
805
806 $this->assertEquals( "foobar", $this->getActualOutput(),
807 "Output before first cleanup" );
808 $this->m->cleanupChanneled();
809 $this->assertEquals( "foobar\n", $this->getActualOutput(),
810 "Output after first cleanup" );
811 $m2->cleanupChanneled();
812 $this->assertEquals( "foobar\n\n", $this->getActualOutput(),
813 "Output after second cleanup" );
814
815 $m2->simulateShutdown();
816 $this->assertOutputPrePostShutdown( "foobar\n\n", false );
817 }
818
819
820 }