3 class DeferredUpdatesTest
extends MediaWikiTestCase
{
6 * @covers DeferredUpdates::getPendingUpdates
8 public function testGetPendingUpdates() {
9 # Prevent updates from running
10 $this->setMwGlobals( 'wgCommandLineMode', false );
12 $pre = DeferredUpdates
::PRESEND
;
13 $post = DeferredUpdates
::POSTSEND
;
14 $all = DeferredUpdates
::ALL
;
16 $update = $this->getMockBuilder( 'DeferrableUpdate' )
18 $update->expects( $this->never() )
19 ->method( 'doUpdate' );
21 DeferredUpdates
::addUpdate( $update, $pre );
22 $this->assertCount( 1, DeferredUpdates
::getPendingUpdates( $pre ) );
23 $this->assertCount( 0, DeferredUpdates
::getPendingUpdates( $post ) );
24 $this->assertCount( 1, DeferredUpdates
::getPendingUpdates( $all ) );
25 $this->assertCount( 1, DeferredUpdates
::getPendingUpdates() );
26 DeferredUpdates
::clearPendingUpdates();
27 $this->assertCount( 0, DeferredUpdates
::getPendingUpdates() );
29 DeferredUpdates
::addUpdate( $update, $post );
30 $this->assertCount( 0, DeferredUpdates
::getPendingUpdates( $pre ) );
31 $this->assertCount( 1, DeferredUpdates
::getPendingUpdates( $post ) );
32 $this->assertCount( 1, DeferredUpdates
::getPendingUpdates( $all ) );
33 $this->assertCount( 1, DeferredUpdates
::getPendingUpdates() );
34 DeferredUpdates
::clearPendingUpdates();
35 $this->assertCount( 0, DeferredUpdates
::getPendingUpdates() );
38 public function testDoUpdatesWeb() {
39 $this->setMwGlobals( 'wgCommandLineMode', false );
42 '1' => "deferred update 1;\n",
43 '2' => "deferred update 2;\n",
44 '2-1' => "deferred update 1 within deferred update 2;\n",
45 '2-2' => "deferred update 2 within deferred update 2;\n",
46 '3' => "deferred update 3;\n",
47 '3-1' => "deferred update 1 within deferred update 3;\n",
48 '3-2' => "deferred update 2 within deferred update 3;\n",
49 '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
50 '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
52 DeferredUpdates
::addCallableUpdate(
53 function () use ( $updates ) {
57 DeferredUpdates
::addCallableUpdate(
58 function () use ( $updates ) {
60 DeferredUpdates
::addCallableUpdate(
61 function () use ( $updates ) {
65 DeferredUpdates
::addCallableUpdate(
66 function () use ( $updates ) {
72 DeferredUpdates
::addCallableUpdate(
73 function () use ( $updates ) {
75 DeferredUpdates
::addCallableUpdate(
76 function () use ( $updates ) {
78 DeferredUpdates
::addCallableUpdate(
79 function () use ( $updates ) {
80 echo $updates['3-1-1'];
85 DeferredUpdates
::addCallableUpdate(
86 function () use ( $updates ) {
88 DeferredUpdates
::addCallableUpdate(
89 function () use ( $updates ) {
90 echo $updates['3-2-1'];
98 $this->assertEquals( 3, DeferredUpdates
::pendingUpdatesCount() );
100 $this->expectOutputString( implode( '', $updates ) );
102 DeferredUpdates
::doUpdates();
106 DeferredUpdates
::addCallableUpdate(
107 function () use ( &$x ) {
110 DeferredUpdates
::PRESEND
112 DeferredUpdates
::addCallableUpdate(
113 function () use ( &$y ) {
116 DeferredUpdates
::POSTSEND
119 $this->assertNull( $x, "Update not run yet" );
120 $this->assertNull( $y, "Update not run yet" );
122 DeferredUpdates
::doUpdates( 'run', DeferredUpdates
::PRESEND
);
123 $this->assertEquals( "Sherity", $x, "PRESEND update ran" );
124 $this->assertNull( $y, "POSTSEND update not run yet" );
126 DeferredUpdates
::doUpdates( 'run', DeferredUpdates
::POSTSEND
);
127 $this->assertEquals( "Marychu", $y, "POSTSEND update ran" );
130 public function testDoUpdatesCLI() {
131 $this->setMwGlobals( 'wgCommandLineMode', true );
133 '1' => "deferred update 1;\n",
134 '2' => "deferred update 2;\n",
135 '2-1' => "deferred update 1 within deferred update 2;\n",
136 '2-2' => "deferred update 2 within deferred update 2;\n",
137 '3' => "deferred update 3;\n",
138 '3-1' => "deferred update 1 within deferred update 3;\n",
139 '3-2' => "deferred update 2 within deferred update 3;\n",
140 '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
141 '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
144 wfGetLBFactory()->commitMasterChanges( __METHOD__
); // clear anything
146 DeferredUpdates
::addCallableUpdate(
147 function () use ( $updates ) {
151 DeferredUpdates
::addCallableUpdate(
152 function () use ( $updates ) {
154 DeferredUpdates
::addCallableUpdate(
155 function () use ( $updates ) {
156 echo $updates['2-1'];
159 DeferredUpdates
::addCallableUpdate(
160 function () use ( $updates ) {
161 echo $updates['2-2'];
166 DeferredUpdates
::addCallableUpdate(
167 function () use ( $updates ) {
169 DeferredUpdates
::addCallableUpdate(
170 function () use ( $updates ) {
171 echo $updates['3-1'];
172 DeferredUpdates
::addCallableUpdate(
173 function () use ( $updates ) {
174 echo $updates['3-1-1'];
179 DeferredUpdates
::addCallableUpdate(
180 function () use ( $updates ) {
181 echo $updates['3-2'];
182 DeferredUpdates
::addCallableUpdate(
183 function () use ( $updates ) {
184 echo $updates['3-2-1'];
192 $this->expectOutputString( implode( '', $updates ) );
194 DeferredUpdates
::doUpdates();