resourceloader: Configure eslint to disallow $ and require inside startup
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / McrReadNewRevisionStoreDbTest.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 intermediate MCR DB schema for use during schema migration.
14 *
15 * @covers \MediaWiki\Storage\RevisionStore
16 *
17 * @group RevisionStore
18 * @group Storage
19 * @group Database
20 * @group medium
21 */
22 class McrReadNewRevisionStoreDbTest extends RevisionStoreDbTestBase {
23
24 use McrReadNewSchemaOverride;
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 // Legacy schema is still being written
52 $this->assertSelect(
53 [ 'revision', 'text' ],
54 [ 'count(*)' ],
55 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
56 [ [ 1 ] ],
57 [],
58 [ 'text' => [ 'INNER JOIN', [ 'rev_text_id = old_id' ] ] ]
59 );
60
61 parent::assertRevisionExistsInDatabase( $rev );
62 }
63
64 /**
65 * @param SlotRecord $a
66 * @param SlotRecord $b
67 */
68 protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
69 parent::assertSameSlotContent( $a, $b );
70
71 // Assert that the same content ID has been used
72 $this->assertSame( $a->getContentId(), $b->getContentId() );
73 }
74
75 public function provideInsertRevisionOn_successes() {
76 foreach ( parent::provideInsertRevisionOn_successes() as $case ) {
77 yield $case;
78 }
79
80 yield 'Multi-slot revision insertion' => [
81 [
82 'content' => [
83 'main' => new WikitextContent( 'Chicken' ),
84 'aux' => new TextContent( 'Egg' ),
85 ],
86 'page' => true,
87 'comment' => $this->getRandomCommentStoreComment(),
88 'timestamp' => '20171117010101',
89 'user' => true,
90 ],
91 ];
92 }
93
94 public function provideNewNullRevision() {
95 foreach ( parent::provideNewNullRevision() as $case ) {
96 yield $case;
97 }
98
99 yield [
100 Title::newFromText( 'UTPage_notAutoCreated' ),
101 [
102 'content' => [
103 'main' => new WikitextContent( 'Chicken' ),
104 'aux' => new WikitextContent( 'Omelet' ),
105 ],
106 ],
107 CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment multi' ),
108 ];
109 }
110
111 public function testGetQueryInfo_NoSlotDataJoin() {
112 $store = MediaWikiServices::getInstance()->getRevisionStore();
113 $queryInfo = $store->getQueryInfo();
114
115 // with the new schema enabled, query info should not join the main slot info
116 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['tables'] ) );
117 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['joins'] ) );
118 }
119
120 public function provideGetArchiveQueryInfo() {
121 yield [
122 [
123 'tables' => [
124 'archive',
125 ],
126 'fields' => array_merge(
127 $this->getDefaultArchiveFields( false ),
128 [
129 'ar_comment_text' => 'ar_comment',
130 'ar_comment_data' => 'NULL',
131 'ar_comment_cid' => 'NULL',
132 'ar_user_text' => 'ar_user_text',
133 'ar_user' => 'ar_user',
134 'ar_actor' => 'NULL',
135 ]
136 ),
137 'joins' => [
138 ],
139 ]
140 ];
141 }
142
143 public function provideGetQueryInfo() {
144 // TODO: more option variations
145 yield [
146 [ 'page', 'user' ],
147 [
148 'tables' => [
149 'revision',
150 'page',
151 'user',
152 ],
153 'fields' => array_merge(
154 $this->getDefaultQueryFields( false ),
155 $this->getCommentQueryFields(),
156 $this->getActorQueryFields(),
157 [
158 'page_namespace',
159 'page_title',
160 'page_id',
161 'page_latest',
162 'page_is_redirect',
163 'page_len',
164 'user_name',
165 ]
166 ),
167 'joins' => [
168 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
169 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
170 ],
171 ]
172 ];
173 }
174
175 public function provideGetSlotsQueryInfo() {
176 yield 'no options' => [
177 [],
178 [
179 'tables' => [
180 'slots'
181 ],
182 'fields' => [
183 'slot_revision_id',
184 'slot_content_id',
185 'slot_origin',
186 'slot_role_id',
187 ],
188 'joins' => [],
189 ]
190 ];
191 yield 'role option' => [
192 [ 'role' ],
193 [
194 'tables' => [
195 'slots',
196 'slot_roles',
197 ],
198 'fields' => [
199 'slot_revision_id',
200 'slot_content_id',
201 'slot_origin',
202 'slot_role_id',
203 'role_name',
204 ],
205 'joins' => [
206 'slot_roles' => [ 'LEFT JOIN', [ 'slot_role_id = role_id' ] ],
207 ],
208 ]
209 ];
210 yield 'content option' => [
211 [ 'content' ],
212 [
213 'tables' => [
214 'slots',
215 'content',
216 ],
217 'fields' => [
218 'slot_revision_id',
219 'slot_content_id',
220 'slot_origin',
221 'slot_role_id',
222 'content_size',
223 'content_sha1',
224 'content_address',
225 'content_model',
226 ],
227 'joins' => [
228 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
229 ],
230 ]
231 ];
232 yield 'content and model options' => [
233 [ 'content', 'model' ],
234 [
235 'tables' => [
236 'slots',
237 'content',
238 'content_models',
239 ],
240 'fields' => [
241 'slot_revision_id',
242 'slot_content_id',
243 'slot_origin',
244 'slot_role_id',
245 'content_size',
246 'content_sha1',
247 'content_address',
248 'content_model',
249 'model_name',
250 ],
251 'joins' => [
252 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
253 'content_models' => [ 'LEFT JOIN', [ 'content_model = model_id' ] ],
254 ],
255 ]
256 ];
257 }
258
259 public function provideNewMutableRevisionFromArray() {
260 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
261 yield $case;
262 }
263
264 yield 'Basic array, multiple roles' => [
265 [
266 'id' => 2,
267 'page' => 1,
268 'timestamp' => '20171017114835',
269 'user_text' => '111.0.1.2',
270 'user' => 0,
271 'minor_edit' => false,
272 'deleted' => 0,
273 'len' => 29,
274 'parent_id' => 1,
275 'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
276 'comment' => 'Goat Comment!',
277 'content' => [
278 'main' => new WikitextContent( 'Söme Cöntent' ),
279 'aux' => new TextContent( 'Öther Cöntent' ),
280 ]
281 ]
282 ];
283 }
284
285 }