2 namespace MediaWiki\Tests\Storage
;
4 use CommentStoreComment
;
5 use MediaWiki\MediaWikiServices
;
6 use MediaWiki\Storage\MutableRevisionRecord
;
7 use MediaWiki\Storage\RevisionRecord
;
8 use MediaWiki\Storage\SlotRecord
;
14 * Tests RevisionStore against the post-migration MCR DB schema.
16 * @covers \MediaWiki\Storage\RevisionStore
18 * @group RevisionStore
23 class McrRevisionStoreDbTest
extends RevisionStoreDbTestBase
{
25 use McrSchemaOverride
;
27 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
28 $numberOfSlots = count( $rev->getSlotRoles() );
30 // new schema is written
34 [ 'slot_revision_id' => $rev->getId() ],
35 [ [ (string)$numberOfSlots ] ]
38 $store = MediaWikiServices
::getInstance()->getRevisionStore();
39 $revQuery = $store->getSlotsQueryInfo( [ 'content' ] );
45 'slot_revision_id' => $rev->getId(),
47 [ [ (string)$numberOfSlots ] ],
52 parent
::assertRevisionExistsInDatabase( $rev );
56 * @param SlotRecord $a
57 * @param SlotRecord $b
59 protected function assertSameSlotContent( SlotRecord
$a, SlotRecord
$b ) {
60 parent
::assertSameSlotContent( $a, $b );
62 // Assert that the same content ID has been used
63 $this->assertSame( $a->getContentId(), $b->getContentId() );
66 public function provideInsertRevisionOn_successes() {
67 foreach ( parent
::provideInsertRevisionOn_successes() as $case ) {
71 yield
'Multi-slot revision insertion' => [
74 'main' => new WikitextContent( 'Chicken' ),
75 'aux' => new TextContent( 'Egg' ),
78 'comment' => $this->getRandomCommentStoreComment(),
79 'timestamp' => '20171117010101',
85 public function provideNewNullRevision() {
86 foreach ( parent
::provideNewNullRevision() as $case ) {
91 Title
::newFromText( 'UTPage_notAutoCreated' ),
94 'main' => new WikitextContent( 'Chicken' ),
95 'aux' => new WikitextContent( 'Omelet' ),
98 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment multi' ),
102 public function provideNewMutableRevisionFromArray() {
103 foreach ( parent
::provideNewMutableRevisionFromArray() as $case ) {
107 yield
'Basic array, multiple roles' => [
111 'timestamp' => '20171017114835',
112 'user_text' => '111.0.1.2',
114 'minor_edit' => false,
118 'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
119 'comment' => 'Goat Comment!',
121 'main' => new WikitextContent( 'Söme Cöntent' ),
122 'aux' => new TextContent( 'Öther Cöntent' ),
128 public function testGetQueryInfo_NoSlotDataJoin() {
129 $store = MediaWikiServices
::getInstance()->getRevisionStore();
130 $queryInfo = $store->getQueryInfo();
132 // with the new schema enabled, query info should not join the main slot info
133 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['tables'] ) );
134 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['joins'] ) );
138 * @covers \MediaWiki\Storage\RevisionStore::insertRevisionOn
139 * @covers \MediaWiki\Storage\RevisionStore::insertSlotRowOn
140 * @covers \MediaWiki\Storage\RevisionStore::insertContentRowOn
142 public function testInsertRevisionOn_T202032() {
143 // This test only makes sense for MySQL
144 if ( $this->db
->getType() !== 'mysql' ) {
145 $this->assertTrue( true );
149 // NOTE: must be done before checking MAX(rev_id)
150 $page = $this->getTestPage();
152 $maxRevId = $this->db
->selectField( 'revision', 'MAX(rev_id)' );
154 // Construct a slot row that will conflict with the insertion of the next revision ID,
155 // to emulate the failure mode described in T202032. Nothing will ever read this row,
156 // we just need it to trigger a primary key conflict.
157 $this->db
->insert( 'slots', [
158 'slot_revision_id' => $maxRevId +
1,
160 'slot_content_id' => 0,
164 $rev = new MutableRevisionRecord( $page->getTitle() );
165 $rev->setTimestamp( '20180101000000' );
166 $rev->setComment( CommentStoreComment
::newUnsavedComment( 'test' ) );
167 $rev->setUser( $this->getTestUser()->getUser() );
168 $rev->setContent( 'main', new WikitextContent( 'Text' ) );
169 $rev->setPageId( $page->getId() );
171 $store = MediaWikiServices
::getInstance()->getRevisionStore();
172 $return = $store->insertRevisionOn( $rev, $this->db
);
174 $this->assertSame( $maxRevId +
2, $return->getId() );
176 // is the new revision correct?
177 $this->assertRevisionCompleteness( $return );
178 $this->assertRevisionRecordsEqual( $rev, $return );
180 // can we find it directly in the database?
181 $this->assertRevisionExistsInDatabase( $return );
183 // can we load it from the store?
184 $loaded = $store->getRevisionById( $return->getId() );
185 $this->assertRevisionCompleteness( $loaded );
186 $this->assertRevisionRecordsEqual( $return, $loaded );