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() {
47 yield
[ 'somewiki', MIGRATION_OLD
, false ];
48 yield
[ 'somewiki', MIGRATION_NEW
, true ];
52 * @dataProvider provideWikiIds
53 * @covers \MediaWiki\Revision\RevisionStoreFactory::getRevisionStore
55 public function testGetRevisionStore(
57 $mcrMigrationStage = MIGRATION_OLD
,
58 $contentHandlerUseDb = true
60 $lbFactory = $this->getMockLoadBalancerFactory();
61 $blobStoreFactory = $this->getMockBlobStoreFactory();
62 $nameTableStoreFactory = $this->getNameTableStoreFactory();
63 $slotRoleRegistry = $this->getMockSlotRoleRegistry();
64 $cache = $this->getHashWANObjectCache();
65 $commentStore = $this->getMockCommentStore();
66 $actorMigration = ActorMigration
::newMigration();
67 $logger = new NullLogger();
69 $factory = new RevisionStoreFactory(
72 $nameTableStoreFactory,
82 $store = $factory->getRevisionStore( $dbDomain );
83 $wrapper = TestingAccessWrapper
::newFromObject( $store );
85 // ensure the correct object type is returned
86 $this->assertInstanceOf( RevisionStore
::class, $store );
88 // ensure the RevisionStore is for the given wikiId
89 $this->assertSame( $dbDomain, $wrapper->dbDomain
);
91 // ensure all other required services are correctly set
92 $this->assertSame( $cache, $wrapper->cache
);
93 $this->assertSame( $commentStore, $wrapper->commentStore
);
94 $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage
);
95 $this->assertSame( $actorMigration, $wrapper->actorMigration
);
96 $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
98 $this->assertInstanceOf( ILoadBalancer
::class, $wrapper->loadBalancer
);
99 $this->assertInstanceOf( BlobStore
::class, $wrapper->blobStore
);
100 $this->assertInstanceOf( NameTableStore
::class, $wrapper->contentModelStore
);
101 $this->assertInstanceOf( NameTableStore
::class, $wrapper->slotRoleStore
);
102 $this->assertInstanceOf( LoggerInterface
::class, $wrapper->logger
);
106 * @return \PHPUnit_Framework_MockObject_MockObject|ILoadBalancer
108 private function getMockLoadBalancer() {
109 return $this->getMockBuilder( ILoadBalancer
::class )
110 ->disableOriginalConstructor()->getMock();
114 * @return \PHPUnit_Framework_MockObject_MockObject|ILBFactory
116 private function getMockLoadBalancerFactory() {
117 $mock = $this->getMockBuilder( ILBFactory
::class )
118 ->disableOriginalConstructor()->getMock();
120 $mock->method( 'getMainLB' )
121 ->willReturnCallback( function () {
122 return $this->getMockLoadBalancer();
129 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
131 private function getMockSqlBlobStore() {
132 return $this->getMockBuilder( SqlBlobStore
::class )
133 ->disableOriginalConstructor()->getMock();
137 * @return \PHPUnit_Framework_MockObject_MockObject|BlobStoreFactory
139 private function getMockBlobStoreFactory() {
140 $mock = $this->getMockBuilder( BlobStoreFactory
::class )
141 ->disableOriginalConstructor()->getMock();
143 $mock->method( 'newSqlBlobStore' )
144 ->willReturnCallback( function () {
145 return $this->getMockSqlBlobStore();
152 * @return SlotRoleRegistry
154 private function getMockSlotRoleRegistry() {
155 return $this->createMock( SlotRoleRegistry
::class );
159 * @return NameTableStoreFactory
161 private function getNameTableStoreFactory() {
162 return new NameTableStoreFactory(
163 $this->getMockLoadBalancerFactory(),
164 $this->getHashWANObjectCache(),
169 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
171 private function getMockCommentStore() {
172 return $this->getMockBuilder( CommentStore
::class )
173 ->disableOriginalConstructor()->getMock();
176 private function getHashWANObjectCache() {
177 return new WANObjectCache( [ 'cache' => new \
HashBagOStuff() ] );