3 namespace MediaWiki\Tests\Storage
;
5 use CommentStoreComment
;
8 use InvalidArgumentException
;
10 use MediaWiki\Linker\LinkTarget
;
11 use MediaWiki\MediaWikiServices
;
12 use MediaWiki\Storage\BlobStoreFactory
;
13 use MediaWiki\Storage\IncompleteRevisionException
;
14 use MediaWiki\Storage\MutableRevisionRecord
;
15 use MediaWiki\Storage\RevisionRecord
;
16 use MediaWiki\Storage\RevisionStore
;
17 use MediaWiki\Storage\SlotRecord
;
18 use MediaWiki\Storage\SqlBlobStore
;
19 use MediaWikiTestCase
;
20 use PHPUnit_Framework_MockObject_MockObject
;
25 use Wikimedia\Rdbms\Database
;
26 use Wikimedia\Rdbms\DatabaseSqlite
;
27 use Wikimedia\Rdbms\FakeResultWrapper
;
28 use Wikimedia\Rdbms\LoadBalancer
;
29 use Wikimedia\Rdbms\TransactionProfiler
;
35 * @group RevisionStore
37 abstract class RevisionStoreDbTestBase
extends MediaWikiTestCase
{
42 abstract protected function getMcrMigrationStage();
47 protected function getContentHandlerUseDB() {
54 abstract protected function getMcrTablesToReset();
56 public function needsDB() {
60 public function setUp() {
62 $this->tablesUsed
[] = 'archive';
63 $this->tablesUsed
[] = 'page';
64 $this->tablesUsed
[] = 'revision';
65 $this->tablesUsed
[] = 'comment';
67 $this->tablesUsed +
= $this->getMcrTablesToReset();
70 'wgMultiContentRevisionSchemaMigrationStage',
71 $this->getMcrMigrationStage()
75 'wgContentHandlerUseDB',
76 $this->getContentHandlerUseDB()
79 $this->overrideMwServices();
82 protected function addCoreDBData() {
83 // Blank out. This would fail with a modified schema, and we don't need it.
87 * @return LoadBalancer|PHPUnit_Framework_MockObject_MockObject
89 private function getLoadBalancerMock( array $server ) {
90 $lb = $this->getMockBuilder( LoadBalancer
::class )
91 ->setMethods( [ 'reallyOpenConnection' ] )
92 ->setConstructorArgs( [ [ 'servers' => [ $server ] ] ] )
95 $lb->method( 'reallyOpenConnection' )->willReturnCallback(
96 function ( array $server, $dbNameOverride ) {
97 return $this->getDatabaseMock( $server );
105 * @return Database|PHPUnit_Framework_MockObject_MockObject
107 private function getDatabaseMock( array $params ) {
108 $db = $this->getMockBuilder( DatabaseSqlite
::class )
109 ->setMethods( [ 'select', 'doQuery', 'open', 'closeConnection', 'isOpen' ] )
110 ->setConstructorArgs( [ $params ] )
113 $db->method( 'select' )->willReturn( new FakeResultWrapper( [] ) );
114 $db->method( 'isOpen' )->willReturn( true );
119 public function provideDomainCheck() {
120 yield
[ false, 'test', '' ];
121 yield
[ 'test', 'test', '' ];
123 yield
[ false, 'test', 'foo_' ];
124 yield
[ 'test-foo_', 'test', 'foo_' ];
126 yield
[ false, 'dash-test', '' ];
127 yield
[ 'dash-test', 'dash-test', '' ];
129 yield
[ false, 'underscore_test', 'foo_' ];
130 yield
[ 'underscore_test-foo_', 'underscore_test', 'foo_' ];
134 * @dataProvider provideDomainCheck
135 * @covers \MediaWiki\Storage\RevisionStore::checkDatabaseWikiId
137 public function testDomainCheck( $wikiId, $dbName, $dbPrefix ) {
140 'wgDBname' => $dbName,
141 'wgDBprefix' => $dbPrefix,
145 $loadBalancer = $this->getLoadBalancerMock(
148 'dbDirectory' => '*dummy*',
150 'password' => 'test',
158 'trxProfiler' => new TransactionProfiler(),
159 'connLogger' => new \Psr\Log\
NullLogger(),
160 'queryLogger' => new \Psr\Log\
NullLogger(),
161 'errorLogger' => function () {
163 'deprecationLogger' => function () {
167 'tablePrefix' => $dbPrefix,
170 $db = $loadBalancer->getConnection( DB_REPLICA
);
172 /** @var SqlBlobStore $blobStore */
173 $blobStore = $this->getMockBuilder( SqlBlobStore
::class )
174 ->disableOriginalConstructor()
177 $store = new RevisionStore(
180 new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
181 MediaWikiServices
::getInstance()->getCommentStore(),
182 MediaWikiServices
::getInstance()->getContentModelStore(),
183 MediaWikiServices
::getInstance()->getSlotRoleStore(),
184 $this->getMcrMigrationStage(),
185 MediaWikiServices
::getInstance()->getActorMigration(),
189 $count = $store->countRevisionsByPageId( $db, 0 );
191 // Dummy check to make PhpUnit happy. We are really only interested in
192 // countRevisionsByPageId not failing due to the DB domain check.
193 $this->assertSame( 0, $count );
196 private function assertLinkTargetsEqual( LinkTarget
$l1, LinkTarget
$l2 ) {
197 $this->assertEquals( $l1->getDBkey(), $l2->getDBkey() );
198 $this->assertEquals( $l1->getNamespace(), $l2->getNamespace() );
199 $this->assertEquals( $l1->getFragment(), $l2->getFragment() );
200 $this->assertEquals( $l1->getInterwiki(), $l2->getInterwiki() );
203 private function assertRevisionRecordsEqual( RevisionRecord
$r1, RevisionRecord
$r2 ) {
204 $this->assertEquals( $r1->getUser()->getName(), $r2->getUser()->getName() );
205 $this->assertEquals( $r1->getUser()->getId(), $r2->getUser()->getId() );
206 $this->assertEquals( $r1->getComment(), $r2->getComment() );
207 $this->assertEquals( $r1->getPageAsLinkTarget(), $r2->getPageAsLinkTarget() );
208 $this->assertEquals( $r1->getTimestamp(), $r2->getTimestamp() );
209 $this->assertEquals( $r1->getVisibility(), $r2->getVisibility() );
210 $this->assertEquals( $r1->getSha1(), $r2->getSha1() );
211 $this->assertEquals( $r1->getParentId(), $r2->getParentId() );
212 $this->assertEquals( $r1->getSize(), $r2->getSize() );
213 $this->assertEquals( $r1->getPageId(), $r2->getPageId() );
214 $this->assertEquals( $r1->getSlotRoles(), $r2->getSlotRoles() );
215 $this->assertEquals( $r1->getWikiId(), $r2->getWikiId() );
216 $this->assertEquals( $r1->isMinor(), $r2->isMinor() );
217 foreach ( $r1->getSlotRoles() as $role ) {
218 $this->assertSlotRecordsEqual( $r1->getSlot( $role ), $r2->getSlot( $role ) );
219 $this->assertTrue( $r1->getContent( $role )->equals( $r2->getContent( $role ) ) );
222 RevisionRecord
::DELETED_TEXT
,
223 RevisionRecord
::DELETED_COMMENT
,
224 RevisionRecord
::DELETED_USER
,
225 RevisionRecord
::DELETED_RESTRICTED
,
227 $this->assertEquals( $r1->isDeleted( $field ), $r2->isDeleted( $field ) );
231 private function assertSlotRecordsEqual( SlotRecord
$s1, SlotRecord
$s2 ) {
232 $this->assertSame( $s1->getRole(), $s2->getRole() );
233 $this->assertSame( $s1->getModel(), $s2->getModel() );
234 $this->assertSame( $s1->getFormat(), $s2->getFormat() );
235 $this->assertSame( $s1->getSha1(), $s2->getSha1() );
236 $this->assertSame( $s1->getSize(), $s2->getSize() );
237 $this->assertTrue( $s1->getContent()->equals( $s2->getContent() ) );
239 $s1->hasRevision() ?
$this->assertSame( $s1->getRevision(), $s2->getRevision() ) : null;
240 $s1->hasAddress() ?
$this->assertSame( $s1->hasAddress(), $s2->hasAddress() ) : null;
243 private function assertRevisionCompleteness( RevisionRecord
$r ) {
244 foreach ( $r->getSlotRoles() as $role ) {
245 $this->assertSlotCompleteness( $r, $r->getSlot( $role ) );
249 private function assertSlotCompleteness( RevisionRecord
$r, SlotRecord
$slot ) {
250 $this->assertTrue( $slot->hasAddress() );
251 $this->assertSame( $r->getId(), $slot->getRevision() );
255 * @param mixed[] $details
257 * @return RevisionRecord
259 private function getRevisionRecordFromDetailsArray( $title, $details = [] ) {
260 // Convert some values that can't be provided by dataProviders
261 $page = WikiPage
::factory( $title );
262 if ( isset( $details['user'] ) && $details['user'] === true ) {
263 $details['user'] = $this->getTestUser()->getUser();
265 if ( isset( $details['page'] ) && $details['page'] === true ) {
266 $details['page'] = $page->getId();
268 if ( isset( $details['parent'] ) && $details['parent'] === true ) {
269 $details['parent'] = $page->getLatest();
272 // Create the RevisionRecord with any available data
273 $rev = new MutableRevisionRecord( $title );
274 isset( $details['slot'] ) ?
$rev->setSlot( $details['slot'] ) : null;
275 isset( $details['parent'] ) ?
$rev->setParentId( $details['parent'] ) : null;
276 isset( $details['page'] ) ?
$rev->setPageId( $details['page'] ) : null;
277 isset( $details['size'] ) ?
$rev->setSize( $details['size'] ) : null;
278 isset( $details['sha1'] ) ?
$rev->setSha1( $details['sha1'] ) : null;
279 isset( $details['comment'] ) ?
$rev->setComment( $details['comment'] ) : null;
280 isset( $details['timestamp'] ) ?
$rev->setTimestamp( $details['timestamp'] ) : null;
281 isset( $details['minor'] ) ?
$rev->setMinorEdit( $details['minor'] ) : null;
282 isset( $details['user'] ) ?
$rev->setUser( $details['user'] ) : null;
283 isset( $details['visibility'] ) ?
$rev->setVisibility( $details['visibility'] ) : null;
284 isset( $details['id'] ) ?
$rev->setId( $details['id'] ) : null;
289 public function provideInsertRevisionOn_successes() {
290 yield
'Bare minimum revision insertion' => [
291 Title
::newFromText( 'UTPage' ),
293 'slot' => SlotRecord
::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
295 'comment' => $this->getRandomCommentStoreComment(),
296 'timestamp' => '20171117010101',
300 yield
'Detailed revision insertion' => [
301 Title
::newFromText( 'UTPage' ),
303 'slot' => SlotRecord
::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
306 'comment' => $this->getRandomCommentStoreComment(),
307 'timestamp' => '20171117010101',
310 'visibility' => RevisionRecord
::DELETED_RESTRICTED
,
315 private function getRandomCommentStoreComment() {
316 return CommentStoreComment
::newUnsavedComment( __METHOD__
. '.' . rand( 0, 1000 ) );
320 * @dataProvider provideInsertRevisionOn_successes
321 * @covers \MediaWiki\Storage\RevisionStore::insertRevisionOn
322 * @covers \MediaWiki\Storage\RevisionStore::insertSlotRowOn
323 * @covers \MediaWiki\Storage\RevisionStore::insertContentRowOn
325 public function testInsertRevisionOn_successes(
327 array $revDetails = []
329 $this->getExistingTestPage( $title );
330 $rev = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
332 $this->overrideMwServices();
333 $store = MediaWikiServices
::getInstance()->getRevisionStore();
334 $return = $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER
) );
336 $this->assertLinkTargetsEqual( $title, $return->getPageAsLinkTarget() );
337 $this->assertRevisionRecordsEqual( $rev, $return );
338 $this->assertRevisionCompleteness( $return );
339 $this->assertRevisionExistsInDatabase( $return );
342 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
344 'revision', [ 'count(*)' ], [ 'rev_id' => $rev->getId() ], [ [ '1' ] ]
349 * @param SlotRecord $a
350 * @param SlotRecord $b
352 protected function assertSameSlotContent( SlotRecord
$a, SlotRecord
$b ) {
353 // Assert that the same blob address has been used.
354 $this->assertSame( $a->getAddress(), $b->getAddress() );
358 * @covers \MediaWiki\Storage\RevisionStore::insertRevisionOn
360 public function testInsertRevisionOn_blobAddressExists() {
361 $page = $this->getExistingTestPage();
362 $title = $page->getTitle();
364 'slot' => SlotRecord
::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
366 'comment' => $this->getRandomCommentStoreComment(),
367 'timestamp' => '20171117010101',
371 $this->overrideMwServices();
372 $store = MediaWikiServices
::getInstance()->getRevisionStore();
374 // Insert the first revision
375 $revOne = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
376 $firstReturn = $store->insertRevisionOn( $revOne, wfGetDB( DB_MASTER
) );
377 $this->assertLinkTargetsEqual( $title, $firstReturn->getPageAsLinkTarget() );
378 $this->assertRevisionRecordsEqual( $revOne, $firstReturn );
380 // Insert a second revision inheriting the same blob address
381 $revDetails['slot'] = SlotRecord
::newInherited( $firstReturn->getSlot( 'main' ) );
382 $revTwo = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
383 $secondReturn = $store->insertRevisionOn( $revTwo, wfGetDB( DB_MASTER
) );
384 $this->assertLinkTargetsEqual( $title, $secondReturn->getPageAsLinkTarget() );
385 $this->assertRevisionRecordsEqual( $revTwo, $secondReturn );
387 $firstMainSlot = $firstReturn->getSlot( 'main' );
388 $secondMainSlot = $secondReturn->getSlot( 'main' );
390 $this->assertSameSlotContent( $firstMainSlot, $secondMainSlot );
392 // And that different revisions have been created.
393 $this->assertNotSame( $firstReturn->getId(), $secondReturn->getId() );
395 // Make sure the slot rows reference the correct revision
396 $this->assertSame( $firstReturn->getId(), $firstMainSlot->getRevision() );
397 $this->assertSame( $secondReturn->getId(), $secondMainSlot->getRevision() );
400 public function provideInsertRevisionOn_failures() {
402 Title
::newFromText( 'UTPage' ),
404 'comment' => $this->getRandomCommentStoreComment(),
405 'timestamp' => '20171117010101',
408 new InvalidArgumentException( 'At least one slot needs to be defined!' )
410 yield
'slot that is not main slot' => [
411 Title
::newFromText( 'UTPage' ),
413 'slot' => SlotRecord
::newUnsaved( 'lalala', new WikitextContent( 'Chicken' ) ),
414 'comment' => $this->getRandomCommentStoreComment(),
415 'timestamp' => '20171117010101',
418 new InvalidArgumentException( 'Only the main slot is supported for now!' )
420 yield
'no timestamp' => [
421 Title
::newFromText( 'UTPage' ),
423 'slot' => SlotRecord
::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
424 'comment' => $this->getRandomCommentStoreComment(),
427 new IncompleteRevisionException( 'timestamp field must not be NULL!' )
429 yield
'no comment' => [
430 Title
::newFromText( 'UTPage' ),
432 'slot' => SlotRecord
::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
433 'timestamp' => '20171117010101',
436 new IncompleteRevisionException( 'comment must not be NULL!' )
439 Title
::newFromText( 'UTPage' ),
441 'slot' => SlotRecord
::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
442 'comment' => $this->getRandomCommentStoreComment(),
443 'timestamp' => '20171117010101',
445 new IncompleteRevisionException( 'user must not be NULL!' )
450 * @dataProvider provideInsertRevisionOn_failures
451 * @covers \MediaWiki\Storage\RevisionStore::insertRevisionOn
453 public function testInsertRevisionOn_failures(
455 array $revDetails = [],
458 $page = $this->getExistingTestPage( $title );
460 $rev = $this->getRevisionRecordFromDetailsArray( $title, $revDetails );
462 $store = MediaWikiServices
::getInstance()->getRevisionStore();
464 $this->setExpectedException(
465 get_class( $exception ),
466 $exception->getMessage(),
467 $exception->getCode()
469 $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER
) );
472 public function provideNewNullRevision() {
474 Title
::newFromText( __METHOD__
),
475 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment1' ),
479 Title
::newFromText( __METHOD__
),
480 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment2', [ 'a' => 1 ] ),
486 * @dataProvider provideNewNullRevision
487 * @covers \MediaWiki\Storage\RevisionStore::newNullRevision
488 * @covers \MediaWiki\Storage\RevisionStore::findSlotContentId
490 public function testNewNullRevision( Title
$title, $comment, $minor ) {
491 $this->overrideMwServices();
493 $page = $this->getExistingTestPage( $title );
494 $rev = $page->getRevision();
496 $store = MediaWikiServices
::getInstance()->getRevisionStore();
497 $user = TestUserRegistry
::getMutableTestUser( __METHOD__
)->getUser();
499 $parent = $store->getRevisionById( $rev->getId() );
500 $record = $store->newNullRevision(
501 wfGetDB( DB_MASTER
),
508 $this->assertEquals( $title->getNamespace(), $record->getPageAsLinkTarget()->getNamespace() );
509 $this->assertEquals( $title->getDBkey(), $record->getPageAsLinkTarget()->getDBkey() );
510 $this->assertEquals( $comment, $record->getComment() );
511 $this->assertEquals( $minor, $record->isMinor() );
512 $this->assertEquals( $user->getName(), $record->getUser()->getName() );
513 $this->assertEquals( $parent->getId(), $record->getParentId() );
515 $parentSlot = $parent->getSlot( 'main' );
516 $slot = $record->getSlot( 'main' );
518 $this->assertTrue( $slot->isInherited(), 'isInherited' );
519 $this->assertSame( $parentSlot->getOrigin(), $slot->getOrigin(), 'getOrigin' );
520 $this->assertSameSlotContent( $parentSlot, $slot );
524 * @covers \MediaWiki\Storage\RevisionStore::newNullRevision
526 public function testNewNullRevision_nonExistingTitle() {
527 $store = MediaWikiServices
::getInstance()->getRevisionStore();
528 $record = $store->newNullRevision(
529 wfGetDB( DB_MASTER
),
530 Title
::newFromText( __METHOD__
. '.iDontExist!' ),
531 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment' ),
533 TestUserRegistry
::getMutableTestUser( __METHOD__
)->getUser()
535 $this->assertNull( $record );
539 * @covers \MediaWiki\Storage\RevisionStore::getRcIdIfUnpatrolled
541 public function testGetRcIdIfUnpatrolled_returnsRecentChangesId() {
542 $page = $this->getExistingTestPage();
543 $status = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
);
544 /** @var Revision $rev */
545 $rev = $status->value
['revision'];
547 $store = MediaWikiServices
::getInstance()->getRevisionStore();
548 $revisionRecord = $store->getRevisionById( $rev->getId() );
549 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
551 $this->assertGreaterThan( 0, $result );
553 $page->getRevision()->getRecentChange()->getAttribute( 'rc_id' ),
559 * @covers \MediaWiki\Storage\RevisionStore::getRcIdIfUnpatrolled
561 public function testGetRcIdIfUnpatrolled_returnsZeroIfPatrolled() {
562 // This assumes that sysops are auto patrolled
563 $sysop = $this->getTestSysop()->getUser();
564 $page = $this->getExistingTestPage();
565 $status = $page->doEditContent(
566 new WikitextContent( __METHOD__
),
572 /** @var Revision $rev */
573 $rev = $status->value
['revision'];
575 $store = MediaWikiServices
::getInstance()->getRevisionStore();
576 $revisionRecord = $store->getRevisionById( $rev->getId() );
577 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
579 $this->assertSame( 0, $result );
583 * @covers \MediaWiki\Storage\RevisionStore::getRecentChange
585 public function testGetRecentChange() {
586 $page = $this->getExistingTestPage();
587 $content = new WikitextContent( __METHOD__
);
588 $status = $page->doEditContent( $content, __METHOD__
);
589 /** @var Revision $rev */
590 $rev = $status->value
['revision'];
592 $store = MediaWikiServices
::getInstance()->getRevisionStore();
593 $revRecord = $store->getRevisionById( $rev->getId() );
594 $recentChange = $store->getRecentChange( $revRecord );
596 $this->assertEquals( $rev->getId(), $recentChange->getAttribute( 'rc_this_oldid' ) );
597 $this->assertEquals( $rev->getRecentChange(), $recentChange );
601 * @covers \MediaWiki\Storage\RevisionStore::getRevisionById
603 public function testGetRevisionById() {
604 $page = $this->getExistingTestPage();
605 $content = new WikitextContent( __METHOD__
);
606 $status = $page->doEditContent( $content, __METHOD__
);
607 /** @var Revision $rev */
608 $rev = $status->value
['revision'];
610 $store = MediaWikiServices
::getInstance()->getRevisionStore();
611 $revRecord = $store->getRevisionById( $rev->getId() );
613 $this->assertSame( $rev->getId(), $revRecord->getId() );
614 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
615 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
619 * @covers \MediaWiki\Storage\RevisionStore::getRevisionByTitle
621 public function testGetRevisionByTitle() {
622 $page = $this->getExistingTestPage();
623 $content = new WikitextContent( __METHOD__
);
624 $status = $page->doEditContent( $content, __METHOD__
);
625 /** @var Revision $rev */
626 $rev = $status->value
['revision'];
628 $store = MediaWikiServices
::getInstance()->getRevisionStore();
629 $revRecord = $store->getRevisionByTitle( $page->getTitle() );
631 $this->assertSame( $rev->getId(), $revRecord->getId() );
632 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
633 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
637 * @covers \MediaWiki\Storage\RevisionStore::getRevisionByPageId
639 public function testGetRevisionByPageId() {
640 $page = $this->getExistingTestPage();
641 $content = new WikitextContent( __METHOD__
);
642 $status = $page->doEditContent( $content, __METHOD__
);
643 /** @var Revision $rev */
644 $rev = $status->value
['revision'];
646 $store = MediaWikiServices
::getInstance()->getRevisionStore();
647 $revRecord = $store->getRevisionByPageId( $page->getId() );
649 $this->assertSame( $rev->getId(), $revRecord->getId() );
650 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
651 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
655 * @covers \MediaWiki\Storage\RevisionStore::getRevisionByTimestamp
657 public function testGetRevisionByTimestamp() {
658 // Make sure there is 1 second between the last revision and the rev we create...
659 // Otherwise we might not get the correct revision and the test may fail...
661 $page = $this->getExistingTestPage();
663 $content = new WikitextContent( __METHOD__
);
664 $status = $page->doEditContent( $content, __METHOD__
);
665 /** @var Revision $rev */
666 $rev = $status->value
['revision'];
668 $store = MediaWikiServices
::getInstance()->getRevisionStore();
669 $revRecord = $store->getRevisionByTimestamp(
674 $this->assertSame( $rev->getId(), $revRecord->getId() );
675 $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
676 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
679 protected function revisionToRow( Revision
$rev ) {
680 $page = WikiPage
::factory( $rev->getTitle() );
683 'rev_id' => (string)$rev->getId(),
684 'rev_page' => (string)$rev->getPage(),
685 'rev_text_id' => (string)$rev->getTextId(),
686 'rev_timestamp' => $this->db
->timestamp( $rev->getTimestamp() ),
687 'rev_user_text' => (string)$rev->getUserText(),
688 'rev_user' => (string)$rev->getUser(),
689 'rev_minor_edit' => $rev->isMinor() ?
'1' : '0',
690 'rev_deleted' => (string)$rev->getVisibility(),
691 'rev_len' => (string)$rev->getSize(),
692 'rev_parent_id' => (string)$rev->getParentId(),
693 'rev_sha1' => (string)$rev->getSha1(),
694 'rev_comment_text' => $rev->getComment(),
695 'rev_comment_data' => null,
696 'rev_comment_cid' => null,
697 'rev_content_format' => $rev->getContentFormat(),
698 'rev_content_model' => $rev->getContentModel(),
699 'page_namespace' => (string)$page->getTitle()->getNamespace(),
700 'page_title' => $page->getTitle()->getDBkey(),
701 'page_id' => (string)$page->getId(),
702 'page_latest' => (string)$page->getLatest(),
703 'page_is_redirect' => $page->isRedirect() ?
'1' : '0',
704 'page_len' => (string)$page->getContent()->getSize(),
705 'user_name' => (string)$rev->getUserText(),
709 private function assertRevisionRecordMatchesRevision(
711 RevisionRecord
$record
713 $this->assertSame( $rev->getId(), $record->getId() );
714 $this->assertSame( $rev->getPage(), $record->getPageId() );
715 $this->assertSame( $rev->getTimestamp(), $record->getTimestamp() );
716 $this->assertSame( $rev->getUserText(), $record->getUser()->getName() );
717 $this->assertSame( $rev->getUser(), $record->getUser()->getId() );
718 $this->assertSame( $rev->isMinor(), $record->isMinor() );
719 $this->assertSame( $rev->getVisibility(), $record->getVisibility() );
720 $this->assertSame( $rev->getSize(), $record->getSize() );
722 * @note As of MW 1.31, the database schema allows the parent ID to be
723 * NULL to indicate that it is unknown.
725 $expectedParent = $rev->getParentId();
726 if ( $expectedParent === null ) {
729 $this->assertSame( $expectedParent, $record->getParentId() );
730 $this->assertSame( $rev->getSha1(), $record->getSha1() );
731 $this->assertSame( $rev->getComment(), $record->getComment()->text
);
732 $this->assertSame( $rev->getContentFormat(), $record->getContent( 'main' )->getDefaultFormat() );
733 $this->assertSame( $rev->getContentModel(), $record->getContent( 'main' )->getModel() );
734 $this->assertLinkTargetsEqual( $rev->getTitle(), $record->getPageAsLinkTarget() );
738 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow
739 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow_1_29
741 public function testNewRevisionFromRow_anonEdit() {
742 $page = $this->getExistingTestPage();
744 $text = __METHOD__
. 'a-ä';
745 /** @var Revision $rev */
746 $rev = $page->doEditContent(
747 new WikitextContent( $text ),
749 )->value
['revision'];
751 $store = MediaWikiServices
::getInstance()->getRevisionStore();
752 $record = $store->newRevisionFromRow(
753 $this->revisionToRow( $rev ),
757 $this->assertRevisionRecordMatchesRevision( $rev, $record );
758 $this->assertSame( $text, $rev->getContent()->serialize() );
762 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow
763 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow_1_29
765 public function testNewRevisionFromRow_anonEdit_legacyEncoding() {
766 $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
767 $this->overrideMwServices();
768 $page = $this->getExistingTestPage();
770 $text = __METHOD__
. 'a-ä';
771 /** @var Revision $rev */
772 $rev = $page->doEditContent(
773 new WikitextContent( $text ),
775 )->value
['revision'];
777 $store = MediaWikiServices
::getInstance()->getRevisionStore();
778 $record = $store->newRevisionFromRow(
779 $this->revisionToRow( $rev ),
783 $this->assertRevisionRecordMatchesRevision( $rev, $record );
784 $this->assertSame( $text, $rev->getContent()->serialize() );
788 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow
789 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow_1_29
791 public function testNewRevisionFromRow_userEdit() {
792 $page = $this->getExistingTestPage();
794 $text = __METHOD__
. 'b-ä';
795 /** @var Revision $rev */
796 $rev = $page->doEditContent(
797 new WikitextContent( $text ),
801 $this->getTestUser()->getUser()
802 )->value
['revision'];
804 $store = MediaWikiServices
::getInstance()->getRevisionStore();
805 $record = $store->newRevisionFromRow(
806 $this->revisionToRow( $rev ),
810 $this->assertRevisionRecordMatchesRevision( $rev, $record );
811 $this->assertSame( $text, $rev->getContent()->serialize() );
815 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromArchiveRow
817 public function testNewRevisionFromArchiveRow() {
818 $store = MediaWikiServices
::getInstance()->getRevisionStore();
819 $title = Title
::newFromText( __METHOD__
);
820 $text = __METHOD__
. '-bä';
821 $page = $this->getExistingTestPage( $title );
822 /** @var Revision $orig */
823 $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__
)
825 $page->doDeleteArticle( __METHOD__
);
827 $db = wfGetDB( DB_MASTER
);
828 $arQuery = $store->getArchiveQueryInfo();
830 $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
831 __METHOD__
, [], $arQuery['joins']
833 $this->assertTrue( is_object( $res ), 'query failed' );
835 $row = $res->fetchObject();
837 $record = $store->newRevisionFromArchiveRow( $row );
839 $this->assertRevisionRecordMatchesRevision( $orig, $record );
840 $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
844 * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromArchiveRow
846 public function testNewRevisionFromArchiveRow_legacyEncoding() {
847 $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
848 $this->overrideMwServices();
849 $store = MediaWikiServices
::getInstance()->getRevisionStore();
850 $title = Title
::newFromText( __METHOD__
);
851 $text = __METHOD__
. '-bä';
852 $page = $this->getExistingTestPage( $title );
853 /** @var Revision $orig */
854 $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__
)
856 $page->doDeleteArticle( __METHOD__
);
858 $db = wfGetDB( DB_MASTER
);
859 $arQuery = $store->getArchiveQueryInfo();
861 $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
862 __METHOD__
, [], $arQuery['joins']
864 $this->assertTrue( is_object( $res ), 'query failed' );
866 $row = $res->fetchObject();
868 $record = $store->newRevisionFromArchiveRow( $row );
870 $this->assertRevisionRecordMatchesRevision( $orig, $record );
871 $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
875 * @covers \MediaWiki\Storage\RevisionStore::loadRevisionFromId
877 public function testLoadRevisionFromId() {
878 $title = Title
::newFromText( __METHOD__
);
879 $page = $this->getExistingTestPage( $title );
880 $rev = $page->getRevision();
882 $store = MediaWikiServices
::getInstance()->getRevisionStore();
883 $result = $store->loadRevisionFromId( wfGetDB( DB_MASTER
), $rev->getId() );
884 $this->assertRevisionRecordMatchesRevision( $rev, $result );
888 * @covers \MediaWiki\Storage\RevisionStore::loadRevisionFromPageId
890 public function testLoadRevisionFromPageId() {
891 $title = Title
::newFromText( __METHOD__
);
892 $page = $this->getExistingTestPage( $title );
893 $rev = $page->getRevision();
895 $store = MediaWikiServices
::getInstance()->getRevisionStore();
896 $result = $store->loadRevisionFromPageId( wfGetDB( DB_MASTER
), $page->getId() );
897 $this->assertRevisionRecordMatchesRevision( $rev, $result );
901 * @covers \MediaWiki\Storage\RevisionStore::loadRevisionFromTitle
903 public function testLoadRevisionFromTitle() {
904 $title = Title
::newFromText( __METHOD__
);
905 $page = $this->getExistingTestPage( $title );
906 $rev = $page->getRevision();
908 $store = MediaWikiServices
::getInstance()->getRevisionStore();
909 $result = $store->loadRevisionFromTitle( wfGetDB( DB_MASTER
), $title );
910 $this->assertRevisionRecordMatchesRevision( $rev, $result );
914 * @covers \MediaWiki\Storage\RevisionStore::loadRevisionFromTimestamp
916 public function testLoadRevisionFromTimestamp() {
917 $page = $this->getNonexistingTestPage( __METHOD__
);
918 $title = $page->getTitle();
919 /** @var Revision $revOne */
920 $revOne = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
)
922 // Sleep to ensure different timestamps... )(evil)
924 /** @var Revision $revTwo */
925 $revTwo = $page->doEditContent( new WikitextContent( __METHOD__
. 'a' ), '' )
928 $store = MediaWikiServices
::getInstance()->getRevisionStore();
930 $store->loadRevisionFromTimestamp( wfGetDB( DB_MASTER
), $title, '20150101010101' )
934 $store->loadRevisionFromTimestamp(
935 wfGetDB( DB_MASTER
),
937 $revOne->getTimestamp()
942 $store->loadRevisionFromTimestamp(
943 wfGetDB( DB_MASTER
),
945 $revTwo->getTimestamp()
951 * @covers \MediaWiki\Storage\RevisionStore::listRevisionSizes
953 public function testGetParentLengths() {
954 $page = $this->getNonexistingTestPage( __METHOD__
);
955 /** @var Revision $revOne */
956 $revOne = $page->doEditContent(
957 new WikitextContent( __METHOD__
), __METHOD__
958 )->value
['revision'];
959 /** @var Revision $revTwo */
960 $revTwo = $page->doEditContent(
961 new WikitextContent( __METHOD__
. '2' ), __METHOD__
962 )->value
['revision'];
964 $store = MediaWikiServices
::getInstance()->getRevisionStore();
967 $revOne->getId() => strlen( __METHOD__
),
969 $store->listRevisionSizes(
970 wfGetDB( DB_MASTER
),
976 $revOne->getId() => strlen( __METHOD__
),
977 $revTwo->getId() => strlen( __METHOD__
) +
1,
979 $store->listRevisionSizes(
980 wfGetDB( DB_MASTER
),
981 [ $revOne->getId(), $revTwo->getId() ]
987 * @covers \MediaWiki\Storage\RevisionStore::getPreviousRevision
989 public function testGetPreviousRevision() {
990 $page = $this->getNonexistingTestPage( __METHOD__
);
991 /** @var Revision $revOne */
992 $revOne = $page->doEditContent(
993 new WikitextContent( __METHOD__
), __METHOD__
994 )->value
['revision'];
995 /** @var Revision $revTwo */
996 $revTwo = $page->doEditContent(
997 new WikitextContent( __METHOD__
. '2' ), __METHOD__
998 )->value
['revision'];
1000 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1002 $store->getPreviousRevision( $store->getRevisionById( $revOne->getId() ) )
1006 $store->getPreviousRevision( $store->getRevisionById( $revTwo->getId() ) )->getId()
1011 * @covers \MediaWiki\Storage\RevisionStore::getNextRevision
1013 public function testGetNextRevision() {
1014 $page = $this->getNonexistingTestPage( __METHOD__
);
1015 /** @var Revision $revOne */
1016 $revOne = $page->doEditContent(
1017 new WikitextContent( __METHOD__
), __METHOD__
1018 )->value
['revision'];
1019 /** @var Revision $revTwo */
1020 $revTwo = $page->doEditContent(
1021 new WikitextContent( __METHOD__
. '2' ), __METHOD__
1022 )->value
['revision'];
1024 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1027 $store->getNextRevision( $store->getRevisionById( $revOne->getId() ) )->getId()
1030 $store->getNextRevision( $store->getRevisionById( $revTwo->getId() ) )
1035 * @covers \MediaWiki\Storage\RevisionStore::getTimestampFromId
1037 public function testGetTimestampFromId_found() {
1038 $page = $this->getExistingTestPage();
1039 $rev = $page->getRevision();
1041 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1042 $result = $store->getTimestampFromId(
1047 $this->assertSame( $rev->getTimestamp(), $result );
1051 * @covers \MediaWiki\Storage\RevisionStore::getTimestampFromId
1053 public function testGetTimestampFromId_notFound() {
1054 $page = $this->getExistingTestPage();
1055 $rev = $page->getRevision();
1057 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1058 $result = $store->getTimestampFromId(
1063 $this->assertFalse( $result );
1067 * @covers \MediaWiki\Storage\RevisionStore::countRevisionsByPageId
1069 public function testCountRevisionsByPageId() {
1070 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1071 $page = $this->getNonexistingTestPage( __METHOD__
);
1075 $store->countRevisionsByPageId( wfGetDB( DB_MASTER
), $page->getId() )
1077 $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1080 $store->countRevisionsByPageId( wfGetDB( DB_MASTER
), $page->getId() )
1082 $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1085 $store->countRevisionsByPageId( wfGetDB( DB_MASTER
), $page->getId() )
1090 * @covers \MediaWiki\Storage\RevisionStore::countRevisionsByTitle
1092 public function testCountRevisionsByTitle() {
1093 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1094 $page = $this->getNonexistingTestPage( __METHOD__
);
1098 $store->countRevisionsByTitle( wfGetDB( DB_MASTER
), $page->getTitle() )
1100 $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1103 $store->countRevisionsByTitle( wfGetDB( DB_MASTER
), $page->getTitle() )
1105 $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1108 $store->countRevisionsByTitle( wfGetDB( DB_MASTER
), $page->getTitle() )
1113 * @covers \MediaWiki\Storage\RevisionStore::userWasLastToEdit
1115 public function testUserWasLastToEdit_false() {
1116 $sysop = $this->getTestSysop()->getUser();
1117 $page = $this->getExistingTestPage();
1118 $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
);
1120 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1121 $result = $store->userWasLastToEdit(
1122 wfGetDB( DB_MASTER
),
1127 $this->assertFalse( $result );
1131 * @covers \MediaWiki\Storage\RevisionStore::userWasLastToEdit
1133 public function testUserWasLastToEdit_true() {
1134 $startTime = wfTimestampNow();
1135 $sysop = $this->getTestSysop()->getUser();
1136 $page = $this->getExistingTestPage();
1137 $page->doEditContent(
1138 new WikitextContent( __METHOD__
),
1145 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1146 $result = $store->userWasLastToEdit(
1147 wfGetDB( DB_MASTER
),
1152 $this->assertTrue( $result );
1156 * @covers \MediaWiki\Storage\RevisionStore::getKnownCurrentRevision
1158 public function testGetKnownCurrentRevision() {
1159 $page = $this->getExistingTestPage();
1160 /** @var Revision $rev */
1161 $rev = $page->doEditContent(
1162 new WikitextContent( __METHOD__
. 'b' ),
1166 $this->getTestUser()->getUser()
1167 )->value
['revision'];
1169 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1170 $record = $store->getKnownCurrentRevision(
1175 $this->assertRevisionRecordMatchesRevision( $rev, $record );
1178 public function provideNewMutableRevisionFromArray() {
1179 yield
'Basic array, with page & id' => [
1184 'timestamp' => '20171017114835',
1185 'user_text' => '111.0.1.2',
1187 'minor_edit' => false,
1191 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1192 'comment' => 'Goat Comment!',
1193 'content_format' => 'text/x-wiki',
1194 'content_model' => 'wikitext',
1197 yield
'Basic array, content object' => [
1201 'timestamp' => '20171017114835',
1202 'user_text' => '111.0.1.2',
1204 'minor_edit' => false,
1208 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1209 'comment' => 'Goat Comment!',
1210 'content' => new WikitextContent( 'Some Content' ),
1213 yield
'Basic array, serialized text' => [
1217 'timestamp' => '20171017114835',
1218 'user_text' => '111.0.1.2',
1220 'minor_edit' => false,
1224 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1225 'comment' => 'Goat Comment!',
1226 'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1229 yield
'Basic array, serialized text, utf-8 flags' => [
1233 'timestamp' => '20171017114835',
1234 'user_text' => '111.0.1.2',
1236 'minor_edit' => false,
1240 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1241 'comment' => 'Goat Comment!',
1242 'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1246 yield
'Basic array, with title' => [
1248 'title' => Title
::newFromText( 'SomeText' ),
1250 'timestamp' => '20171017114835',
1251 'user_text' => '111.0.1.2',
1253 'minor_edit' => false,
1257 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1258 'comment' => 'Goat Comment!',
1259 'content_format' => 'text/x-wiki',
1260 'content_model' => 'wikitext',
1263 yield
'Basic array, no user field' => [
1268 'timestamp' => '20171017114835',
1269 'user_text' => '111.0.1.3',
1270 'minor_edit' => false,
1274 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1275 'comment' => 'Goat Comment!',
1276 'content_format' => 'text/x-wiki',
1277 'content_model' => 'wikitext',
1283 * @dataProvider provideNewMutableRevisionFromArray
1284 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
1286 public function testNewMutableRevisionFromArray( array $array ) {
1287 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1289 // HACK: if $array['page'] is given, make sure that the page exists
1290 if ( isset( $array['page'] ) ) {
1291 $t = Title
::newFromID( $array['page'] );
1292 if ( !$t ||
!$t->exists() ) {
1293 $t = Title
::makeTitle( NS_MAIN
, __METHOD__
);
1294 $info = $this->insertPage( $t );
1295 $array['page'] = $info['id'];
1299 $result = $store->newMutableRevisionFromArray( $array );
1301 if ( isset( $array['id'] ) ) {
1302 $this->assertSame( $array['id'], $result->getId() );
1304 if ( isset( $array['page'] ) ) {
1305 $this->assertSame( $array['page'], $result->getPageId() );
1307 $this->assertSame( $array['timestamp'], $result->getTimestamp() );
1308 $this->assertSame( $array['user_text'], $result->getUser()->getName() );
1309 if ( isset( $array['user'] ) ) {
1310 $this->assertSame( $array['user'], $result->getUser()->getId() );
1312 $this->assertSame( (bool)$array['minor_edit'], $result->isMinor() );
1313 $this->assertSame( $array['deleted'], $result->getVisibility() );
1314 $this->assertSame( $array['len'], $result->getSize() );
1315 $this->assertSame( $array['parent_id'], $result->getParentId() );
1316 $this->assertSame( $array['sha1'], $result->getSha1() );
1317 $this->assertSame( $array['comment'], $result->getComment()->text
);
1318 if ( isset( $array['content'] ) ) {
1320 $result->getSlot( 'main' )->getContent()->equals( $array['content'] )
1322 } elseif ( isset( $array['text'] ) ) {
1323 $this->assertSame( $array['text'], $result->getSlot( 'main' )->getContent()->serialize() );
1326 $array['content_format'],
1327 $result->getSlot( 'main' )->getContent()->getDefaultFormat()
1329 $this->assertSame( $array['content_model'], $result->getSlot( 'main' )->getModel() );
1334 * @dataProvider provideNewMutableRevisionFromArray
1335 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
1337 public function testNewMutableRevisionFromArray_legacyEncoding( array $array ) {
1338 $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1339 $lb = MediaWikiServices
::getInstance()->getDBLoadBalancer();
1340 $blobStore = new SqlBlobStore( $lb, $cache );
1341 $blobStore->setLegacyEncoding( 'windows-1252', Language
::factory( 'en' ) );
1343 $factory = $this->getMockBuilder( BlobStoreFactory
::class )
1344 ->setMethods( [ 'newBlobStore', 'newSqlBlobStore' ] )
1345 ->disableOriginalConstructor()
1347 $factory->expects( $this->any() )
1348 ->method( 'newBlobStore' )
1349 ->willReturn( $blobStore );
1350 $factory->expects( $this->any() )
1351 ->method( 'newSqlBlobStore' )
1352 ->willReturn( $blobStore );
1354 $this->setService( 'BlobStoreFactory', $factory );
1356 $this->testNewMutableRevisionFromArray( $array );
1359 protected function getDefaultQueryFields( $returnTextIdField = true ) {
1370 if ( $returnTextIdField ) {
1371 $fields[] = 'rev_text_id';
1376 protected function getCommentQueryFields() {
1378 'rev_comment_text' => 'rev_comment',
1379 'rev_comment_data' => 'NULL',
1380 'rev_comment_cid' => 'NULL',
1384 protected function getActorQueryFields() {
1386 'rev_user' => 'rev_user',
1387 'rev_user_text' => 'rev_user_text',
1388 'rev_actor' => 'NULL',
1392 protected function getContentHandlerQueryFields() {
1394 'rev_content_format',
1395 'rev_content_model',
1399 abstract public function provideGetQueryInfo();
1402 * @dataProvider provideGetQueryInfo
1403 * @covers \MediaWiki\Storage\RevisionStore::getQueryInfo
1405 public function testGetQueryInfo( $options, $expected ) {
1406 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1408 $queryInfo = $store->getQueryInfo( $options );
1410 $this->assertArrayEqualsIgnoringIntKeyOrder(
1411 $expected['tables'],
1412 $queryInfo['tables']
1414 $this->assertArrayEqualsIgnoringIntKeyOrder(
1415 $expected['fields'],
1416 $queryInfo['fields']
1418 $this->assertArrayEqualsIgnoringIntKeyOrder(
1424 protected function getDefaultArchiveFields( $returnTextFields = true ) {
1438 if ( $returnTextFields ) {
1439 $fields[] = 'ar_text_id';
1444 abstract public function provideGetArchiveQueryInfo();
1447 * @dataProvider provideGetArchiveQueryInfo
1448 * @covers \MediaWiki\Storage\RevisionStore::getArchiveQueryInfo
1450 public function testGetArchiveQueryInfo( $expected ) {
1451 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1453 $archiveQueryInfo = $store->getArchiveQueryInfo();
1455 $this->assertArrayEqualsIgnoringIntKeyOrder(
1456 $expected['tables'],
1457 $archiveQueryInfo['tables']
1460 $this->assertArrayEqualsIgnoringIntKeyOrder(
1461 $expected['fields'],
1462 $archiveQueryInfo['fields']
1465 $this->assertArrayEqualsIgnoringIntKeyOrder(
1467 $archiveQueryInfo['joins']
1472 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
1475 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
1476 * split into a string key array and an int key array before assertions occur.
1478 * @param array $expected
1479 * @param array $actual
1481 private function assertArrayEqualsIgnoringIntKeyOrder( array $expected, array $actual ) {
1482 $this->objectAssociativeSort( $expected );
1483 $this->objectAssociativeSort( $actual );
1485 // Separate the int key values from the string key values so that assertion failures are
1486 // easier to understand.
1487 $expectedIntKeyValues = [];
1488 $actualIntKeyValues = [];
1490 // Remove all int keys and re add them at the end after sorting by value
1491 // This will result in all int keys being in the same order with same ints at the end of
1493 foreach ( $expected as $key => $value ) {
1494 if ( is_int( $key ) ) {
1495 unset( $expected[$key] );
1496 $expectedIntKeyValues[] = $value;
1499 foreach ( $actual as $key => $value ) {
1500 if ( is_int( $key ) ) {
1501 unset( $actual[$key] );
1502 $actualIntKeyValues[] = $value;
1506 $this->assertArrayEquals( $expected, $actual, false, true );
1507 $this->assertArrayEquals( $expectedIntKeyValues, $actualIntKeyValues, false, true );