Merge "tests: Remove unused TableCleanupTest class"
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / DeferredUpdatesTest.php
1 <?php
2
3 class DeferredUpdatesTest extends MediaWikiTestCase {
4 public function testDoUpdatesWeb() {
5 $this->setMwGlobals( 'wgCommandLineMode', false );
6
7 $updates = array(
8 '1' => 'deferred update 1',
9 '2' => 'deferred update 2',
10 '3' => 'deferred update 3',
11 '2-1' => 'deferred update 1 within deferred update 2',
12 );
13 DeferredUpdates::addCallableUpdate(
14 function () use ( $updates ) {
15 echo $updates['1'];
16 }
17 );
18 DeferredUpdates::addCallableUpdate(
19 function () use ( $updates ) {
20 echo $updates['2'];
21 DeferredUpdates::addCallableUpdate(
22 function () use ( $updates ) {
23 echo $updates['2-1'];
24 }
25 );
26 }
27 );
28 DeferredUpdates::addCallableUpdate(
29 function () use ( $updates ) {
30 echo $updates[3];
31 }
32 );
33
34 $this->expectOutputString( implode( '', $updates ) );
35
36 DeferredUpdates::doUpdates();
37
38 $x = null;
39 $y = null;
40 DeferredUpdates::addCallableUpdate(
41 function () use ( &$x ) {
42 $x = 'Sherity';
43 },
44 DeferredUpdates::PRESEND
45 );
46 DeferredUpdates::addCallableUpdate(
47 function () use ( &$y ) {
48 $y = 'Marychu';
49 },
50 DeferredUpdates::POSTSEND
51 );
52
53 $this->assertNull( $x, "Update not run yet" );
54 $this->assertNull( $y, "Update not run yet" );
55
56 DeferredUpdates::doUpdates( 'run', DeferredUpdates::PRESEND );
57 $this->assertEquals( "Sherity", $x, "PRESEND update ran" );
58 $this->assertNull( $y, "POSTSEND update not run yet" );
59
60 DeferredUpdates::doUpdates( 'run', DeferredUpdates::POSTSEND );
61 $this->assertEquals( "Marychu", $y, "POSTSEND update ran" );
62 }
63
64 public function testDoUpdatesCLI() {
65 $this->setMwGlobals( 'wgCommandLineMode', true );
66
67 $updates = array(
68 '1' => 'deferred update 1',
69 '2' => 'deferred update 2',
70 '2-1' => 'deferred update 1 within deferred update 2',
71 '3' => 'deferred update 3',
72 );
73 DeferredUpdates::addCallableUpdate(
74 function () use ( $updates ) {
75 echo $updates['1'];
76 }
77 );
78 DeferredUpdates::addCallableUpdate(
79 function () use ( $updates ) {
80 echo $updates['2'];
81 DeferredUpdates::addCallableUpdate(
82 function () use ( $updates ) {
83 echo $updates['2-1'];
84 }
85 );
86 }
87 );
88 DeferredUpdates::addCallableUpdate(
89 function () use ( $updates ) {
90 echo $updates[3];
91 }
92 );
93
94 $this->expectOutputString( implode( '', $updates ) );
95
96 DeferredUpdates::doUpdates();
97 }
98 }