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'] ) );
137 public function provideGetArchiveQueryInfo() {
143 'fields' => array_merge(
144 $this->getDefaultArchiveFields( false ),
146 'ar_comment_text' => 'ar_comment',
147 'ar_comment_data' => 'NULL',
148 'ar_comment_cid' => 'NULL',
149 'ar_user_text' => 'ar_user_text',
150 'ar_user' => 'ar_user',
151 'ar_actor' => 'NULL',
160 public function provideGetQueryInfo() {
161 // TODO: more option variations
170 'fields' => array_merge(
171 $this->getDefaultQueryFields( false ),
172 $this->getCommentQueryFields(),
173 $this->getActorQueryFields(),
185 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
186 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
192 public function provideGetSlotsQueryInfo() {
200 'fields' => array_merge(
209 'slot_roles' => [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ],
222 'fields' => array_merge(
235 'slot_roles' => [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ],
236 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
237 'content_models' => [ 'INNER JOIN', [ 'content_model = model_id' ] ],
244 * @covers \MediaWiki\Storage\RevisionStore::insertRevisionOn
245 * @covers \MediaWiki\Storage\RevisionStore::insertSlotRowOn
246 * @covers \MediaWiki\Storage\RevisionStore::insertContentRowOn
248 public function testInsertRevisionOn_T202032() {
249 // This test only makes sense for MySQL
250 if ( $this->db
->getType() !== 'mysql' ) {
251 $this->assertTrue( true );
255 // NOTE: must be done before checking MAX(rev_id)
256 $page = $this->getTestPage();
258 $maxRevId = $this->db
->selectField( 'revision', 'MAX(rev_id)' );
260 // Construct a slot row that will conflict with the insertion of the next revision ID,
261 // to emulate the failure mode described in T202032. Nothing will ever read this row,
262 // we just need it to trigger a primary key conflict.
263 $this->db
->insert( 'slots', [
264 'slot_revision_id' => $maxRevId +
1,
266 'slot_content_id' => 0,
270 $rev = new MutableRevisionRecord( $page->getTitle() );
271 $rev->setTimestamp( '20180101000000' );
272 $rev->setComment( CommentStoreComment
::newUnsavedComment( 'test' ) );
273 $rev->setUser( $this->getTestUser()->getUser() );
274 $rev->setContent( 'main', new WikitextContent( 'Text' ) );
275 $rev->setPageId( $page->getId() );
277 $store = MediaWikiServices
::getInstance()->getRevisionStore();
278 $return = $store->insertRevisionOn( $rev, $this->db
);
280 $this->assertSame( $maxRevId +
2, $return->getId() );
282 // is the new revision correct?
283 $this->assertRevisionCompleteness( $return );
284 $this->assertRevisionRecordsEqual( $rev, $return );
286 // can we find it directly in the database?
287 $this->assertRevisionExistsInDatabase( $return );
289 // can we load it from the store?
290 $loaded = $store->getRevisionById( $return->getId() );
291 $this->assertRevisionCompleteness( $loaded );
292 $this->assertRevisionRecordsEqual( $return, $loaded );