Push all DeferredUpdates to POSTSEND queue when running that queue
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / DeferredUpdatesTest.php
index d7ad1d1..3b42356 100644 (file)
@@ -13,8 +13,7 @@ class DeferredUpdatesTest extends MediaWikiTestCase {
                $post = DeferredUpdates::POSTSEND;
                $all = DeferredUpdates::ALL;
 
-               $update = $this->getMockBuilder( 'DeferrableUpdate' )
-                             ->getMock();
+               $update = $this->getMock( DeferrableUpdate::class );
                $update->expects( $this->never() )
                        ->method( 'doUpdate' );
 
@@ -193,4 +192,30 @@ class DeferredUpdatesTest extends MediaWikiTestCase {
 
                DeferredUpdates::doUpdates();
        }
+
+       public function testPresendAddOnPostsendRun() {
+               $this->setMwGlobals( 'wgCommandLineMode', true );
+
+               $x = false;
+               $y = false;
+               wfGetLBFactory()->commitMasterChanges( __METHOD__ ); // clear anything
+
+               DeferredUpdates::addCallableUpdate(
+                       function () use ( &$x, &$y ) {
+                               $x = true;
+                               DeferredUpdates::addCallableUpdate(
+                                       function () use ( &$y ) {
+                                               $y = true;
+                                       },
+                                       DeferredUpdates::PRESEND
+                               );
+                       },
+                       DeferredUpdates::POSTSEND
+               );
+
+               DeferredUpdates::doUpdates();
+
+               $this->assertTrue( $x, "Outer POSTSEND update ran" );
+               $this->assertTrue( $y, "Nested PRESEND update ran" );
+       }
 }