.pipeline/config.yaml: rename dev stage to publish
[lhc/web/wiklou.git] / tests / phpunit / includes / Revision / RevisionStoreFactoryTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Revision;
4
5 use ActorMigration;
6 use CommentStore;
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;
17 use WANObjectCache;
18 use Wikimedia\Rdbms\ILBFactory;
19 use Wikimedia\Rdbms\ILoadBalancer;
20 use Wikimedia\TestingAccessWrapper;
21
22 class RevisionStoreFactoryTest extends \MediaWikiIntegrationTestCase {
23
24 /**
25 * @covers \MediaWiki\Revision\RevisionStoreFactory::__construct
26 */
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(),
36 MIGRATION_OLD,
37 new NullLogger(),
38 true
39 );
40 $this->assertTrue( true );
41 }
42
43 public function provideWikiIds() {
44 yield [ true ];
45 yield [ false ];
46 yield [ 'somewiki' ];
47 yield [ 'somewiki', MIGRATION_OLD , false ];
48 yield [ 'somewiki', MIGRATION_NEW , true ];
49 }
50
51 /**
52 * @dataProvider provideWikiIds
53 * @covers \MediaWiki\Revision\RevisionStoreFactory::getRevisionStore
54 */
55 public function testGetRevisionStore(
56 $dbDomain,
57 $mcrMigrationStage = MIGRATION_OLD,
58 $contentHandlerUseDb = true
59 ) {
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();
68
69 $factory = new RevisionStoreFactory(
70 $lbFactory,
71 $blobStoreFactory,
72 $nameTableStoreFactory,
73 $slotRoleRegistry,
74 $cache,
75 $commentStore,
76 $actorMigration,
77 $mcrMigrationStage,
78 $logger,
79 $contentHandlerUseDb
80 );
81
82 $store = $factory->getRevisionStore( $dbDomain );
83 $wrapper = TestingAccessWrapper::newFromObject( $store );
84
85 // ensure the correct object type is returned
86 $this->assertInstanceOf( RevisionStore::class, $store );
87
88 // ensure the RevisionStore is for the given wikiId
89 $this->assertSame( $dbDomain, $wrapper->dbDomain );
90
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() );
97
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 );
103 }
104
105 /**
106 * @return \PHPUnit_Framework_MockObject_MockObject|ILoadBalancer
107 */
108 private function getMockLoadBalancer() {
109 return $this->getMockBuilder( ILoadBalancer::class )
110 ->disableOriginalConstructor()->getMock();
111 }
112
113 /**
114 * @return \PHPUnit_Framework_MockObject_MockObject|ILBFactory
115 */
116 private function getMockLoadBalancerFactory() {
117 $mock = $this->getMockBuilder( ILBFactory::class )
118 ->disableOriginalConstructor()->getMock();
119
120 $mock->method( 'getMainLB' )
121 ->willReturnCallback( function () {
122 return $this->getMockLoadBalancer();
123 } );
124
125 return $mock;
126 }
127
128 /**
129 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
130 */
131 private function getMockSqlBlobStore() {
132 return $this->getMockBuilder( SqlBlobStore::class )
133 ->disableOriginalConstructor()->getMock();
134 }
135
136 /**
137 * @return \PHPUnit_Framework_MockObject_MockObject|BlobStoreFactory
138 */
139 private function getMockBlobStoreFactory() {
140 $mock = $this->getMockBuilder( BlobStoreFactory::class )
141 ->disableOriginalConstructor()->getMock();
142
143 $mock->method( 'newSqlBlobStore' )
144 ->willReturnCallback( function () {
145 return $this->getMockSqlBlobStore();
146 } );
147
148 return $mock;
149 }
150
151 /**
152 * @return SlotRoleRegistry
153 */
154 private function getMockSlotRoleRegistry() {
155 return $this->createMock( SlotRoleRegistry::class );
156 }
157
158 /**
159 * @return NameTableStoreFactory
160 */
161 private function getNameTableStoreFactory() {
162 return new NameTableStoreFactory(
163 $this->getMockLoadBalancerFactory(),
164 $this->getHashWANObjectCache(),
165 new NullLogger() );
166 }
167
168 /**
169 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
170 */
171 private function getMockCommentStore() {
172 return $this->getMockBuilder( CommentStore::class )
173 ->disableOriginalConstructor()->getMock();
174 }
175
176 private function getHashWANObjectCache() {
177 return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
178 }
179
180 }