2017-11-15 12:02:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-09-20 17:29:04 +00:00
|
|
|
namespace MediaWiki\Tests\Revision;
|
2017-11-15 12:02:40 +00:00
|
|
|
|
2020-01-18 20:25:04 +00:00
|
|
|
use MediaWiki\Content\IContentHandlerFactory;
|
2018-01-29 14:25:49 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionAccessException;
|
|
|
|
|
use MediaWiki\Revision\RevisionStore;
|
2017-11-15 12:02:40 +00:00
|
|
|
use MediaWiki\Storage\SqlBlobStore;
|
2020-06-30 15:09:24 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2020-01-10 00:00:51 +00:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-11-15 12:02:40 +00:00
|
|
|
use WANObjectCache;
|
2018-06-08 20:16:21 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\ILoadBalancer;
|
2017-11-15 12:02:40 +00:00
|
|
|
use Wikimedia\Rdbms\LoadBalancer;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\MaintainableDBConnRef;
|
2017-11-15 12:02:40 +00:00
|
|
|
|
2019-02-27 21:26:17 +00:00
|
|
|
/**
|
|
|
|
|
* Tests RevisionStore
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class RevisionStoreTest extends MediaWikiIntegrationTestCase {
|
2017-11-15 12:02:40 +00:00
|
|
|
|
|
|
|
|
/**
|
2021-01-09 11:03:10 +00:00
|
|
|
* @param LoadBalancer|null $loadBalancer
|
|
|
|
|
* @param SqlBlobStore|null $blobStore
|
|
|
|
|
* @param WANObjectCache|null $WANObjectCache
|
2017-11-15 12:02:40 +00:00
|
|
|
*
|
|
|
|
|
* @return RevisionStore
|
|
|
|
|
*/
|
|
|
|
|
private function getRevisionStore(
|
|
|
|
|
$loadBalancer = null,
|
|
|
|
|
$blobStore = null,
|
|
|
|
|
$WANObjectCache = null
|
|
|
|
|
) {
|
|
|
|
|
return new RevisionStore(
|
2018-06-11 09:16:48 +00:00
|
|
|
$loadBalancer ?: $this->getMockLoadBalancer(),
|
|
|
|
|
$blobStore ?: $this->getMockSqlBlobStore(),
|
|
|
|
|
$WANObjectCache ?: $this->getHashWANObjectCache(),
|
2017-09-12 17:12:29 +00:00
|
|
|
MediaWikiServices::getInstance()->getCommentStore(),
|
2018-01-29 15:54:02 +00:00
|
|
|
MediaWikiServices::getInstance()->getContentModelStore(),
|
|
|
|
|
MediaWikiServices::getInstance()->getSlotRoleStore(),
|
2018-11-19 11:39:56 +00:00
|
|
|
MediaWikiServices::getInstance()->getSlotRoleRegistry(),
|
2020-01-18 20:25:04 +00:00
|
|
|
MediaWikiServices::getInstance()->getActorMigration(),
|
2021-02-04 02:43:09 +00:00
|
|
|
MediaWikiServices::getInstance()->getActorStore(),
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getMockContentHandlerFactory(),
|
|
|
|
|
MediaWikiServices::getInstance()->getHookContainer()
|
2017-11-15 12:02:40 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-06 04:54:59 +00:00
|
|
|
* @return MockObject|LoadBalancer
|
2017-11-15 12:02:40 +00:00
|
|
|
*/
|
|
|
|
|
private function getMockLoadBalancer() {
|
|
|
|
|
return $this->getMockBuilder( LoadBalancer::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:56:29 +00:00
|
|
|
/**
|
2019-10-06 04:54:59 +00:00
|
|
|
* @return MockObject|IDatabase
|
2018-01-11 16:56:29 +00:00
|
|
|
*/
|
|
|
|
|
private function getMockDatabase() {
|
2018-06-08 20:16:21 +00:00
|
|
|
return $this->getMockBuilder( IDatabase::class )
|
2018-01-11 16:56:29 +00:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-24 19:29:56 +00:00
|
|
|
/**
|
|
|
|
|
* @param ILoadBalancer $mockLoadBalancer
|
|
|
|
|
* @param Database $db
|
|
|
|
|
* @return callable
|
|
|
|
|
*/
|
|
|
|
|
private function getMockDBConnRefCallback( ILoadBalancer $mockLoadBalancer, IDatabase $db ) {
|
2021-02-06 19:30:20 +00:00
|
|
|
return static function ( $i, $g, $domain, $flg ) use ( $mockLoadBalancer, $db ) {
|
2019-07-24 19:29:56 +00:00
|
|
|
return new MaintainableDBConnRef( $mockLoadBalancer, $db, $i );
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 12:02:40 +00:00
|
|
|
/**
|
2019-10-06 04:54:59 +00:00
|
|
|
* @return MockObject|SqlBlobStore
|
2017-11-15 12:02:40 +00:00
|
|
|
*/
|
|
|
|
|
private function getMockSqlBlobStore() {
|
|
|
|
|
return $this->getMockBuilder( SqlBlobStore::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 15:54:02 +00:00
|
|
|
private function getHashWANObjectCache() {
|
|
|
|
|
return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
|
2017-09-12 17:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-18 20:25:04 +00:00
|
|
|
/**
|
|
|
|
|
* @return IContentHandlerFactory|MockObject
|
|
|
|
|
*/
|
|
|
|
|
public function getMockContentHandlerFactory(): IContentHandlerFactory {
|
|
|
|
|
return $this->createMock( IContentHandlerFactory::class );
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 19:53:33 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::getTitle
|
|
|
|
|
*/
|
2018-01-11 16:56:29 +00:00
|
|
|
public function testGetTitle_successFromPageId() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
2019-07-24 19:29:56 +00:00
|
|
|
// RevisionStore uses getConnectionRef
|
|
|
|
|
$mockLoadBalancer->expects( $this->any() )
|
|
|
|
|
->method( 'getConnectionRef' )
|
|
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
|
|
|
|
// Title calls wfGetDB() which uses getMaintenanceConnectionRef
|
2018-01-11 16:56:29 +00:00
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
2019-07-24 19:29:56 +00:00
|
|
|
->method( 'getMaintenanceConnectionRef' )
|
|
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
2018-01-11 16:56:29 +00:00
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '1',
|
|
|
|
|
'page_title' => 'Food',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 1, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Food', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 19:53:33 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::getTitle
|
|
|
|
|
*/
|
2018-01-10 16:05:46 +00:00
|
|
|
public function testGetTitle_successFromPageIdOnFallback() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
2019-07-24 19:29:56 +00:00
|
|
|
// Title calls wfGetDB() which uses getMaintenanceConnectionRef
|
2018-01-10 16:05:46 +00:00
|
|
|
// Assert that the first call uses a REPLICA and the second falls back to master
|
|
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getConnectionRef' )
|
2019-07-24 19:29:56 +00:00
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
|
|
|
|
// Title calls wfGetDB() which uses getMaintenanceConnectionRef
|
|
|
|
|
$mockLoadBalancer->expects( $this->exactly( 2 ) )
|
|
|
|
|
->method( 'getMaintenanceConnectionRef' )
|
|
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
2018-01-10 16:05:46 +00:00
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// First select using rev_id, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 1 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// Second call to Title::newFromID, no result
|
|
|
|
|
$db->expects( $this->at( 2 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '2',
|
|
|
|
|
'page_title' => 'Foodey',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 2, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Foodey', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 19:53:33 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::getTitle
|
|
|
|
|
*/
|
2018-01-11 16:56:29 +00:00
|
|
|
public function testGetTitle_successFromRevId() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
2019-04-07 00:28:14 +00:00
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
2019-07-24 18:07:18 +00:00
|
|
|
->method( 'getConnectionRef' )
|
2019-07-24 19:29:56 +00:00
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
|
|
|
|
// Title calls wfGetDB() which uses getMaintenanceConnectionRef
|
|
|
|
|
// RevisionStore getTitle uses getMaintenanceConnectionRef
|
|
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getMaintenanceConnectionRef' )
|
|
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
2018-01-11 16:56:29 +00:00
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// First select using rev_id, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 1 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '1',
|
|
|
|
|
'page_title' => 'Food2',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 1, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Food2', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 19:53:33 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::getTitle
|
|
|
|
|
*/
|
2018-01-10 16:05:46 +00:00
|
|
|
public function testGetTitle_successFromRevIdOnFallback() {
|
2018-01-11 16:56:29 +00:00
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
2018-01-10 16:05:46 +00:00
|
|
|
// Assert that the first call uses a REPLICA and the second falls back to master
|
2019-07-24 19:29:56 +00:00
|
|
|
// RevisionStore uses getMaintenanceConnectionRef
|
2018-01-11 16:56:29 +00:00
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getConnectionRef' )
|
2019-07-24 19:29:56 +00:00
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
|
|
|
|
// Title calls wfGetDB() which uses getMaintenanceConnectionRef
|
|
|
|
|
$mockLoadBalancer->expects( $this->exactly( 2 ) )
|
|
|
|
|
->method( 'getMaintenanceConnectionRef' )
|
|
|
|
|
->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
|
2018-01-11 16:56:29 +00:00
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// First select using rev_id, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 1 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
2018-01-10 16:05:46 +00:00
|
|
|
// Second call to Title::newFromID, no result
|
|
|
|
|
$db->expects( $this->at( 2 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// Second select using rev_id, result
|
|
|
|
|
$db->expects( $this->at( 3 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '2',
|
|
|
|
|
'page_title' => 'Foodey',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 2, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Foodey', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-20 17:29:04 +00:00
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::getTitle
|
2018-01-10 16:05:46 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetTitle_correctFallbackAndthrowsExceptionAfterFallbacks() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
2019-07-24 19:29:56 +00:00
|
|
|
// Title calls wfGetDB() which uses getMaintenanceConnectionRef
|
2018-01-10 16:05:46 +00:00
|
|
|
// Assert that the first call uses a REPLICA and the second falls back to master
|
|
|
|
|
|
|
|
|
|
// RevisionStore getTitle uses getConnectionRef
|
2019-07-24 19:29:56 +00:00
|
|
|
// Title::newFromID uses getMaintenanceConnectionRef
|
|
|
|
|
foreach ( [
|
|
|
|
|
'getConnectionRef', 'getMaintenanceConnectionRef'
|
|
|
|
|
] as $method ) {
|
2018-01-10 16:05:46 +00:00
|
|
|
$mockLoadBalancer->expects( $this->exactly( 2 ) )
|
|
|
|
|
->method( $method )
|
|
|
|
|
->willReturnCallback( function ( $masterOrReplica ) use ( $db ) {
|
|
|
|
|
static $callCounter = 0;
|
|
|
|
|
$callCounter++;
|
|
|
|
|
// The first call should be to a REPLICA, and the second a MASTER.
|
|
|
|
|
if ( $callCounter === 1 ) {
|
|
|
|
|
$this->assertSame( DB_REPLICA, $masterOrReplica );
|
|
|
|
|
} elseif ( $callCounter === 2 ) {
|
|
|
|
|
$this->assertSame( DB_MASTER, $masterOrReplica );
|
|
|
|
|
}
|
|
|
|
|
return $db;
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
// First and third call to Title::newFromID, faking no result
|
|
|
|
|
foreach ( [ 0, 2 ] as $counter ) {
|
|
|
|
|
$db->expects( $this->at( $counter ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( [ 1, 3 ] as $counter ) {
|
|
|
|
|
$db->expects( $this->at( $counter ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:56:29 +00:00
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
|
2019-10-05 15:39:46 +00:00
|
|
|
$this->expectException( RevisionAccessException::class );
|
2018-01-11 16:56:29 +00:00
|
|
|
$store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 12:02:40 +00:00
|
|
|
}
|