7 use InvalidArgumentException;
21 use Wikimedia\TestingAccessWrapper;
45 $WANObjectCache =
null
69 ->disableOriginalConstructor()->getMock();
77 ->disableOriginalConstructor()->getMock();
85 ->disableOriginalConstructor()->getMock();
93 ->disableOriginalConstructor()->getMock();
101 ->disableOriginalConstructor()->getMock();
130 if ( $expectedFail ) {
141 $nameTables->getContentModels(),
142 $nameTables->getSlotRoles(),
149 $this->assertSame( $contentHandlerDb, $store->getContentHandlerUseDB() );
158 $this->
setService(
'DBLoadBalancer', $mockLoadBalancer );
162 $mockLoadBalancer->expects( $this->atLeastOnce() )
163 ->method(
'getConnection' )
167 $db->expects( $this->at( 0 ) )
168 ->method(
'selectRow' )
174 ->willReturn( (
object)[
175 'page_namespace' =>
'1',
176 'page_title' =>
'Food',
180 $title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
182 $this->assertSame( 1,
$title->getNamespace() );
183 $this->assertSame(
'Food',
$title->getDBkey() );
192 $this->
setService(
'DBLoadBalancer', $mockLoadBalancer );
197 $mockLoadBalancer->expects( $this->exactly( 2 ) )
198 ->method(
'getConnection' )
201 $mockLoadBalancer->expects( $this->atLeastOnce() )
202 ->method(
'getConnectionRef' )
206 $db->expects( $this->at( 0 ) )
207 ->method(
'selectRow' )
213 ->willReturn(
false );
216 $db->expects( $this->at( 1 ) )
217 ->method(
'selectRow' )
219 [
'revision',
'page' ],
223 ->willReturn(
false );
226 $db->expects( $this->at( 2 ) )
227 ->method(
'selectRow' )
233 ->willReturn( (
object)[
234 'page_namespace' =>
'2',
235 'page_title' =>
'Foodey',
239 $title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
241 $this->assertSame( 2,
$title->getNamespace() );
242 $this->assertSame(
'Foodey',
$title->getDBkey() );
251 $this->
setService(
'DBLoadBalancer', $mockLoadBalancer );
255 $mockLoadBalancer->expects( $this->atLeastOnce() )
256 ->method(
'getConnection' )
259 $mockLoadBalancer->expects( $this->atLeastOnce() )
260 ->method(
'getConnectionRef' )
264 $db->expects( $this->at( 0 ) )
265 ->method(
'selectRow' )
271 ->willReturn(
false );
274 $db->expects( $this->at( 1 ) )
275 ->method(
'selectRow' )
277 [
'revision',
'page' ],
281 ->willReturn( (
object)[
282 'page_namespace' =>
'1',
283 'page_title' =>
'Food2',
287 $title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
289 $this->assertSame( 1,
$title->getNamespace() );
290 $this->assertSame(
'Food2',
$title->getDBkey() );
299 $this->
setService(
'DBLoadBalancer', $mockLoadBalancer );
304 $mockLoadBalancer->expects( $this->exactly( 2 ) )
305 ->method(
'getConnection' )
308 $mockLoadBalancer->expects( $this->atLeastOnce() )
309 ->method(
'getConnectionRef' )
313 $db->expects( $this->at( 0 ) )
314 ->method(
'selectRow' )
320 ->willReturn(
false );
323 $db->expects( $this->at( 1 ) )
324 ->method(
'selectRow' )
326 [
'revision',
'page' ],
330 ->willReturn(
false );
333 $db->expects( $this->at( 2 ) )
334 ->method(
'selectRow' )
340 ->willReturn(
false );
343 $db->expects( $this->at( 3 ) )
344 ->method(
'selectRow' )
346 [
'revision',
'page' ],
350 ->willReturn( (
object)[
351 'page_namespace' =>
'2',
352 'page_title' =>
'Foodey',
356 $title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
358 $this->assertSame( 2,
$title->getNamespace() );
359 $this->assertSame(
'Foodey',
$title->getDBkey() );
368 $this->
setService(
'DBLoadBalancer', $mockLoadBalancer );
376 foreach ( [
'getConnection',
'getConnectionRef' ]
as $method ) {
377 $mockLoadBalancer->expects( $this->exactly( 2 ) )
379 ->willReturnCallback(
function ( $masterOrReplica )
use (
$db ) {
380 static $callCounter = 0;
383 if ( $callCounter === 1 ) {
384 $this->assertSame(
DB_REPLICA, $masterOrReplica );
385 } elseif ( $callCounter === 2 ) {
386 $this->assertSame(
DB_MASTER, $masterOrReplica );
392 foreach ( [ 0, 2 ]
as $counter ) {
393 $db->expects( $this->at( $counter ) )
394 ->method(
'selectRow' )
400 ->willReturn(
false );
403 foreach ( [ 1, 3 ]
as $counter ) {
404 $db->expects( $this->at( $counter ) )
405 ->method(
'selectRow' )
407 [
'revision',
'page' ],
411 ->willReturn(
false );
417 $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
421 yield
'windows-1252, old_flags is empty' => [
426 'old_text' =>
"S\xF6me Content",
431 yield
'windows-1252, old_flags is null' => [
436 'old_text' =>
"S\xF6me Content",
449 $this->markTestSkipped(
'No longer applicable with MCR schema' );
460 $record = $store->newRevisionFromRow(
466 $this->assertSame( $text, $record->getContent(
SlotRecord::MAIN )->serialize() );
474 $this->markTestSkipped(
'No longer applicable with MCR schema' );
478 'old_flags' =>
'utf-8',
479 'old_text' =>
'Söme Content',
490 $record = $store->newRevisionFromRow(
495 $this->assertSame(
'Söme Content', $record->getContent(
SlotRecord::MAIN )->serialize() );
502 'rev_timestamp' =>
'20110101000000',
503 'rev_user_text' =>
'Tester',
505 'rev_minor_edit' => 0,
508 'rev_parent_id' => 0,
509 'rev_sha1' =>
'deadbeef',
510 'rev_comment_text' =>
'Testing',
511 'rev_comment_data' =>
'{}',
512 'rev_comment_cid' => 111,
513 'page_namespace' => 0,
514 'page_title' =>
'TEST',
517 'page_is_redirect' => 0,
519 'user_name' =>
'Tester',
528 'old_text' =>
'Hello World',
529 'old_flags' =>
'utf-8',
531 } elseif ( !isset( $row[
'content'] ) && isset( $array[
'old_text'] ) ) {
557 if ( $expectException ) {
565 $nameTables =
$services->getNameTableStoreFactory();
566 $contentModelStore = $nameTables->getContentModels();
567 $slotRoleStore = $nameTables->getSlotRoles();
568 $slotRoleRegistry =
$services->getSlotRoleRegistry();
574 $nameTables->getContentModels(),
575 $nameTables->getSlotRoles(),
580 if ( !$expectException ) {
581 $store = TestingAccessWrapper::newFromObject( $store );
582 $this->assertSame( $loadBalancer, $store->loadBalancer );
583 $this->assertSame( $blobStore, $store->blobStore );
584 $this->assertSame(
$cache, $store->cache );
585 $this->assertSame( $commentStore, $store->commentStore );
586 $this->assertSame( $contentModelStore, $store->contentModelStore );
587 $this->assertSame( $slotRoleStore, $store->slotRoleStore );
588 $this->assertSame( $migration, $store->mcrMigrationStage );