Merge "Update Parser to use ContentLanguage"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / RevisionStoreFactoryTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Storage;
4
5 use ActorMigration;
6 use CommentStore;
7 use MediaWiki\Logger\Spi as LoggerSpi;
8 use MediaWiki\Storage\BlobStore;
9 use MediaWiki\Storage\BlobStoreFactory;
10 use MediaWiki\Storage\NameTableStore;
11 use MediaWiki\Storage\RevisionStore;
12 use MediaWiki\Storage\RevisionStoreFactory;
13 use MediaWiki\Storage\SqlBlobStore;
14 use MediaWikiTestCase;
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 MediaWikiTestCase {
23
24 public function testValidConstruction_doesntCauseErrors() {
25 new RevisionStoreFactory(
26 $this->getMockLoadBalancerFactory(),
27 $this->getMockBlobStoreFactory(),
28 $this->getHashWANObjectCache(),
29 $this->getMockCommentStore(),
30 ActorMigration::newMigration(),
31 MIGRATION_OLD,
32 $this->getMockLoggerSpi(),
33 true
34 );
35 $this->assertTrue( true );
36 }
37
38 public function provideWikiIds() {
39 yield [ true ];
40 yield [ false ];
41 yield [ 'somewiki' ];
42 yield [ 'somewiki', MIGRATION_OLD , false ];
43 yield [ 'somewiki', MIGRATION_NEW , true ];
44 }
45
46 /**
47 * @dataProvider provideWikiIds
48 */
49 public function testGetRevisionStore(
50 $wikiId,
51 $mcrMigrationStage = MIGRATION_OLD,
52 $contentHandlerUseDb = true
53 ) {
54 $lbFactory = $this->getMockLoadBalancerFactory();
55 $blobStoreFactory = $this->getMockBlobStoreFactory();
56 $cache = $this->getHashWANObjectCache();
57 $commentStore = $this->getMockCommentStore();
58 $actorMigration = ActorMigration::newMigration();
59 $loggerProvider = $this->getMockLoggerSpi();
60
61 $factory = new RevisionStoreFactory(
62 $lbFactory,
63 $blobStoreFactory,
64 $cache,
65 $commentStore,
66 $actorMigration,
67 $mcrMigrationStage,
68 $loggerProvider,
69 $contentHandlerUseDb
70 );
71
72 $store = $factory->getRevisionStore( $wikiId );
73 $wrapper = TestingAccessWrapper::newFromObject( $store );
74
75 // ensure the correct object type is returned
76 $this->assertInstanceOf( RevisionStore::class, $store );
77
78 // ensure the RevisionStore is for the given wikiId
79 $this->assertSame( $wikiId, $wrapper->wikiId );
80
81 // ensure all other required services are correctly set
82 $this->assertSame( $cache, $wrapper->cache );
83 $this->assertSame( $commentStore, $wrapper->commentStore );
84 $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage );
85 $this->assertSame( $actorMigration, $wrapper->actorMigration );
86 $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
87
88 $this->assertInstanceOf( ILoadBalancer::class, $wrapper->loadBalancer );
89 $this->assertInstanceOf( BlobStore::class, $wrapper->blobStore );
90 $this->assertInstanceOf( NameTableStore::class, $wrapper->contentModelStore );
91 $this->assertInstanceOf( NameTableStore::class, $wrapper->slotRoleStore );
92 $this->assertInstanceOf( LoggerInterface::class, $wrapper->logger );
93 }
94
95 /**
96 * @return \PHPUnit_Framework_MockObject_MockObject|ILoadBalancer
97 */
98 private function getMockLoadBalancer() {
99 return $this->getMockBuilder( ILoadBalancer::class )
100 ->disableOriginalConstructor()->getMock();
101 }
102
103 /**
104 * @return \PHPUnit_Framework_MockObject_MockObject|ILBFactory
105 */
106 private function getMockLoadBalancerFactory() {
107 $mock = $this->getMockBuilder( ILBFactory::class )
108 ->disableOriginalConstructor()->getMock();
109
110 $mock->method( 'getMainLB' )
111 ->willReturnCallback( function () {
112 return $this->getMockLoadBalancer();
113 } );
114
115 return $mock;
116 }
117
118 /**
119 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
120 */
121 private function getMockSqlBlobStore() {
122 return $this->getMockBuilder( SqlBlobStore::class )
123 ->disableOriginalConstructor()->getMock();
124 }
125
126 /**
127 * @return \PHPUnit_Framework_MockObject_MockObject|BlobStoreFactory
128 */
129 private function getMockBlobStoreFactory() {
130 $mock = $this->getMockBuilder( BlobStoreFactory::class )
131 ->disableOriginalConstructor()->getMock();
132
133 $mock->method( 'newSqlBlobStore' )
134 ->willReturnCallback( function () {
135 return $this->getMockSqlBlobStore();
136 } );
137
138 return $mock;
139 }
140
141 /**
142 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
143 */
144 private function getMockCommentStore() {
145 return $this->getMockBuilder( CommentStore::class )
146 ->disableOriginalConstructor()->getMock();
147 }
148
149 private function getHashWANObjectCache() {
150 return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
151 }
152
153 /**
154 * @return \PHPUnit_Framework_MockObject_MockObject|LoggerSpi
155 */
156 private function getMockLoggerSpi() {
157 $mock = $this->getMock( LoggerSpi::class );
158
159 $mock->method( 'getLogger' )
160 ->willReturn( new NullLogger() );
161
162 return $mock;
163 }
164
165 }