Merge "Remove "dash" case in preprocessToObj"
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / DeferredUpdatesTest.php
index 999ad03..6b41707 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 class DeferredUpdatesTest extends MediaWikiTestCase {
 
        /**
@@ -205,7 +207,8 @@ class DeferredUpdatesTest extends MediaWikiTestCase {
                ];
 
                // clear anything
-               wfGetLBFactory()->commitMasterChanges( __METHOD__ );
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $lbFactory->commitMasterChanges( __METHOD__ );
 
                DeferredUpdates::addCallableUpdate(
                        function () use ( $updates ) {
@@ -269,7 +272,8 @@ class DeferredUpdatesTest extends MediaWikiTestCase {
                $x = false;
                $y = false;
                // clear anything
-               wfGetLBFactory()->commitMasterChanges( __METHOD__ );
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $lbFactory->commitMasterChanges( __METHOD__ );
 
                DeferredUpdates::addCallableUpdate(
                        function () use ( &$x, &$y ) {
@@ -289,4 +293,46 @@ class DeferredUpdatesTest extends MediaWikiTestCase {
                $this->assertTrue( $x, "Outer POSTSEND update ran" );
                $this->assertTrue( $y, "Nested PRESEND update ran" );
        }
+
+       /**
+        * @covers DeferredUpdates::runUpdate
+        */
+       public function testRunUpdateTransactionScope() {
+               $this->setMwGlobals( 'wgCommandLineMode', false );
+
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $this->assertFalse( $lbFactory->hasTransactionRound(), 'Initial state' );
+
+               $ran = 0;
+               DeferredUpdates::addCallableUpdate( function () use ( &$ran, $lbFactory ) {
+                       $ran++;
+                       $this->assertTrue( $lbFactory->hasTransactionRound(), 'Has transaction' );
+               } );
+               DeferredUpdates::doUpdates();
+
+               $this->assertSame( 1, $ran, 'Update ran' );
+               $this->assertFalse( $lbFactory->hasTransactionRound(), 'Final state' );
+       }
+
+       /**
+        * @covers DeferredUpdates::runUpdate
+        * @covers TransactionRoundDefiningUpdate::getOrigin
+        */
+       public function testRunOuterScopeUpdate() {
+               $this->setMwGlobals( 'wgCommandLineMode', false );
+
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $this->assertFalse( $lbFactory->hasTransactionRound(), 'Initial state' );
+
+               $ran = 0;
+               DeferredUpdates::addUpdate( new TransactionRoundDefiningUpdate(
+                       function () use ( &$ran, $lbFactory ) {
+                               $ran++;
+                               $this->assertFalse( $lbFactory->hasTransactionRound(), 'No transaction' );
+                       } )
+               );
+               DeferredUpdates::doUpdates();
+
+               $this->assertSame( 1, $ran, 'Update ran' );
+       }
 }