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