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