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