3 namespace MediaWiki\Tests\Revision
;
5 use CommentStoreComment
;
11 use InvalidArgumentException
;
13 use MediaWiki\Linker\LinkTarget
;
14 use MediaWiki\MediaWikiServices
;
15 use MediaWiki\Revision\IncompleteRevisionException
;
16 use MediaWiki\Revision\MutableRevisionRecord
;
17 use MediaWiki\Revision\RevisionArchiveRecord
;
18 use MediaWiki\Revision\RevisionRecord
;
19 use MediaWiki\Revision\RevisionStoreRecord
;
20 use MediaWiki\Revision\RevisionSlots
;
21 use MediaWiki\Revision\RevisionStore
;
22 use MediaWiki\Revision\SlotRecord
;
23 use MediaWiki\Storage\BlobStoreFactory
;
24 use MediaWiki\Storage\SqlBlobStore
;
25 use MediaWiki\User\UserIdentityValue
;
26 use MediaWikiTestCase
;
27 use PHPUnit_Framework_MockObject_MockObject
;
32 use Wikimedia\Rdbms\Database
;
33 use Wikimedia\Rdbms\DatabaseDomain
;
34 use Wikimedia\Rdbms\DatabaseSqlite
;
35 use Wikimedia\Rdbms\FakeResultWrapper
;
36 use Wikimedia\Rdbms\LoadBalancer
;
37 use Wikimedia\Rdbms\TransactionProfiler
;
43 * @group RevisionStore
45 abstract class RevisionStoreDbTestBase
extends MediaWikiTestCase
{
50 private $testPageTitle;
60 abstract protected function getMcrMigrationStage();
65 protected function getContentHandlerUseDB() {
72 abstract protected function getMcrTablesToReset();
74 public function setUp() {
76 $this->tablesUsed
[] = 'archive';
77 $this->tablesUsed
[] = 'page';
78 $this->tablesUsed
[] = 'revision';
79 $this->tablesUsed
[] = 'comment';
81 $this->tablesUsed +
= $this->getMcrTablesToReset();
83 $this->setMwGlobals( [
84 'wgMultiContentRevisionSchemaMigrationStage' => $this->getMcrMigrationStage(),
85 'wgContentHandlerUseDB' => $this->getContentHandlerUseDB(),
89 protected function addCoreDBData() {
90 // Blank out. This would fail with a modified schema, and we don't need it.
96 protected function getTestPageTitle() {
97 if ( $this->testPageTitle
) {
98 return $this->testPageTitle
;
101 $this->testPageTitle
= Title
::newFromText( 'UTPage-' . __CLASS__
);
102 return $this->testPageTitle
;
106 * @param string|null $pageTitle whether to force-create a new page
109 protected function getTestPage( $pageTitle = null ) {
110 if ( is_null( $pageTitle ) && $this->testPage
) {
111 return $this->testPage
;
114 $title = is_null( $pageTitle ) ?
$this->getTestPageTitle() : Title
::newFromText( $pageTitle );
115 $page = WikiPage
::factory( $title );
117 if ( !$page->exists() ) {
118 // Make sure we don't write to the live db.
119 $this->ensureMockDatabaseConnection( wfGetDB( DB_MASTER
) );
121 $user = static::getTestSysop()->getUser();
123 $page->doEditContent(
124 new WikitextContent( 'UTContent-' . __CLASS__
),
125 'UTPageSummary-' . __CLASS__
,
126 EDIT_NEW | EDIT_SUPPRESS_RC
,
132 if ( is_null( $pageTitle ) ) {
133 $this->testPage
= $page;
139 * @return LoadBalancer|PHPUnit_Framework_MockObject_MockObject
141 private function getLoadBalancerMock( array $server ) {
142 $domain = new DatabaseDomain( $server['dbname'], null, $server['tablePrefix'] );
144 $lb = $this->getMockBuilder( LoadBalancer
::class )
145 ->setMethods( [ 'reallyOpenConnection' ] )
146 ->setConstructorArgs( [
147 [ 'servers' => [ $server ], 'localDomain' => $domain ]
151 $lb->method( 'reallyOpenConnection' )->willReturnCallback(
152 function ( array $server, $dbNameOverride ) {
153 return $this->getDatabaseMock( $server );
161 * @return Database|PHPUnit_Framework_MockObject_MockObject
163 private function getDatabaseMock( array $params ) {
164 $db = $this->getMockBuilder( DatabaseSqlite
::class )
165 ->setMethods( [ 'select', 'doQuery', 'open', 'closeConnection', 'isOpen' ] )
166 ->setConstructorArgs( [ $params ] )
169 $db->method( 'select' )->willReturn( new FakeResultWrapper( [] ) );
170 $db->method( 'isOpen' )->willReturn( true );
175 public function provideDomainCheck() {
176 yield
[ false, 'test', '' ];
177 yield
[ 'test', 'test', '' ];
179 yield
[ false, 'test', 'foo_' ];
180 yield
[ 'test-foo_', 'test', 'foo_' ];
182 yield
[ false, 'dash-test', '' ];
183 yield
[ 'dash-test', 'dash-test', '' ];
185 yield
[ false, 'underscore_test', 'foo_' ];
186 yield
[ 'underscore_test-foo_', 'underscore_test', 'foo_' ];
190 * @dataProvider provideDomainCheck
191 * @covers \MediaWiki\Revision\RevisionStore::checkDatabaseDomain
193 public function testDomainCheck( $wikiId, $dbName, $dbPrefix ) {
196 'wgDBname' => $dbName,
197 'wgDBprefix' => $dbPrefix,
201 $loadBalancer = $this->getLoadBalancerMock(
204 'dbDirectory' => '*dummy*',
206 'password' => 'test',
214 'trxProfiler' => new TransactionProfiler(),
215 'connLogger' => new \Psr\Log\
NullLogger(),
216 'queryLogger' => new \Psr\Log\
NullLogger(),
217 'errorLogger' => function () {
219 'deprecationLogger' => function () {
223 'tablePrefix' => $dbPrefix,
226 $db = $loadBalancer->getConnection( DB_REPLICA
);
228 /** @var SqlBlobStore $blobStore */
229 $blobStore = $this->getMockBuilder( SqlBlobStore
::class )
230 ->disableOriginalConstructor()
233 $store = new RevisionStore(
236 new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
237 MediaWikiServices
::getInstance()->getCommentStore(),
238 MediaWikiServices
::getInstance()->getContentModelStore(),
239 MediaWikiServices
::getInstance()->getSlotRoleStore(),
240 MediaWikiServices
::getInstance()->getSlotRoleRegistry(),
241 $this->getMcrMigrationStage(),
242 MediaWikiServices
::getInstance()->getActorMigration(),
246 $count = $store->countRevisionsByPageId( $db, 0 );
248 // Dummy check to make PhpUnit happy. We are really only interested in
249 // countRevisionsByPageId not failing due to the DB domain check.
250 $this->assertSame( 0, $count );
253 protected function assertLinkTargetsEqual( LinkTarget
$l1, LinkTarget
$l2 ) {
254 $this->assertEquals( $l1->getDBkey(), $l2->getDBkey() );
255 $this->assertEquals( $l1->getNamespace(), $l2->getNamespace() );
256 $this->assertEquals( $l1->getFragment(), $l2->getFragment() );
257 $this->assertEquals( $l1->getInterwiki(), $l2->getInterwiki() );
260 protected function assertRevisionRecordsEqual( RevisionRecord
$r1, RevisionRecord
$r2 ) {
262 $r1->getPageAsLinkTarget()->getNamespace(),
263 $r2->getPageAsLinkTarget()->getNamespace()
267 $r1->getPageAsLinkTarget()->getText(),
268 $r2->getPageAsLinkTarget()->getText()
271 if ( $r1->getParentId() ) {
272 $this->assertEquals( $r1->getParentId(), $r2->getParentId() );
275 $this->assertEquals( $r1->getUser()->getName(), $r2->getUser()->getName() );
276 $this->assertEquals( $r1->getUser()->getId(), $r2->getUser()->getId() );
277 $this->assertEquals( $r1->getComment(), $r2->getComment() );
278 $this->assertEquals( $r1->getTimestamp(), $r2->getTimestamp() );
279 $this->assertEquals( $r1->getVisibility(), $r2->getVisibility() );
280 $this->assertEquals( $r1->getSha1(), $r2->getSha1() );
281 $this->assertEquals( $r1->getSize(), $r2->getSize() );
282 $this->assertEquals( $r1->getPageId(), $r2->getPageId() );
283 $this->assertArrayEquals( $r1->getSlotRoles(), $r2->getSlotRoles() );
284 $this->assertEquals( $r1->getWikiId(), $r2->getWikiId() );
285 $this->assertEquals( $r1->isMinor(), $r2->isMinor() );
286 foreach ( $r1->getSlotRoles() as $role ) {
287 $this->assertSlotRecordsEqual( $r1->getSlot( $role ), $r2->getSlot( $role ) );
288 $this->assertTrue( $r1->getContent( $role )->equals( $r2->getContent( $role ) ) );
291 RevisionRecord
::DELETED_TEXT
,
292 RevisionRecord
::DELETED_COMMENT
,
293 RevisionRecord
::DELETED_USER
,
294 RevisionRecord
::DELETED_RESTRICTED
,
296 $this->assertEquals( $r1->isDeleted( $field ), $r2->isDeleted( $field ) );
300 protected function assertSlotRecordsEqual( SlotRecord
$s1, SlotRecord
$s2 ) {
301 $this->assertSame( $s1->getRole(), $s2->getRole() );
302 $this->assertSame( $s1->getModel(), $s2->getModel() );
303 $this->assertSame( $s1->getFormat(), $s2->getFormat() );
304 $this->assertSame( $s1->getSha1(), $s2->getSha1() );
305 $this->assertSame( $s1->getSize(), $s2->getSize() );
306 $this->assertTrue( $s1->getContent()->equals( $s2->getContent() ) );
308 $s1->hasRevision() ?
$this->assertSame( $s1->getRevision(), $s2->getRevision() ) : null;
309 $s1->hasAddress() ?
$this->assertSame( $s1->hasAddress(), $s2->hasAddress() ) : null;
312 protected function assertRevisionCompleteness( RevisionRecord
$r ) {
313 $this->assertTrue( $r->hasSlot( SlotRecord
::MAIN
) );
314 $this->assertInstanceOf( SlotRecord
::class, $r->getSlot( SlotRecord
::MAIN
) );
315 $this->assertInstanceOf( Content
::class, $r->getContent( SlotRecord
::MAIN
) );
317 foreach ( $r->getSlotRoles() as $role ) {
318 $this->assertSlotCompleteness( $r, $r->getSlot( $role ) );
322 protected function assertSlotCompleteness( RevisionRecord
$r, SlotRecord
$slot ) {
323 $this->assertTrue( $slot->hasAddress() );
324 $this->assertSame( $r->getId(), $slot->getRevision() );
326 $this->assertInstanceOf( Content
::class, $slot->getContent() );
330 * @param mixed[] $details
332 * @return RevisionRecord
334 private function getRevisionRecordFromDetailsArray( $details = [] ) {
335 // Convert some values that can't be provided by dataProviders
336 if ( isset( $details['user'] ) && $details['user'] === true ) {
337 $details['user'] = $this->getTestUser()->getUser();
339 if ( isset( $details['page'] ) && $details['page'] === true ) {
340 $details['page'] = $this->getTestPage()->getId();
342 if ( isset( $details['parent'] ) && $details['parent'] === true ) {
343 $details['parent'] = $this->getTestPage()->getLatest();
346 // Create the RevisionRecord with any available data
347 $rev = new MutableRevisionRecord( $this->getTestPageTitle() );
348 isset( $details['slot'] ) ?
$rev->setSlot( $details['slot'] ) : null;
349 isset( $details['parent'] ) ?
$rev->setParentId( $details['parent'] ) : null;
350 isset( $details['page'] ) ?
$rev->setPageId( $details['page'] ) : null;
351 isset( $details['size'] ) ?
$rev->setSize( $details['size'] ) : null;
352 isset( $details['sha1'] ) ?
$rev->setSha1( $details['sha1'] ) : null;
353 isset( $details['comment'] ) ?
$rev->setComment( $details['comment'] ) : null;
354 isset( $details['timestamp'] ) ?
$rev->setTimestamp( $details['timestamp'] ) : null;
355 isset( $details['minor'] ) ?
$rev->setMinorEdit( $details['minor'] ) : null;
356 isset( $details['user'] ) ?
$rev->setUser( $details['user'] ) : null;
357 isset( $details['visibility'] ) ?
$rev->setVisibility( $details['visibility'] ) : null;
358 isset( $details['id'] ) ?
$rev->setId( $details['id'] ) : null;
360 if ( isset( $details['content'] ) ) {
361 foreach ( $details['content'] as $role => $content ) {
362 $rev->setContent( $role, $content );
369 public function provideInsertRevisionOn_successes() {
370 yield
'Bare minimum revision insertion' => [
372 'slot' => SlotRecord
::newUnsaved( SlotRecord
::MAIN
, new WikitextContent( 'Chicken' ) ),
374 'comment' => $this->getRandomCommentStoreComment(),
375 'timestamp' => '20171117010101',
379 yield
'Detailed revision insertion' => [
381 'slot' => SlotRecord
::newUnsaved( SlotRecord
::MAIN
, new WikitextContent( 'Chicken' ) ),
384 'comment' => $this->getRandomCommentStoreComment(),
385 'timestamp' => '20171117010101',
388 'visibility' => RevisionRecord
::DELETED_RESTRICTED
,
393 protected function getRandomCommentStoreComment() {
394 return CommentStoreComment
::newUnsavedComment( __METHOD__
. '.' . rand( 0, 1000 ) );
398 * @dataProvider provideInsertRevisionOn_successes
399 * @covers \MediaWiki\Revision\RevisionStore::insertRevisionOn
400 * @covers \MediaWiki\Revision\RevisionStore::insertSlotRowOn
401 * @covers \MediaWiki\Revision\RevisionStore::insertContentRowOn
403 public function testInsertRevisionOn_successes(
404 array $revDetails = []
406 $title = $this->getTestPageTitle();
407 $rev = $this->getRevisionRecordFromDetailsArray( $revDetails );
409 $store = MediaWikiServices
::getInstance()->getRevisionStore();
410 $return = $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER
) );
412 // is the new revision correct?
413 $this->assertRevisionCompleteness( $return );
414 $this->assertLinkTargetsEqual( $title, $return->getPageAsLinkTarget() );
415 $this->assertRevisionRecordsEqual( $rev, $return );
417 // can we load it from the store?
418 $loaded = $store->getRevisionById( $return->getId() );
419 $this->assertRevisionCompleteness( $loaded );
420 $this->assertRevisionRecordsEqual( $return, $loaded );
422 // can we find it directly in the database?
423 $this->assertRevisionExistsInDatabase( $return );
426 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
427 $row = $this->revisionToRow( new Revision( $rev ), [] );
429 // unset nulled fields
430 unset( $row->rev_content_model
);
431 unset( $row->rev_content_format
);
434 unset( $row->rev_comment_text
);
435 unset( $row->rev_comment_data
);
436 unset( $row->rev_comment_cid
);
437 unset( $row->rev_comment_id
);
439 $store = MediaWikiServices
::getInstance()->getRevisionStore();
440 $queryInfo = $store->getQueryInfo( [ 'user' ] );
442 $row = get_object_vars( $row );
444 // Use aliased fields from $queryInfo, e.g. rev_user
445 $keys = array_keys( $row );
446 $keys = array_combine( $keys, $keys );
447 $fields = array_intersect_key( $queryInfo['fields'], $keys ) +
$keys;
449 // assertSelect() fails unless the orders match.
454 $queryInfo['tables'],
456 [ 'rev_id' => $rev->getId() ],
457 [ array_values( $row ) ],
464 * @param SlotRecord $a
465 * @param SlotRecord $b
467 protected function assertSameSlotContent( SlotRecord
$a, SlotRecord
$b ) {
468 // Assert that the same blob address has been used.
469 $this->assertSame( $a->getAddress(), $b->getAddress() );
473 * @covers \MediaWiki\Revision\RevisionStore::insertRevisionOn
475 public function testInsertRevisionOn_blobAddressExists() {
476 $title = $this->getTestPageTitle();
478 'slot' => SlotRecord
::newUnsaved( SlotRecord
::MAIN
, new WikitextContent( 'Chicken' ) ),
480 'comment' => $this->getRandomCommentStoreComment(),
481 'timestamp' => '20171117010101',
485 $store = MediaWikiServices
::getInstance()->getRevisionStore();
487 // Insert the first revision
488 $revOne = $this->getRevisionRecordFromDetailsArray( $revDetails );
489 $firstReturn = $store->insertRevisionOn( $revOne, wfGetDB( DB_MASTER
) );
490 $this->assertLinkTargetsEqual( $title, $firstReturn->getPageAsLinkTarget() );
491 $this->assertRevisionRecordsEqual( $revOne, $firstReturn );
493 // Insert a second revision inheriting the same blob address
494 $revDetails['slot'] = SlotRecord
::newInherited( $firstReturn->getSlot( SlotRecord
::MAIN
) );
495 $revTwo = $this->getRevisionRecordFromDetailsArray( $revDetails );
496 $secondReturn = $store->insertRevisionOn( $revTwo, wfGetDB( DB_MASTER
) );
497 $this->assertLinkTargetsEqual( $title, $secondReturn->getPageAsLinkTarget() );
498 $this->assertRevisionRecordsEqual( $revTwo, $secondReturn );
500 $firstMainSlot = $firstReturn->getSlot( SlotRecord
::MAIN
);
501 $secondMainSlot = $secondReturn->getSlot( SlotRecord
::MAIN
);
503 $this->assertSameSlotContent( $firstMainSlot, $secondMainSlot );
505 // And that different revisions have been created.
506 $this->assertNotSame( $firstReturn->getId(), $secondReturn->getId() );
508 // Make sure the slot rows reference the correct revision
509 $this->assertSame( $firstReturn->getId(), $firstMainSlot->getRevision() );
510 $this->assertSame( $secondReturn->getId(), $secondMainSlot->getRevision() );
513 public function provideInsertRevisionOn_failures() {
516 'comment' => $this->getRandomCommentStoreComment(),
517 'timestamp' => '20171117010101',
520 new InvalidArgumentException( 'main slot must be provided' )
522 yield
'no main slot' => [
524 'slot' => SlotRecord
::newUnsaved( 'aux', new WikitextContent( 'Turkey' ) ),
525 'comment' => $this->getRandomCommentStoreComment(),
526 'timestamp' => '20171117010101',
529 new InvalidArgumentException( 'main slot must be provided' )
531 yield
'no timestamp' => [
533 'slot' => SlotRecord
::newUnsaved( SlotRecord
::MAIN
, new WikitextContent( 'Chicken' ) ),
534 'comment' => $this->getRandomCommentStoreComment(),
537 new IncompleteRevisionException( 'timestamp field must not be NULL!' )
539 yield
'no comment' => [
541 'slot' => SlotRecord
::newUnsaved( SlotRecord
::MAIN
, new WikitextContent( 'Chicken' ) ),
542 'timestamp' => '20171117010101',
545 new IncompleteRevisionException( 'comment must not be NULL!' )
549 'slot' => SlotRecord
::newUnsaved( SlotRecord
::MAIN
, new WikitextContent( 'Chicken' ) ),
550 'comment' => $this->getRandomCommentStoreComment(),
551 'timestamp' => '20171117010101',
553 new IncompleteRevisionException( 'user must not be NULL!' )
558 * @dataProvider provideInsertRevisionOn_failures
559 * @covers \MediaWiki\Revision\RevisionStore::insertRevisionOn
561 public function testInsertRevisionOn_failures(
562 array $revDetails = [],
565 $rev = $this->getRevisionRecordFromDetailsArray( $revDetails );
567 $store = MediaWikiServices
::getInstance()->getRevisionStore();
569 $this->setExpectedException(
570 get_class( $exception ),
571 $exception->getMessage(),
572 $exception->getCode()
574 $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER
) );
577 public function provideNewNullRevision() {
579 Title
::newFromText( 'UTPage_notAutoCreated' ),
580 [ 'content' => [ 'main' => new WikitextContent( 'Flubber1' ) ] ],
581 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment1' ),
585 Title
::newFromText( 'UTPage_notAutoCreated' ),
586 [ 'content' => [ 'main' => new WikitextContent( 'Flubber2' ) ] ],
587 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment2', [ 'a' => 1 ] ),
593 * @dataProvider provideNewNullRevision
594 * @covers \MediaWiki\Revision\RevisionStore::newNullRevision
595 * @covers \MediaWiki\Revision\RevisionStore::findSlotContentId
597 public function testNewNullRevision( Title
$title, $revDetails, $comment, $minor = false ) {
598 $user = TestUserRegistry
::getMutableTestUser( __METHOD__
)->getUser();
599 $page = WikiPage
::factory( $title );
601 if ( !$page->exists() ) {
602 $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
, EDIT_NEW
);
605 $revDetails['page'] = $page->getId();
606 $revDetails['timestamp'] = wfTimestampNow();
607 $revDetails['comment'] = CommentStoreComment
::newUnsavedComment( 'Base' );
608 $revDetails['user'] = $user;
610 $baseRev = $this->getRevisionRecordFromDetailsArray( $revDetails );
611 $store = MediaWikiServices
::getInstance()->getRevisionStore();
613 $dbw = wfGetDB( DB_MASTER
);
614 $baseRev = $store->insertRevisionOn( $baseRev, $dbw );
615 $page->updateRevisionOn( $dbw, new Revision( $baseRev ), $page->getLatest() );
617 $record = $store->newNullRevision(
618 wfGetDB( DB_MASTER
),
625 $this->assertEquals( $title->getNamespace(), $record->getPageAsLinkTarget()->getNamespace() );
626 $this->assertEquals( $title->getDBkey(), $record->getPageAsLinkTarget()->getDBkey() );
627 $this->assertEquals( $comment, $record->getComment() );
628 $this->assertEquals( $minor, $record->isMinor() );
629 $this->assertEquals( $user->getName(), $record->getUser()->getName() );
630 $this->assertEquals( $baseRev->getId(), $record->getParentId() );
632 $this->assertArrayEquals(
633 $baseRev->getSlotRoles(),
634 $record->getSlotRoles()
637 foreach ( $baseRev->getSlotRoles() as $role ) {
638 $parentSlot = $baseRev->getSlot( $role );
639 $slot = $record->getSlot( $role );
641 $this->assertTrue( $slot->isInherited(), 'isInherited' );
642 $this->assertSame( $parentSlot->getOrigin(), $slot->getOrigin(), 'getOrigin' );
643 $this->assertSameSlotContent( $parentSlot, $slot );
648 * @covers \MediaWiki\Revision\RevisionStore::newNullRevision
650 public function testNewNullRevision_nonExistingTitle() {
651 $store = MediaWikiServices
::getInstance()->getRevisionStore();
652 $record = $store->newNullRevision(
653 wfGetDB( DB_MASTER
),
654 Title
::newFromText( __METHOD__
. '.iDontExist!' ),
655 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment' ),
657 TestUserRegistry
::getMutableTestUser( __METHOD__
)->getUser()
659 $this->assertNull( $record );
663 * @covers \MediaWiki\Revision\RevisionStore::getRcIdIfUnpatrolled
665 public function testGetRcIdIfUnpatrolled_returnsRecentChangesId() {
666 $page = $this->getTestPage();
667 $status = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
);
668 /** @var Revision $rev */
669 $rev = $status->value
['revision'];
671 $store = MediaWikiServices
::getInstance()->getRevisionStore();
672 $revisionRecord = $store->getRevisionById( $rev->getId() );
673 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
675 $this->assertGreaterThan( 0, $result );
677 $store->getRecentChange( $revisionRecord )->getAttribute( 'rc_id' ),
683 * @covers \MediaWiki\Revision\RevisionStore::getRcIdIfUnpatrolled
685 public function testGetRcIdIfUnpatrolled_returnsZeroIfPatrolled() {
686 // This assumes that sysops are auto patrolled
687 $sysop = $this->getTestSysop()->getUser();
688 $page = $this->getTestPage();
689 $status = $page->doEditContent(
690 new WikitextContent( __METHOD__
),
696 /** @var Revision $rev */
697 $rev = $status->value
['revision'];
699 $store = MediaWikiServices
::getInstance()->getRevisionStore();
700 $revisionRecord = $store->getRevisionById( $rev->getId() );
701 $result = $store->getRcIdIfUnpatrolled( $revisionRecord );
703 $this->assertSame( 0, $result );
707 * @covers \MediaWiki\Revision\RevisionStore::getRecentChange
709 public function testGetRecentChange() {
710 $page = $this->getTestPage();
711 $content = new WikitextContent( __METHOD__
);
712 $status = $page->doEditContent( $content, __METHOD__
);
713 /** @var Revision $rev */
714 $rev = $status->value
['revision'];
716 $store = MediaWikiServices
::getInstance()->getRevisionStore();
717 $revRecord = $store->getRevisionById( $rev->getId() );
718 $recentChange = $store->getRecentChange( $revRecord );
720 $this->assertEquals( $rev->getId(), $recentChange->getAttribute( 'rc_this_oldid' ) );
721 $this->assertEquals( $rev->getRecentChange(), $recentChange );
725 * @covers \MediaWiki\Revision\RevisionStore::getRevisionById
727 public function testGetRevisionById() {
728 $page = $this->getTestPage();
729 $content = new WikitextContent( __METHOD__
);
730 $status = $page->doEditContent( $content, __METHOD__
);
731 /** @var Revision $rev */
732 $rev = $status->value
['revision'];
734 $store = MediaWikiServices
::getInstance()->getRevisionStore();
735 $revRecord = $store->getRevisionById( $rev->getId() );
737 $this->assertSame( $rev->getId(), $revRecord->getId() );
738 $this->assertTrue( $revRecord->getSlot( SlotRecord
::MAIN
)->getContent()->equals( $content ) );
739 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
743 * @covers \MediaWiki\Revision\RevisionStore::getRevisionByTitle
745 public function testGetRevisionByTitle() {
746 $page = $this->getTestPage();
747 $content = new WikitextContent( __METHOD__
);
748 $status = $page->doEditContent( $content, __METHOD__
);
749 /** @var Revision $rev */
750 $rev = $status->value
['revision'];
752 $store = MediaWikiServices
::getInstance()->getRevisionStore();
753 $revRecord = $store->getRevisionByTitle( $page->getTitle() );
755 $this->assertSame( $rev->getId(), $revRecord->getId() );
756 $this->assertTrue( $revRecord->getSlot( SlotRecord
::MAIN
)->getContent()->equals( $content ) );
757 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
761 * @covers \MediaWiki\Revision\RevisionStore::getRevisionByPageId
763 public function testGetRevisionByPageId() {
764 $page = $this->getTestPage();
765 $content = new WikitextContent( __METHOD__
);
766 $status = $page->doEditContent( $content, __METHOD__
);
767 /** @var Revision $rev */
768 $rev = $status->value
['revision'];
770 $store = MediaWikiServices
::getInstance()->getRevisionStore();
771 $revRecord = $store->getRevisionByPageId( $page->getId() );
773 $this->assertSame( $rev->getId(), $revRecord->getId() );
774 $this->assertTrue( $revRecord->getSlot( SlotRecord
::MAIN
)->getContent()->equals( $content ) );
775 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
779 * @covers \MediaWiki\Revision\RevisionStore::getRevisionByTimestamp
781 public function testGetRevisionByTimestamp() {
782 // Make sure there is 1 second between the last revision and the rev we create...
783 // Otherwise we might not get the correct revision and the test may fail...
785 $page = $this->getTestPage();
787 $content = new WikitextContent( __METHOD__
);
788 $status = $page->doEditContent( $content, __METHOD__
);
789 /** @var Revision $rev */
790 $rev = $status->value
['revision'];
792 $store = MediaWikiServices
::getInstance()->getRevisionStore();
793 $revRecord = $store->getRevisionByTimestamp(
798 $this->assertSame( $rev->getId(), $revRecord->getId() );
799 $this->assertTrue( $revRecord->getSlot( SlotRecord
::MAIN
)->getContent()->equals( $content ) );
800 $this->assertSame( __METHOD__
, $revRecord->getComment()->text
);
803 protected function revisionToRow( Revision
$rev, $options = [ 'page', 'user', 'comment' ] ) {
804 // XXX: the WikiPage object loads another RevisionRecord from the database. Not great.
805 $page = WikiPage
::factory( $rev->getTitle() );
808 'rev_id' => (string)$rev->getId(),
809 'rev_page' => (string)$rev->getPage(),
810 'rev_timestamp' => $this->db
->timestamp( $rev->getTimestamp() ),
811 'rev_user_text' => (string)$rev->getUserText(),
812 'rev_user' => (string)$rev->getUser() ?
: null,
813 'rev_minor_edit' => $rev->isMinor() ?
'1' : '0',
814 'rev_deleted' => (string)$rev->getVisibility(),
815 'rev_len' => (string)$rev->getSize(),
816 'rev_parent_id' => (string)$rev->getParentId(),
817 'rev_sha1' => (string)$rev->getSha1(),
820 if ( in_array( 'page', $options ) ) {
822 'page_namespace' => (string)$page->getTitle()->getNamespace(),
823 'page_title' => $page->getTitle()->getDBkey(),
824 'page_id' => (string)$page->getId(),
825 'page_latest' => (string)$page->getLatest(),
826 'page_is_redirect' => $page->isRedirect() ?
'1' : '0',
827 'page_len' => (string)$page->getContent()->getSize(),
831 if ( in_array( 'user', $options ) ) {
833 'user_name' => (string)$rev->getUserText(),
837 if ( in_array( 'comment', $options ) ) {
839 'rev_comment_text' => $rev->getComment(),
840 'rev_comment_data' => null,
841 'rev_comment_cid' => null,
845 if ( $rev->getId() ) {
847 'rev_id' => (string)$rev->getId(),
851 return (object)$fields;
854 protected function assertRevisionRecordMatchesRevision(
856 RevisionRecord
$record
858 $this->assertSame( $rev->getId(), $record->getId() );
859 $this->assertSame( $rev->getPage(), $record->getPageId() );
860 $this->assertSame( $rev->getTimestamp(), $record->getTimestamp() );
861 $this->assertSame( $rev->getUserText(), $record->getUser()->getName() );
862 $this->assertSame( $rev->getUser(), $record->getUser()->getId() );
863 $this->assertSame( $rev->isMinor(), $record->isMinor() );
864 $this->assertSame( $rev->getVisibility(), $record->getVisibility() );
865 $this->assertSame( $rev->getSize(), $record->getSize() );
867 * @note As of MW 1.31, the database schema allows the parent ID to be
868 * NULL to indicate that it is unknown.
870 $expectedParent = $rev->getParentId();
871 if ( $expectedParent === null ) {
874 $this->assertSame( $expectedParent, $record->getParentId() );
875 $this->assertSame( $rev->getSha1(), $record->getSha1() );
876 $this->assertSame( $rev->getComment(), $record->getComment()->text
);
877 $this->assertSame( $rev->getContentFormat(),
878 $record->getContent( SlotRecord
::MAIN
)->getDefaultFormat() );
879 $this->assertSame( $rev->getContentModel(), $record->getContent( SlotRecord
::MAIN
)->getModel() );
880 $this->assertLinkTargetsEqual( $rev->getTitle(), $record->getPageAsLinkTarget() );
882 $revRec = $rev->getRevisionRecord();
883 $revMain = $revRec->getSlot( SlotRecord
::MAIN
);
884 $recMain = $record->getSlot( SlotRecord
::MAIN
);
886 $this->assertSame( $revMain->hasOrigin(), $recMain->hasOrigin(), 'hasOrigin' );
887 $this->assertSame( $revMain->hasAddress(), $recMain->hasAddress(), 'hasAddress' );
888 $this->assertSame( $revMain->hasContentId(), $recMain->hasContentId(), 'hasContentId' );
890 if ( $revMain->hasOrigin() ) {
891 $this->assertSame( $revMain->getOrigin(), $recMain->getOrigin(), 'getOrigin' );
894 if ( $revMain->hasAddress() ) {
895 $this->assertSame( $revMain->getAddress(), $recMain->getAddress(), 'getAddress' );
898 if ( $revMain->hasContentId() ) {
899 // XXX: the content ID value is ill-defined when SCHEMA_COMPAT_WRITE_BOTH and
900 // SCHEMA_COMPAT_READ_OLD is set, since revision insertion will report the
901 // content ID used with the new schema, while loading the revision from the
902 // old schema will report an emulated ID.
903 if ( $this->getMcrMigrationStage() & SCHEMA_COMPAT_READ_NEW
) {
904 $this->assertSame( $revMain->getContentId(), $recMain->getContentId(), 'getContentId' );
910 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots
911 * @covers \MediaWiki\Revision\RevisionStore::getQueryInfo
913 public function testNewRevisionFromRowAndSlot_getQueryInfo() {
914 $page = $this->getTestPage();
915 $text = __METHOD__
. 'o-ö';
916 /** @var Revision $rev */
917 $rev = $page->doEditContent(
918 new WikitextContent( $text ),
920 )->value
['revision'];
922 $store = MediaWikiServices
::getInstance()->getRevisionStore();
923 $info = $store->getQueryInfo();
924 $row = $this->db
->selectRow(
927 [ 'rev_id' => $rev->getId() ],
933 $info = $store->getSlotsQueryInfo( [ 'content' ] );
934 $slotRows = $this->db
->select(
937 $this->getSlotRevisionConditions( $rev->getId() ),
943 $record = $store->newRevisionFromRowAndSlots(
945 iterator_to_array( $slotRows ),
949 $this->assertRevisionRecordMatchesRevision( $rev, $record );
950 $this->assertSame( $text, $rev->getContent()->serialize() );
954 * Conditions to use together with getSlotsQueryInfo() when selecting slot rows for a given
959 abstract protected function getSlotRevisionConditions( $revId );
962 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
963 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots
964 * @covers \MediaWiki\Revision\RevisionStore::getQueryInfo
966 public function testNewRevisionFromRow_getQueryInfo() {
967 $page = $this->getTestPage();
968 $text = __METHOD__
. 'a-ä';
969 /** @var Revision $rev */
970 $rev = $page->doEditContent(
971 new WikitextContent( $text ),
973 )->value
['revision'];
975 $store = MediaWikiServices
::getInstance()->getRevisionStore();
976 $info = $store->getQueryInfo();
977 $row = $this->db
->selectRow(
980 [ 'rev_id' => $rev->getId() ],
985 $record = $store->newRevisionFromRow(
990 $this->assertRevisionRecordMatchesRevision( $rev, $record );
991 $this->assertSame( $text, $rev->getContent()->serialize() );
995 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
996 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots
998 public function testNewRevisionFromRow_anonEdit() {
999 $page = $this->getTestPage();
1000 $text = __METHOD__
. 'a-ä';
1001 /** @var Revision $rev */
1002 $rev = $page->doEditContent(
1003 new WikitextContent( $text ),
1005 )->value
['revision'];
1007 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1008 $record = $store->newRevisionFromRow(
1009 $this->revisionToRow( $rev ),
1013 $this->assertRevisionRecordMatchesRevision( $rev, $record );
1014 $this->assertSame( $text, $rev->getContent()->serialize() );
1018 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
1019 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots
1021 public function testNewRevisionFromRow_anonEdit_legacyEncoding() {
1022 $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
1023 $page = $this->getTestPage();
1024 $text = __METHOD__
. 'a-ä';
1025 /** @var Revision $rev */
1026 $rev = $page->doEditContent(
1027 new WikitextContent( $text ),
1029 )->value
['revision'];
1031 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1032 $record = $store->newRevisionFromRow(
1033 $this->revisionToRow( $rev ),
1037 $this->assertRevisionRecordMatchesRevision( $rev, $record );
1038 $this->assertSame( $text, $rev->getContent()->serialize() );
1042 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
1043 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots
1045 public function testNewRevisionFromRow_userEdit() {
1046 $page = $this->getTestPage();
1047 $text = __METHOD__
. 'b-ä';
1048 /** @var Revision $rev */
1049 $rev = $page->doEditContent(
1050 new WikitextContent( $text ),
1054 $this->getTestUser()->getUser()
1055 )->value
['revision'];
1057 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1058 $record = $store->newRevisionFromRow(
1059 $this->revisionToRow( $rev ),
1063 $this->assertRevisionRecordMatchesRevision( $rev, $record );
1064 $this->assertSame( $text, $rev->getContent()->serialize() );
1068 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
1069 * @covers \MediaWiki\Revision\RevisionStore::getArchiveQueryInfo
1071 public function testNewRevisionFromArchiveRow_getArchiveQueryInfo() {
1072 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1073 $title = Title
::newFromText( __METHOD__
);
1074 $text = __METHOD__
. '-bä';
1075 $page = WikiPage
::factory( $title );
1076 /** @var Revision $orig */
1077 $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__
)
1078 ->value
['revision'];
1079 $page->doDeleteArticle( __METHOD__
);
1081 $db = wfGetDB( DB_MASTER
);
1082 $arQuery = $store->getArchiveQueryInfo();
1084 $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1085 __METHOD__
, [], $arQuery['joins']
1087 $this->assertTrue( is_object( $res ), 'query failed' );
1089 $row = $res->fetchObject();
1091 $record = $store->newRevisionFromArchiveRow( $row );
1093 $this->assertRevisionRecordMatchesRevision( $orig, $record );
1094 $this->assertSame( $text, $record->getContent( SlotRecord
::MAIN
)->serialize() );
1098 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
1100 public function testNewRevisionFromArchiveRow_legacyEncoding() {
1101 $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
1102 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1103 $title = Title
::newFromText( __METHOD__
);
1104 $text = __METHOD__
. '-bä';
1105 $page = WikiPage
::factory( $title );
1106 /** @var Revision $orig */
1107 $orig = $page->doEditContent( new WikitextContent( $text ), __METHOD__
)
1108 ->value
['revision'];
1109 $page->doDeleteArticle( __METHOD__
);
1111 $db = wfGetDB( DB_MASTER
);
1112 $arQuery = $store->getArchiveQueryInfo();
1114 $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1115 __METHOD__
, [], $arQuery['joins']
1117 $this->assertTrue( is_object( $res ), 'query failed' );
1119 $row = $res->fetchObject();
1121 $record = $store->newRevisionFromArchiveRow( $row );
1123 $this->assertRevisionRecordMatchesRevision( $orig, $record );
1124 $this->assertSame( $text, $record->getContent( SlotRecord
::MAIN
)->serialize() );
1128 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
1130 public function testNewRevisionFromArchiveRow_no_user() {
1131 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1135 'ar_page_id' => '2',
1136 'ar_namespace' => '0',
1137 'ar_title' => 'Something',
1139 'ar_text_id' => '47',
1140 'ar_timestamp' => '20180528192356',
1141 'ar_minor_edit' => '0',
1142 'ar_deleted' => '0',
1144 'ar_parent_id' => '0',
1145 'ar_sha1' => 'deadbeef',
1146 'ar_comment_text' => 'whatever',
1147 'ar_comment_data' => null,
1148 'ar_comment_cid' => null,
1150 'ar_user_text' => '', // this is the important bit
1152 'ar_content_format' => null,
1153 'ar_content_model' => null,
1156 \Wikimedia\
suppressWarnings();
1157 $record = $store->newRevisionFromArchiveRow( $row );
1158 \Wikimedia\
suppressWarnings( true );
1160 $this->assertInstanceOf( RevisionRecord
::class, $record );
1161 $this->assertInstanceOf( UserIdentityValue
::class, $record->getUser() );
1162 $this->assertSame( 'Unknown user', $record->getUser()->getName() );
1166 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
1167 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots
1169 public function testNewRevisionFromRow_no_user() {
1170 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1171 $title = Title
::newFromText( __METHOD__
);
1176 'page_namespace' => '0',
1177 'page_title' => $title->getText(),
1178 'rev_text_id' => '47',
1179 'rev_timestamp' => '20180528192356',
1180 'rev_minor_edit' => '0',
1181 'rev_deleted' => '0',
1183 'rev_parent_id' => '0',
1184 'rev_sha1' => 'deadbeef',
1185 'rev_comment_text' => 'whatever',
1186 'rev_comment_data' => null,
1187 'rev_comment_cid' => null,
1189 'rev_user_text' => '', // this is the important bit
1190 'rev_actor' => null,
1191 'rev_content_format' => null,
1192 'rev_content_model' => null,
1195 \Wikimedia\
suppressWarnings();
1196 $record = $store->newRevisionFromRow( $row, 0, $title );
1197 \Wikimedia\
suppressWarnings( true );
1199 $this->assertNotNull( $record );
1200 $this->assertNotNull( $record->getUser() );
1201 $this->assertNotEmpty( $record->getUser()->getName() );
1205 * @covers \MediaWiki\Revision\RevisionStore::insertRevisionOn
1207 public function testInsertRevisionOn_archive() {
1208 // This is a round trip test for deletion and undeletion of a
1209 // revision row via the archive table.
1211 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1212 $title = Title
::newFromText( __METHOD__
);
1214 $page = WikiPage
::factory( $title );
1215 /** @var Revision $origRev */
1216 $page->doEditContent( new WikitextContent( "First" ), __METHOD__
. '-first' );
1217 $origRev = $page->doEditContent( new WikitextContent( "Foo" ), __METHOD__
)
1218 ->value
['revision'];
1219 $orig = $origRev->getRevisionRecord();
1220 $page->doDeleteArticle( __METHOD__
);
1222 // re-create page, so we can later load revisions for it
1223 $page->doEditContent( new WikitextContent( 'Two' ), __METHOD__
);
1225 $db = wfGetDB( DB_MASTER
);
1226 $arQuery = $store->getArchiveQueryInfo();
1227 $row = $db->selectRow(
1228 $arQuery['tables'], $arQuery['fields'], [ 'ar_rev_id' => $orig->getId() ],
1229 __METHOD__
, [], $arQuery['joins']
1232 $this->assertNotFalse( $row, 'query failed' );
1234 $record = $store->newRevisionFromArchiveRow(
1238 [ 'page_id' => $title->getArticleID() ]
1241 $restored = $store->insertRevisionOn( $record, $db );
1243 // is the new revision correct?
1244 $this->assertRevisionCompleteness( $restored );
1245 $this->assertRevisionRecordsEqual( $record, $restored );
1247 // does the new revision use the original slot?
1248 $recMain = $record->getSlot( SlotRecord
::MAIN
);
1249 $restMain = $restored->getSlot( SlotRecord
::MAIN
);
1250 $this->assertSame( $recMain->getAddress(), $restMain->getAddress() );
1251 $this->assertSame( $recMain->getContentId(), $restMain->getContentId() );
1252 $this->assertSame( $recMain->getOrigin(), $restMain->getOrigin() );
1253 $this->assertSame( 'Foo', $restMain->getContent()->serialize() );
1255 // can we load it from the store?
1256 $loaded = $store->getRevisionById( $restored->getId() );
1257 $this->assertNotNull( $loaded );
1258 $this->assertRevisionCompleteness( $loaded );
1259 $this->assertRevisionRecordsEqual( $restored, $loaded );
1261 // can we find it directly in the database?
1262 $this->assertRevisionExistsInDatabase( $restored );
1266 * @covers \MediaWiki\Revision\RevisionStore::loadRevisionFromId
1268 public function testLoadRevisionFromId() {
1269 $title = Title
::newFromText( __METHOD__
);
1270 $page = WikiPage
::factory( $title );
1271 /** @var Revision $rev */
1272 $rev = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
)
1273 ->value
['revision'];
1275 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1276 $result = $store->loadRevisionFromId( wfGetDB( DB_MASTER
), $rev->getId() );
1277 $this->assertRevisionRecordMatchesRevision( $rev, $result );
1281 * @covers \MediaWiki\Revision\RevisionStore::loadRevisionFromPageId
1283 public function testLoadRevisionFromPageId() {
1284 $title = Title
::newFromText( __METHOD__
);
1285 $page = WikiPage
::factory( $title );
1286 /** @var Revision $rev */
1287 $rev = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
)
1288 ->value
['revision'];
1290 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1291 $result = $store->loadRevisionFromPageId( wfGetDB( DB_MASTER
), $page->getId() );
1292 $this->assertRevisionRecordMatchesRevision( $rev, $result );
1296 * @covers \MediaWiki\Revision\RevisionStore::loadRevisionFromTitle
1298 public function testLoadRevisionFromTitle() {
1299 $title = Title
::newFromText( __METHOD__
);
1300 $page = WikiPage
::factory( $title );
1301 /** @var Revision $rev */
1302 $rev = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
)
1303 ->value
['revision'];
1305 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1306 $result = $store->loadRevisionFromTitle( wfGetDB( DB_MASTER
), $title );
1307 $this->assertRevisionRecordMatchesRevision( $rev, $result );
1311 * @covers \MediaWiki\Revision\RevisionStore::loadRevisionFromTimestamp
1313 public function testLoadRevisionFromTimestamp() {
1314 $title = Title
::newFromText( __METHOD__
);
1315 $page = WikiPage
::factory( $title );
1316 /** @var Revision $revOne */
1317 $revOne = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
)
1318 ->value
['revision'];
1319 // Sleep to ensure different timestamps... )(evil)
1321 /** @var Revision $revTwo */
1322 $revTwo = $page->doEditContent( new WikitextContent( __METHOD__
. 'a' ), '' )
1323 ->value
['revision'];
1325 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1327 $store->loadRevisionFromTimestamp( wfGetDB( DB_MASTER
), $title, '20150101010101' )
1331 $store->loadRevisionFromTimestamp(
1332 wfGetDB( DB_MASTER
),
1334 $revOne->getTimestamp()
1339 $store->loadRevisionFromTimestamp(
1340 wfGetDB( DB_MASTER
),
1342 $revTwo->getTimestamp()
1348 * @covers \MediaWiki\Revision\RevisionStore::listRevisionSizes
1350 public function testGetParentLengths() {
1351 $page = WikiPage
::factory( Title
::newFromText( __METHOD__
) );
1352 /** @var Revision $revOne */
1353 $revOne = $page->doEditContent(
1354 new WikitextContent( __METHOD__
), __METHOD__
1355 )->value
['revision'];
1356 /** @var Revision $revTwo */
1357 $revTwo = $page->doEditContent(
1358 new WikitextContent( __METHOD__
. '2' ), __METHOD__
1359 )->value
['revision'];
1361 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1364 $revOne->getId() => strlen( __METHOD__
),
1366 $store->listRevisionSizes(
1367 wfGetDB( DB_MASTER
),
1368 [ $revOne->getId() ]
1373 $revOne->getId() => strlen( __METHOD__
),
1374 $revTwo->getId() => strlen( __METHOD__
) +
1,
1376 $store->listRevisionSizes(
1377 wfGetDB( DB_MASTER
),
1378 [ $revOne->getId(), $revTwo->getId() ]
1384 * @covers \MediaWiki\Revision\RevisionStore::getPreviousRevision
1386 public function testGetPreviousRevision() {
1387 $page = WikiPage
::factory( Title
::newFromText( __METHOD__
) );
1388 /** @var Revision $revOne */
1389 $revOne = $page->doEditContent(
1390 new WikitextContent( __METHOD__
), __METHOD__
1391 )->value
['revision'];
1392 /** @var Revision $revTwo */
1393 $revTwo = $page->doEditContent(
1394 new WikitextContent( __METHOD__
. '2' ), __METHOD__
1395 )->value
['revision'];
1397 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1399 $store->getPreviousRevision( $store->getRevisionById( $revOne->getId() ) )
1403 $store->getPreviousRevision( $store->getRevisionById( $revTwo->getId() ) )->getId()
1408 * @covers \MediaWiki\Revision\RevisionStore::getNextRevision
1410 public function testGetNextRevision() {
1411 $page = WikiPage
::factory( Title
::newFromText( __METHOD__
) );
1412 /** @var Revision $revOne */
1413 $revOne = $page->doEditContent(
1414 new WikitextContent( __METHOD__
), __METHOD__
1415 )->value
['revision'];
1416 /** @var Revision $revTwo */
1417 $revTwo = $page->doEditContent(
1418 new WikitextContent( __METHOD__
. '2' ), __METHOD__
1419 )->value
['revision'];
1421 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1424 $store->getNextRevision( $store->getRevisionById( $revOne->getId() ) )->getId()
1427 $store->getNextRevision( $store->getRevisionById( $revTwo->getId() ) )
1431 public function provideNonHistoryRevision() {
1432 $title = Title
::newFromText( __METHOD__
);
1433 $rev = new MutableRevisionRecord( $title );
1436 $user = new UserIdentityValue( 7, 'Frank', 0 );
1437 $comment = CommentStoreComment
::newUnsavedComment( 'Test' );
1440 'ar_rev_id' => 34567,
1443 'ar_minor_edit' => 0,
1444 'ar_timestamp' => '20180101020202',
1446 $slots = new RevisionSlots( [] );
1447 $rev = new RevisionArchiveRecord( $title, $user, $comment, $row, $slots );
1452 * @dataProvider provideNonHistoryRevision
1453 * @covers \MediaWiki\Revision\RevisionStore::getPreviousRevision
1455 public function testGetPreviousRevision_bad( RevisionRecord
$rev ) {
1456 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1457 $this->assertNull( $store->getPreviousRevision( $rev ) );
1461 * @dataProvider provideNonHistoryRevision
1462 * @covers \MediaWiki\Revision\RevisionStore::getNextRevision
1464 public function testGetNextRevision_bad( RevisionRecord
$rev ) {
1465 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1466 $this->assertNull( $store->getNextRevision( $rev ) );
1470 * @covers \MediaWiki\Revision\RevisionStore::getTimestampFromId
1472 public function testGetTimestampFromId_found() {
1473 $page = $this->getTestPage();
1474 /** @var Revision $rev */
1475 $rev = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
)
1476 ->value
['revision'];
1478 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1479 $result = $store->getTimestampFromId( $rev->getId() );
1481 $this->assertSame( $rev->getTimestamp(), $result );
1485 * @covers \MediaWiki\Revision\RevisionStore::getTimestampFromId
1487 public function testGetTimestampFromId_notFound() {
1488 $page = $this->getTestPage();
1489 /** @var Revision $rev */
1490 $rev = $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
)
1491 ->value
['revision'];
1493 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1494 $result = $store->getTimestampFromId( $rev->getId() +
1 );
1496 $this->assertFalse( $result );
1500 * @covers \MediaWiki\Revision\RevisionStore::countRevisionsByPageId
1502 public function testCountRevisionsByPageId() {
1503 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1504 $page = WikiPage
::factory( Title
::newFromText( __METHOD__
) );
1508 $store->countRevisionsByPageId( wfGetDB( DB_MASTER
), $page->getId() )
1510 $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1513 $store->countRevisionsByPageId( wfGetDB( DB_MASTER
), $page->getId() )
1515 $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1518 $store->countRevisionsByPageId( wfGetDB( DB_MASTER
), $page->getId() )
1523 * @covers \MediaWiki\Revision\RevisionStore::countRevisionsByTitle
1525 public function testCountRevisionsByTitle() {
1526 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1527 $page = WikiPage
::factory( Title
::newFromText( __METHOD__
) );
1531 $store->countRevisionsByTitle( wfGetDB( DB_MASTER
), $page->getTitle() )
1533 $page->doEditContent( new WikitextContent( 'a' ), 'a' );
1536 $store->countRevisionsByTitle( wfGetDB( DB_MASTER
), $page->getTitle() )
1538 $page->doEditContent( new WikitextContent( 'b' ), 'b' );
1541 $store->countRevisionsByTitle( wfGetDB( DB_MASTER
), $page->getTitle() )
1546 * @covers \MediaWiki\Revision\RevisionStore::userWasLastToEdit
1548 public function testUserWasLastToEdit_false() {
1549 $sysop = $this->getTestSysop()->getUser();
1550 $page = $this->getTestPage();
1551 $page->doEditContent( new WikitextContent( __METHOD__
), __METHOD__
);
1553 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1554 $result = $store->userWasLastToEdit(
1555 wfGetDB( DB_MASTER
),
1560 $this->assertFalse( $result );
1564 * @covers \MediaWiki\Revision\RevisionStore::userWasLastToEdit
1566 public function testUserWasLastToEdit_true() {
1567 $startTime = wfTimestampNow();
1568 $sysop = $this->getTestSysop()->getUser();
1569 $page = $this->getTestPage();
1570 $page->doEditContent(
1571 new WikitextContent( __METHOD__
),
1578 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1579 $result = $store->userWasLastToEdit(
1580 wfGetDB( DB_MASTER
),
1585 $this->assertTrue( $result );
1589 * @covers \MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
1591 public function testGetKnownCurrentRevision() {
1592 $page = $this->getTestPage();
1593 /** @var Revision $rev */
1594 $rev = $page->doEditContent(
1595 new WikitextContent( __METHOD__
. 'b' ),
1599 $this->getTestUser()->getUser()
1600 )->value
['revision'];
1602 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1603 $record = $store->getKnownCurrentRevision(
1608 $this->assertRevisionRecordMatchesRevision( $rev, $record );
1611 public function provideNewMutableRevisionFromArray() {
1612 yield
'Basic array, content object' => [
1616 'timestamp' => '20171017114835',
1617 'user_text' => '111.0.1.2',
1619 'minor_edit' => false,
1623 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1624 'comment' => 'Goat Comment!',
1625 'content' => new WikitextContent( 'Some Content' ),
1628 yield
'Basic array, serialized text' => [
1632 'timestamp' => '20171017114835',
1633 'user_text' => '111.0.1.2',
1635 'minor_edit' => false,
1639 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1640 'comment' => 'Goat Comment!',
1641 'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1644 yield
'Basic array, serialized text, utf-8 flags' => [
1648 'timestamp' => '20171017114835',
1649 'user_text' => '111.0.1.2',
1651 'minor_edit' => false,
1655 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1656 'comment' => 'Goat Comment!',
1657 'text' => ( new WikitextContent( 'Söme Content' ) )->serialize(),
1661 yield
'Basic array, with title' => [
1663 'title' => Title
::newFromText( 'SomeText' ),
1664 'timestamp' => '20171017114835',
1665 'user_text' => '111.0.1.2',
1667 'minor_edit' => false,
1671 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1672 'comment' => 'Goat Comment!',
1673 'content' => new WikitextContent( 'Some Content' ),
1676 yield
'Basic array, no user field' => [
1680 'timestamp' => '20171017114835',
1681 'user_text' => '111.0.1.3',
1682 'minor_edit' => false,
1686 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
1687 'comment' => 'Goat Comment!',
1688 'content' => new WikitextContent( 'Some Content' ),
1694 * @dataProvider provideNewMutableRevisionFromArray
1695 * @covers \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray
1697 public function testNewMutableRevisionFromArray( array $array ) {
1698 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1700 // HACK: if $array['page'] is given, make sure that the page exists
1701 if ( isset( $array['page'] ) ) {
1702 $t = Title
::newFromID( $array['page'] );
1703 if ( !$t ||
!$t->exists() ) {
1704 $t = Title
::makeTitle( NS_MAIN
, __METHOD__
);
1705 $info = $this->insertPage( $t );
1706 $array['page'] = $info['id'];
1710 $result = $store->newMutableRevisionFromArray( $array );
1712 if ( isset( $array['id'] ) ) {
1713 $this->assertSame( $array['id'], $result->getId() );
1715 if ( isset( $array['page'] ) ) {
1716 $this->assertSame( $array['page'], $result->getPageId() );
1718 $this->assertSame( $array['timestamp'], $result->getTimestamp() );
1719 $this->assertSame( $array['user_text'], $result->getUser()->getName() );
1720 if ( isset( $array['user'] ) ) {
1721 $this->assertSame( $array['user'], $result->getUser()->getId() );
1723 $this->assertSame( (bool)$array['minor_edit'], $result->isMinor() );
1724 $this->assertSame( $array['deleted'], $result->getVisibility() );
1725 $this->assertSame( $array['len'], $result->getSize() );
1726 $this->assertSame( $array['parent_id'], $result->getParentId() );
1727 $this->assertSame( $array['sha1'], $result->getSha1() );
1728 $this->assertSame( $array['comment'], $result->getComment()->text
);
1729 if ( isset( $array['content'] ) ) {
1730 foreach ( $array['content'] as $role => $content ) {
1732 $result->getContent( $role )->equals( $content )
1735 } elseif ( isset( $array['text'] ) ) {
1736 $this->assertSame( $array['text'],
1737 $result->getSlot( SlotRecord
::MAIN
)->getContent()->serialize() );
1738 } elseif ( isset( $array['content_format'] ) ) {
1740 $array['content_format'],
1741 $result->getSlot( SlotRecord
::MAIN
)->getContent()->getDefaultFormat()
1743 $this->assertSame( $array['content_model'], $result->getSlot( SlotRecord
::MAIN
)->getModel() );
1748 * @dataProvider provideNewMutableRevisionFromArray
1749 * @covers \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray
1751 public function testNewMutableRevisionFromArray_legacyEncoding( array $array ) {
1752 $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1753 $services = MediaWikiServices
::getInstance();
1754 $lb = $services->getDBLoadBalancer();
1755 $access = $services->getExternalStoreAccess();
1756 $blobStore = new SqlBlobStore( $lb, $access, $cache );
1757 $blobStore->setLegacyEncoding( 'windows-1252', Language
::factory( 'en' ) );
1759 $factory = $this->getMockBuilder( BlobStoreFactory
::class )
1760 ->setMethods( [ 'newBlobStore', 'newSqlBlobStore' ] )
1761 ->disableOriginalConstructor()
1763 $factory->expects( $this->any() )
1764 ->method( 'newBlobStore' )
1765 ->willReturn( $blobStore );
1766 $factory->expects( $this->any() )
1767 ->method( 'newSqlBlobStore' )
1768 ->willReturn( $blobStore );
1770 $this->setService( 'BlobStoreFactory', $factory );
1772 $this->testNewMutableRevisionFromArray( $array );
1776 * Creates a new revision for testing caching behavior
1778 * @param WikiPage $page the page for the new revision
1779 * @param RevisionStore $store store object to use for creating the revision
1780 * @return bool|RevisionStoreRecord the revision created, or false if missing
1782 private function createRevisionStoreCacheRecord( $page, $store ) {
1783 $user = MediaWikiTestCase
::getMutableTestUser()->getUser();
1784 $updater = $page->newPageUpdater( $user );
1785 $updater->setContent( SlotRecord
::MAIN
, new WikitextContent( __METHOD__
) );
1786 $summary = CommentStoreComment
::newUnsavedComment( __METHOD__
);
1787 $rev = $updater->saveRevision( $summary, EDIT_NEW
);
1788 return $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1792 * @covers \MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
1794 public function testGetKnownCurrentRevision_userNameChange() {
1795 $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1796 $this->setService( 'MainWANObjectCache', $cache );
1798 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1799 $page = $this->getNonexistingTestPage();
1800 $rev = $this->createRevisionStoreCacheRecord( $page, $store );
1802 // Grab the user name
1803 $userNameBefore = $rev->getUser()->getName();
1805 // Change the user name in the database, "behind the back" of the cache
1806 $newUserName = "Renamed $userNameBefore";
1807 $this->db
->update( 'revision',
1808 [ 'rev_user_text' => $newUserName ],
1809 [ 'rev_id' => $rev->getId() ] );
1810 $this->db
->update( 'user',
1811 [ 'user_name' => $newUserName ],
1812 [ 'user_id' => $rev->getUser()->getId() ] );
1813 $this->db
->update( 'actor',
1814 [ 'actor_name' => $newUserName ],
1815 [ 'actor_user' => $rev->getUser()->getId() ] );
1817 // Reload the revision and regrab the user name.
1818 $revAfter = $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1819 $userNameAfter = $revAfter->getUser()->getName();
1821 // The two user names should be different.
1822 // If they are the same, we are seeing a cached value, which is bad.
1823 $this->assertNotSame( $userNameBefore, $userNameAfter );
1825 // This is implied by the above assertion, but explicitly check it, for completeness
1826 $this->assertSame( $newUserName, $userNameAfter );
1830 * @covers \MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
1832 public function testGetKnownCurrentRevision_revDelete() {
1833 $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
1834 $this->setService( 'MainWANObjectCache', $cache );
1836 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1837 $page = $this->getNonexistingTestPage();
1838 $rev = $this->createRevisionStoreCacheRecord( $page, $store );
1840 // Grab the deleted bitmask
1841 $deletedBefore = $rev->getVisibility();
1843 // Change the deleted bitmask in the database, "behind the back" of the cache
1844 $this->db
->update( 'revision',
1845 [ 'rev_deleted' => RevisionRecord
::DELETED_TEXT
],
1846 [ 'rev_id' => $rev->getId() ] );
1848 // Reload the revision and regrab the visibility flag.
1849 $revAfter = $store->getKnownCurrentRevision( $page->getTitle(), $rev->getId() );
1850 $deletedAfter = $revAfter->getVisibility();
1852 // The two deleted flags should be different.
1853 // If they are the same, we are seeing a cached value, which is bad.
1854 $this->assertNotSame( $deletedBefore, $deletedAfter );
1856 // This is implied by the above assertion, but explicitly check it, for completeness
1857 $this->assertSame( RevisionRecord
::DELETED_TEXT
, $deletedAfter );
1861 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
1863 public function testNewRevisionFromRow_userNameChange() {
1864 $page = $this->getTestPage();
1866 /** @var Revision $rev */
1867 $rev = $page->doEditContent(
1868 new WikitextContent( $text ),
1872 $this->getMutableTestUser()->getUser()
1873 )->value
['revision'];
1875 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1876 $record = $store->newRevisionFromRow(
1877 $this->revisionToRow( $rev ),
1882 // Grab the user name
1883 $userNameBefore = $record->getUser()->getName();
1885 // Change the user name in the database
1886 $newUserName = "Renamed $userNameBefore";
1887 $this->db
->update( 'revision',
1888 [ 'rev_user_text' => $newUserName ],
1889 [ 'rev_id' => $record->getId() ] );
1890 $this->db
->update( 'user',
1891 [ 'user_name' => $newUserName ],
1892 [ 'user_id' => $record->getUser()->getId() ] );
1893 $this->db
->update( 'actor',
1894 [ 'actor_name' => $newUserName ],
1895 [ 'actor_user' => $record->getUser()->getId() ] );
1897 // Reload the record, passing $fromCache as true to force fresh info from the db,
1898 // and regrab the user name
1899 $recordAfter = $store->newRevisionFromRow(
1900 $this->revisionToRow( $rev ),
1905 $userNameAfter = $recordAfter->getUser()->getName();
1907 // The two user names should be different.
1908 // If they are the same, we are seeing a cached value, which is bad.
1909 $this->assertNotSame( $userNameBefore, $userNameAfter );
1911 // This is implied by the above assertion, but explicitly check it, for completeness
1912 $this->assertSame( $newUserName, $userNameAfter );
1916 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
1918 public function testNewRevisionFromRow_revDelete() {
1919 $page = $this->getTestPage();
1921 /** @var Revision $rev */
1922 $rev = $page->doEditContent(
1923 new WikitextContent( $text ),
1925 )->value
['revision'];
1927 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1928 $record = $store->newRevisionFromRow(
1929 $this->revisionToRow( $rev ),
1934 // Grab the deleted bitmask
1935 $deletedBefore = $record->getVisibility();
1937 // Change the deleted bitmask in the database
1938 $this->db
->update( 'revision',
1939 [ 'rev_deleted' => RevisionRecord
::DELETED_TEXT
],
1940 [ 'rev_id' => $record->getId() ] );
1942 // Reload the record, passing $fromCache as true to force fresh info from the db,
1943 // and regrab the deleted bitmask
1944 $recordAfter = $store->newRevisionFromRow(
1945 $this->revisionToRow( $rev ),
1950 $deletedAfter = $recordAfter->getVisibility();
1952 // The two deleted flags should be different, because we modified the database.
1953 $this->assertNotSame( $deletedBefore, $deletedAfter );
1955 // This is implied by the above assertion, but explicitly check it, for completeness
1956 $this->assertSame( RevisionRecord
::DELETED_TEXT
, $deletedAfter );
1959 public function provideNewRevisionsFromBatchOptions() {
1960 yield
'No preload slots or content, single page' => [
1964 yield
'Preload slots and content, single page' => [
1967 'slots' => [ SlotRecord
::MAIN
],
1971 yield
'No preload slots or content, multiple pages' => [
1975 yield
'Preload slots and content, multiple pages' => [
1978 'slots' => [ SlotRecord
::MAIN
],
1985 * @dataProvider provideNewRevisionsFromBatchOptions
1986 * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
1987 * @param string|null $otherPageTitle
1988 * @param array|null $options
1989 * @throws \MWException
1991 public function testNewRevisionsFromBatch_preloadContent(
1992 $otherPageTitle = null,
1995 $page1 = $this->getTestPage();
1996 $text = __METHOD__
. 'b-ä';
1997 $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' );
1998 $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 1' );
1999 /** @var Revision $rev1 */
2000 $rev1 = $editStatus->getValue()['revision'];
2002 $page2 = $this->getTestPage( $otherPageTitle );
2003 $editStatus = $this->editPage( $page2->getTitle()->getPrefixedDBkey(), $text . '2' );
2004 $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 2' );
2005 /** @var Revision $rev2 */
2006 $rev2 = $editStatus->getValue()['revision'];
2008 $store = MediaWikiServices
::getInstance()->getRevisionStore();
2009 $result = $store->newRevisionsFromBatch(
2010 [ $this->revisionToRow( $rev1 ), $this->revisionToRow( $rev2 ) ],
2013 $this->assertTrue( $result->isGood() );
2014 $this->assertEmpty( $result->getErrors() );
2015 /** @var RevisionRecord[] $records */
2016 $records = $result->getValue();
2017 $this->assertRevisionRecordMatchesRevision( $rev1, $records[$rev1->getId()] );
2018 $this->assertRevisionRecordMatchesRevision( $rev2, $records[$rev2->getId()] );
2020 $this->assertSame( $text . '1',
2021 ContentHandler
::getContentText( $records[$rev1->getId()]->getContent( SlotRecord
::MAIN
) ) );
2022 $this->assertSame( $text . '2',
2023 ContentHandler
::getContentText( $records[$rev2->getId()]->getContent( SlotRecord
::MAIN
) ) );
2024 $this->assertEquals( $page1->getTitle()->getDBkey(),
2025 $records[$rev1->getId()]->getPageAsLinkTarget()->getDBkey() );
2026 $this->assertEquals( $page2->getTitle()->getDBkey(),
2027 $records[$rev2->getId()]->getPageAsLinkTarget()->getDBkey() );
2031 * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
2033 public function testNewRevisionsFromBatch_emptyBatch() {
2034 $result = MediaWikiServices
::getInstance()->getRevisionStore()
2035 ->newRevisionsFromBatch(
2038 'slots' => [ SlotRecord
::MAIN
],
2042 $this->assertTrue( $result->isGood() );
2043 $this->assertEmpty( $result->getValue() );
2044 $this->assertEmpty( $result->getErrors() );
2048 * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
2050 public function testNewRevisionsFromBatch_wrongTitle() {
2051 $page1 = $this->getTestPage();
2052 $text = __METHOD__
. 'b-ä';
2053 $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' );
2054 $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 1' );
2055 /** @var Revision $rev1 */
2056 $rev1 = $editStatus->getValue()['revision'];
2058 $this->setExpectedException( InvalidArgumentException
::class );
2059 MediaWikiServices
::getInstance()->getRevisionStore()
2060 ->newRevisionsFromBatch(
2061 [ $this->revisionToRow( $rev1 ) ],
2063 IDBAccessObject
::READ_NORMAL
,
2064 $this->getTestPage( 'Title_Other_Then_The_One_Revision_Belongs_To' )->getTitle()
2069 * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
2071 public function testNewRevisionsFromBatch_DuplicateRows() {
2072 $page1 = $this->getTestPage();
2073 $text = __METHOD__
. 'b-ä';
2074 $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' );
2075 $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 1' );
2076 /** @var Revision $rev1 */
2077 $rev1 = $editStatus->getValue()['revision'];
2079 $status = MediaWikiServices
::getInstance()->getRevisionStore()
2080 ->newRevisionsFromBatch( [ $this->revisionToRow( $rev1 ), $this->revisionToRow( $rev1 ) ] );
2082 $this->assertFalse( $status->isGood() );
2083 $this->assertTrue( $status->hasMessage( 'internalerror' ) );