MediaWiki REL1_33
McrRevisionStoreDbTest.php
Go to the documentation of this file.
1<?php
3
12
24
26
28 $numberOfSlots = count( $rev->getSlotRoles() );
29
30 // new schema is written
31 $this->assertSelect(
32 'slots',
33 [ 'count(*)' ],
34 [ 'slot_revision_id' => $rev->getId() ],
35 [ [ (string)$numberOfSlots ] ]
36 );
37
38 $store = MediaWikiServices::getInstance()->getRevisionStore();
39 $revQuery = $store->getSlotsQueryInfo( [ 'content' ] );
40
41 $this->assertSelect(
42 $revQuery['tables'],
43 [ 'count(*)' ],
44 [
45 'slot_revision_id' => $rev->getId(),
46 ],
47 [ [ (string)$numberOfSlots ] ],
48 [],
49 $revQuery['joins']
50 );
51
52 parent::assertRevisionExistsInDatabase( $rev );
53 }
54
59 protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
60 parent::assertSameSlotContent( $a, $b );
61
62 // Assert that the same content ID has been used
63 $this->assertSame( $a->getContentId(), $b->getContentId() );
64 }
65
67 foreach ( parent::provideInsertRevisionOn_successes() as $case ) {
68 yield $case;
69 }
70
71 yield 'Multi-slot revision insertion' => [
72 [
73 'content' => [
74 'main' => new WikitextContent( 'Chicken' ),
75 'aux' => new TextContent( 'Egg' ),
76 ],
77 'page' => true,
78 'comment' => $this->getRandomCommentStoreComment(),
79 'timestamp' => '20171117010101',
80 'user' => true,
81 ],
82 ];
83 }
84
85 public function provideNewNullRevision() {
86 foreach ( parent::provideNewNullRevision() as $case ) {
87 yield $case;
88 }
89
90 yield [
91 Title::newFromText( 'UTPage_notAutoCreated' ),
92 [
93 'content' => [
94 'main' => new WikitextContent( 'Chicken' ),
95 'aux' => new WikitextContent( 'Omelet' ),
96 ],
97 ],
98 CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment multi' ),
99 ];
100 }
101
103 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
104 yield $case;
105 }
106
107 yield 'Basic array, multiple roles' => [
108 [
109 'id' => 2,
110 'page' => 1,
111 'timestamp' => '20171017114835',
112 'user_text' => '111.0.1.2',
113 'user' => 0,
114 'minor_edit' => false,
115 'deleted' => 0,
116 'len' => 29,
117 'parent_id' => 1,
118 'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
119 'comment' => 'Goat Comment!',
120 'content' => [
121 'main' => new WikitextContent( 'Söme Cöntent' ),
122 'aux' => new TextContent( 'Öther Cöntent' ),
123 ]
124 ]
125 ];
126 }
127
129 $store = MediaWikiServices::getInstance()->getRevisionStore();
130 $queryInfo = $store->getQueryInfo();
131
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'] ) );
135 }
136
143 // This test only makes sense for MySQL
144 if ( $this->db->getType() !== 'mysql' ) {
145 $this->assertTrue( true );
146 return;
147 }
148
149 // NOTE: must be done before checking MAX(rev_id)
150 $page = $this->getTestPage();
151
152 $maxRevId = $this->db->selectField( 'revision', 'MAX(rev_id)' );
153
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,
159 'slot_role_id' => 1,
160 'slot_content_id' => 0,
161 'slot_origin' => 0
162 ], __METHOD__ );
163
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() );
170
171 $store = MediaWikiServices::getInstance()->getRevisionStore();
172 $return = $store->insertRevisionOn( $rev, $this->db );
173
174 $this->assertSame( $maxRevId + 2, $return->getId() );
175
176 // is the new revision correct?
177 $this->assertRevisionCompleteness( $return );
178 $this->assertRevisionRecordsEqual( $rev, $return );
179
180 // can we find it directly in the database?
181 $this->assertRevisionExistsInDatabase( $return );
182
183 // can we load it from the store?
184 $loaded = $store->getRevisionById( $return->getId() );
185 $this->assertRevisionCompleteness( $loaded );
186 $this->assertRevisionRecordsEqual( $return, $loaded );
187 }
188
189}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
CommentStoreComment represents a comment stored by CommentStore.
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
assertSelect( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
Asserts that the given database query yields the rows given by $expectedRows.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Page revision base class.
Value object representing a content slot associated with a page revision.
getContentId()
Returns the ID of the content meta data row associated with the slot.
Tests RevisionStore against the post-migration MCR DB schema.
testInsertRevisionOn_T202032()
\MediaWiki\Revision\RevisionStore::insertRevisionOn \MediaWiki\Revision\RevisionStore::insertSlotRowO...
assertRevisionRecordsEqual(RevisionRecord $r1, RevisionRecord $r2)
Content object implementation for representing flat text.
Represents a title within MediaWiki.
Definition Title.php:40
Content object for wiki text pages.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1779
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
trait McrSchemaOverride
Trait providing schema overrides that allow tests to run against the post-migration MCR database sche...