3 namespace MediaWiki\Tests\Revision
;
7 use MediaWiki\Revision\RevisionStore
;
8 use MediaWiki\Revision\RevisionStoreFactory
;
9 use MediaWiki\Revision\SlotRoleRegistry
;
10 use MediaWiki\Storage\BlobStore
;
11 use MediaWiki\Storage\BlobStoreFactory
;
12 use MediaWiki\Storage\NameTableStore
;
13 use MediaWiki\Storage\NameTableStoreFactory
;
14 use MediaWiki\Storage\SqlBlobStore
;
15 use Psr\Log\LoggerInterface
;
16 use Psr\Log\NullLogger
;
18 use Wikimedia\Rdbms\ILBFactory
;
19 use Wikimedia\Rdbms\ILoadBalancer
;
20 use Wikimedia\TestingAccessWrapper
;
22 class RevisionStoreFactoryTest
extends \MediaWikiIntegrationTestCase
{
25 * @covers \MediaWiki\Revision\RevisionStoreFactory::__construct
27 public function testValidConstruction_doesntCauseErrors() {
28 new RevisionStoreFactory(
29 $this->getMockLoadBalancerFactory(),
30 $this->getMockBlobStoreFactory(),
31 $this->getNameTableStoreFactory(),
32 $this->getMockSlotRoleRegistry(),
33 $this->getHashWANObjectCache(),
34 $this->getMockCommentStore(),
35 ActorMigration
::newMigration(),
40 $this->assertTrue( true );
43 public function provideWikiIds() {
50 * @dataProvider provideWikiIds
51 * @covers \MediaWiki\Revision\RevisionStoreFactory::getRevisionStore
53 public function testGetRevisionStore(
55 $mcrMigrationStage = MIGRATION_NEW
,
56 $contentHandlerUseDb = true
58 $lbFactory = $this->getMockLoadBalancerFactory();
59 $blobStoreFactory = $this->getMockBlobStoreFactory();
60 $nameTableStoreFactory = $this->getNameTableStoreFactory();
61 $slotRoleRegistry = $this->getMockSlotRoleRegistry();
62 $cache = $this->getHashWANObjectCache();
63 $commentStore = $this->getMockCommentStore();
64 $actorMigration = ActorMigration
::newMigration();
65 $logger = new NullLogger();
67 $factory = new RevisionStoreFactory(
70 $nameTableStoreFactory,
80 $store = $factory->getRevisionStore( $dbDomain );
81 $wrapper = TestingAccessWrapper
::newFromObject( $store );
83 // ensure the correct object type is returned
84 $this->assertInstanceOf( RevisionStore
::class, $store );
86 // ensure the RevisionStore is for the given wikiId
87 $this->assertSame( $dbDomain, $wrapper->dbDomain
);
89 // ensure all other required services are correctly set
90 $this->assertSame( $cache, $wrapper->cache
);
91 $this->assertSame( $commentStore, $wrapper->commentStore
);
92 $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage
);
93 $this->assertSame( $actorMigration, $wrapper->actorMigration
);
94 $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
96 $this->assertInstanceOf( ILoadBalancer
::class, $wrapper->loadBalancer
);
97 $this->assertInstanceOf( BlobStore
::class, $wrapper->blobStore
);
98 $this->assertInstanceOf( NameTableStore
::class, $wrapper->contentModelStore
);
99 $this->assertInstanceOf( NameTableStore
::class, $wrapper->slotRoleStore
);
100 $this->assertInstanceOf( LoggerInterface
::class, $wrapper->logger
);
104 * @return \PHPUnit_Framework_MockObject_MockObject|ILoadBalancer
106 private function getMockLoadBalancer() {
107 return $this->getMockBuilder( ILoadBalancer
::class )
108 ->disableOriginalConstructor()->getMock();
112 * @return \PHPUnit_Framework_MockObject_MockObject|ILBFactory
114 private function getMockLoadBalancerFactory() {
115 $mock = $this->getMockBuilder( ILBFactory
::class )
116 ->disableOriginalConstructor()->getMock();
118 $mock->method( 'getMainLB' )
119 ->willReturnCallback( function () {
120 return $this->getMockLoadBalancer();
127 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
129 private function getMockSqlBlobStore() {
130 return $this->getMockBuilder( SqlBlobStore
::class )
131 ->disableOriginalConstructor()->getMock();
135 * @return \PHPUnit_Framework_MockObject_MockObject|BlobStoreFactory
137 private function getMockBlobStoreFactory() {
138 $mock = $this->getMockBuilder( BlobStoreFactory
::class )
139 ->disableOriginalConstructor()->getMock();
141 $mock->method( 'newSqlBlobStore' )
142 ->willReturnCallback( function () {
143 return $this->getMockSqlBlobStore();
150 * @return SlotRoleRegistry
152 private function getMockSlotRoleRegistry() {
153 return $this->createMock( SlotRoleRegistry
::class );
157 * @return NameTableStoreFactory
159 private function getNameTableStoreFactory() {
160 return new NameTableStoreFactory(
161 $this->getMockLoadBalancerFactory(),
162 $this->getHashWANObjectCache(),
167 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
169 private function getMockCommentStore() {
170 return $this->getMockBuilder( CommentStore
::class )
171 ->disableOriginalConstructor()->getMock();
174 private function getHashWANObjectCache() {
175 return new WANObjectCache( [ 'cache' => new \
HashBagOStuff() ] );