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