Merge "rdbms: add IDatabase::lockForUpdate() convenience method"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / McrRevisionStoreDbTest.php
1 <?php
2 namespace MediaWiki\Tests\Storage;
3
4 use CommentStoreComment;
5 use MediaWiki\MediaWikiServices;
6 use MediaWiki\Storage\RevisionRecord;
7 use MediaWiki\Storage\SlotRecord;
8 use TextContent;
9 use Title;
10 use WikitextContent;
11
12 /**
13 * Tests RevisionStore against the post-migration MCR DB schema.
14 *
15 * @covers \MediaWiki\Storage\RevisionStore
16 *
17 * @group RevisionStore
18 * @group Storage
19 * @group Database
20 * @group medium
21 */
22 class McrRevisionStoreDbTest extends RevisionStoreDbTestBase {
23
24 use McrSchemaOverride;
25
26 protected function assertRevisionExistsInDatabase( RevisionRecord $rev ) {
27 $numberOfSlots = count( $rev->getSlotRoles() );
28
29 // new schema is written
30 $this->assertSelect(
31 'slots',
32 [ 'count(*)' ],
33 [ 'slot_revision_id' => $rev->getId() ],
34 [ [ (string)$numberOfSlots ] ]
35 );
36
37 $store = MediaWikiServices::getInstance()->getRevisionStore();
38 $revQuery = $store->getSlotsQueryInfo( [ 'content' ] );
39
40 $this->assertSelect(
41 $revQuery['tables'],
42 [ 'count(*)' ],
43 [
44 'slot_revision_id' => $rev->getId(),
45 ],
46 [ [ (string)$numberOfSlots ] ],
47 [],
48 $revQuery['joins']
49 );
50
51 parent::assertRevisionExistsInDatabase( $rev );
52 }
53
54 /**
55 * @param SlotRecord $a
56 * @param SlotRecord $b
57 */
58 protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
59 parent::assertSameSlotContent( $a, $b );
60
61 // Assert that the same content ID has been used
62 $this->assertSame( $a->getContentId(), $b->getContentId() );
63 }
64
65 public function provideInsertRevisionOn_successes() {
66 foreach ( parent::provideInsertRevisionOn_successes() as $case ) {
67 yield $case;
68 }
69
70 yield 'Multi-slot revision insertion' => [
71 [
72 'content' => [
73 'main' => new WikitextContent( 'Chicken' ),
74 'aux' => new TextContent( 'Egg' ),
75 ],
76 'page' => true,
77 'comment' => $this->getRandomCommentStoreComment(),
78 'timestamp' => '20171117010101',
79 'user' => true,
80 ],
81 ];
82 }
83
84 public function provideNewNullRevision() {
85 foreach ( parent::provideNewNullRevision() as $case ) {
86 yield $case;
87 }
88
89 yield [
90 Title::newFromText( 'UTPage_notAutoCreated' ),
91 [
92 'content' => [
93 'main' => new WikitextContent( 'Chicken' ),
94 'aux' => new WikitextContent( 'Omelet' ),
95 ],
96 ],
97 CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment multi' ),
98 ];
99 }
100
101 public function provideNewMutableRevisionFromArray() {
102 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
103 yield $case;
104 }
105
106 yield 'Basic array, multiple roles' => [
107 [
108 'id' => 2,
109 'page' => 1,
110 'timestamp' => '20171017114835',
111 'user_text' => '111.0.1.2',
112 'user' => 0,
113 'minor_edit' => false,
114 'deleted' => 0,
115 'len' => 29,
116 'parent_id' => 1,
117 'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
118 'comment' => 'Goat Comment!',
119 'content' => [
120 'main' => new WikitextContent( 'Söme Cöntent' ),
121 'aux' => new TextContent( 'Öther Cöntent' ),
122 ]
123 ]
124 ];
125 }
126
127 public function testGetQueryInfo_NoSlotDataJoin() {
128 $store = MediaWikiServices::getInstance()->getRevisionStore();
129 $queryInfo = $store->getQueryInfo();
130
131 // with the new schema enabled, query info should not join the main slot info
132 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['tables'] ) );
133 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['joins'] ) );
134 }
135
136 public function provideGetArchiveQueryInfo() {
137 yield [
138 [
139 'tables' => [
140 'archive',
141 ],
142 'fields' => array_merge(
143 $this->getDefaultArchiveFields( false ),
144 [
145 'ar_comment_text' => 'ar_comment',
146 'ar_comment_data' => 'NULL',
147 'ar_comment_cid' => 'NULL',
148 'ar_user_text' => 'ar_user_text',
149 'ar_user' => 'ar_user',
150 'ar_actor' => 'NULL',
151 ]
152 ),
153 'joins' => [
154 ],
155 ]
156 ];
157 }
158
159 public function provideGetQueryInfo() {
160 // TODO: more option variations
161 yield [
162 [ 'page', 'user' ],
163 [
164 'tables' => [
165 'revision',
166 'page',
167 'user',
168 ],
169 'fields' => array_merge(
170 $this->getDefaultQueryFields( false ),
171 $this->getCommentQueryFields(),
172 $this->getActorQueryFields(),
173 [
174 'page_namespace',
175 'page_title',
176 'page_id',
177 'page_latest',
178 'page_is_redirect',
179 'page_len',
180 'user_name',
181 ]
182 ),
183 'joins' => [
184 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
185 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
186 ],
187 ]
188 ];
189 }
190
191 public function provideGetSlotsQueryInfo() {
192 yield [
193 [],
194 [
195 'tables' => [
196 'slots',
197 'slot_roles',
198 ],
199 'fields' => array_merge(
200 [
201 'slot_revision_id',
202 'slot_content_id',
203 'slot_origin',
204 'role_name',
205 ]
206 ),
207 'joins' => [
208 'slot_roles' => [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ],
209 ],
210 ]
211 ];
212 yield [
213 [ 'content' ],
214 [
215 'tables' => [
216 'slots',
217 'slot_roles',
218 'content',
219 'content_models',
220 ],
221 'fields' => array_merge(
222 [
223 'slot_revision_id',
224 'slot_content_id',
225 'slot_origin',
226 'role_name',
227 'content_size',
228 'content_sha1',
229 'content_address',
230 'model_name',
231 ]
232 ),
233 'joins' => [
234 'slot_roles' => [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ],
235 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
236 'content_models' => [ 'INNER JOIN', [ 'content_model = model_id' ] ],
237 ],
238 ]
239 ];
240 }
241
242 }