3 namespace MediaWiki\Tests\Revision
;
5 use CommentStoreComment
;
6 use MediaWiki\MediaWikiServices
;
7 use MediaWiki\Revision\MutableRevisionRecord
;
8 use MediaWiki\Revision\RevisionRecord
;
9 use MediaWiki\Revision\SlotRecord
;
15 * Tests RevisionStore against the post-migration MCR DB schema.
17 * @covers \MediaWiki\Revision\RevisionStore
19 * @group RevisionStore
24 class McrRevisionStoreDbTest
extends RevisionStoreDbTestBase
{
26 use McrSchemaOverride
;
28 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
29 $numberOfSlots = count( $rev->getSlotRoles() );
31 // new schema is written
35 [ 'slot_revision_id' => $rev->getId() ],
36 [ [ (string)$numberOfSlots ] ]
39 $store = MediaWikiServices
::getInstance()->getRevisionStore();
40 $revQuery = $store->getSlotsQueryInfo( [ 'content' ] );
46 'slot_revision_id' => $rev->getId(),
48 [ [ (string)$numberOfSlots ] ],
53 parent
::assertRevisionExistsInDatabase( $rev );
57 * @param SlotRecord $a
58 * @param SlotRecord $b
60 protected function assertSameSlotContent( SlotRecord
$a, SlotRecord
$b ) {
61 parent
::assertSameSlotContent( $a, $b );
63 // Assert that the same content ID has been used
64 $this->assertSame( $a->getContentId(), $b->getContentId() );
67 public function provideInsertRevisionOn_successes() {
68 foreach ( parent
::provideInsertRevisionOn_successes() as $case ) {
72 yield
'Multi-slot revision insertion' => [
75 'main' => new WikitextContent( 'Chicken' ),
76 'aux' => new TextContent( 'Egg' ),
79 'comment' => $this->getRandomCommentStoreComment(),
80 'timestamp' => '20171117010101',
86 public function provideNewNullRevision() {
87 foreach ( parent
::provideNewNullRevision() as $case ) {
92 Title
::newFromText( 'UTPage_notAutoCreated' ),
95 'main' => new WikitextContent( 'Chicken' ),
96 'aux' => new WikitextContent( 'Omelet' ),
99 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment multi' ),
103 public function provideNewMutableRevisionFromArray() {
104 foreach ( parent
::provideNewMutableRevisionFromArray() as $case ) {
108 yield
'Basic array, multiple roles' => [
112 'timestamp' => '20171017114835',
113 'user_text' => '111.0.1.2',
115 'minor_edit' => false,
119 'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
120 'comment' => 'Goat Comment!',
122 'main' => new WikitextContent( 'Söme Cöntent' ),
123 'aux' => new TextContent( 'Öther Cöntent' ),
129 public function testGetQueryInfo_NoSlotDataJoin() {
130 $store = MediaWikiServices
::getInstance()->getRevisionStore();
131 $queryInfo = $store->getQueryInfo();
133 // with the new schema enabled, query info should not join the main slot info
134 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['tables'] ) );
135 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['joins'] ) );
139 * @covers \MediaWiki\Revision\RevisionStore::insertRevisionOn
140 * @covers \MediaWiki\Revision\RevisionStore::insertSlotRowOn
141 * @covers \MediaWiki\Revision\RevisionStore::insertContentRowOn
143 public function testInsertRevisionOn_T202032() {
144 // This test only makes sense for MySQL
145 if ( $this->db
->getType() !== 'mysql' ) {
146 $this->assertTrue( true );
150 // NOTE: must be done before checking MAX(rev_id)
151 $page = $this->getTestPage();
153 $maxRevId = $this->db
->selectField( 'revision', 'MAX(rev_id)' );
155 // Construct a slot row that will conflict with the insertion of the next revision ID,
156 // to emulate the failure mode described in T202032. Nothing will ever read this row,
157 // we just need it to trigger a primary key conflict.
158 $this->db
->insert( 'slots', [
159 'slot_revision_id' => $maxRevId +
1,
161 'slot_content_id' => 0,
165 $rev = new MutableRevisionRecord( $page->getTitle() );
166 $rev->setTimestamp( '20180101000000' );
167 $rev->setComment( CommentStoreComment
::newUnsavedComment( 'test' ) );
168 $rev->setUser( $this->getTestUser()->getUser() );
169 $rev->setContent( 'main', new WikitextContent( 'Text' ) );
170 $rev->setPageId( $page->getId() );
172 $store = MediaWikiServices
::getInstance()->getRevisionStore();
173 $return = $store->insertRevisionOn( $rev, $this->db
);
175 $this->assertSame( $maxRevId +
2, $return->getId() );
177 // is the new revision correct?
178 $this->assertRevisionCompleteness( $return );
179 $this->assertRevisionRecordsEqual( $rev, $return );
181 // can we find it directly in the database?
182 $this->assertRevisionExistsInDatabase( $return );
184 // can we load it from the store?
185 $loaded = $store->getRevisionById( $return->getId() );
186 $this->assertRevisionCompleteness( $loaded );
187 $this->assertRevisionRecordsEqual( $return, $loaded );