Merge "Paranoia, escape image alignment parameters before outputting."
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / McrWriteBothRevisionStoreDbTest.php
1 <?php
2 namespace MediaWiki\Tests\Storage;
3
4 use InvalidArgumentException;
5 use MediaWiki\Storage\RevisionRecord;
6 use MediaWiki\Storage\SlotRecord;
7 use Revision;
8 use WikitextContent;
9
10 /**
11 * Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
12 *
13 * @covers \MediaWiki\Storage\RevisionStore
14 *
15 * @group RevisionStore
16 * @group Storage
17 * @group Database
18 * @group medium
19 */
20 class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase {
21
22 use McrWriteBothSchemaOverride;
23
24 protected function revisionToRow( Revision $rev, $options = [ 'page', 'user', 'comment' ] ) {
25 $row = parent::revisionToRow( $rev, $options );
26
27 $row->rev_text_id = (string)$rev->getTextId();
28 $row->rev_content_format = (string)$rev->getContentFormat();
29 $row->rev_content_model = (string)$rev->getContentModel();
30
31 return $row;
32 }
33
34 protected function assertRevisionExistsInDatabase( RevisionRecord $rev ) {
35 // New schema is being written
36 $this->assertSelect(
37 'slots',
38 [ 'count(*)' ],
39 [ 'slot_revision_id' => $rev->getId() ],
40 [ [ '1' ] ]
41 );
42
43 $this->assertSelect(
44 'content',
45 [ 'count(*)' ],
46 [ 'content_address' => $rev->getSlot( 'main' )->getAddress() ],
47 [ [ '1' ] ]
48 );
49
50 // Legacy schema is still being written
51 $this->assertSelect(
52 [ 'revision', 'text' ],
53 [ 'count(*)' ],
54 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
55 [ [ 1 ] ],
56 [],
57 [ 'text' => [ 'INNER JOIN', [ 'rev_text_id = old_id' ] ] ]
58 );
59
60 parent::assertRevisionExistsInDatabase( $rev );
61 }
62
63 /**
64 * @param SlotRecord $a
65 * @param SlotRecord $b
66 */
67 protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
68 parent::assertSameSlotContent( $a, $b );
69
70 // Assert that the same content ID has been used
71 if ( $a->hasContentId() && $b->hasContentId() ) {
72 $this->assertSame( $a->getContentId(), $b->getContentId() );
73 }
74 }
75
76 public function provideGetArchiveQueryInfo() {
77 yield [
78 [
79 'tables' => [ 'archive' ],
80 'fields' => array_merge(
81 $this->getDefaultArchiveFields(),
82 [
83 'ar_comment_text' => 'ar_comment',
84 'ar_comment_data' => 'NULL',
85 'ar_comment_cid' => 'NULL',
86 'ar_user_text' => 'ar_user_text',
87 'ar_user' => 'ar_user',
88 'ar_actor' => 'NULL',
89 'ar_content_format',
90 'ar_content_model',
91 ]
92 ),
93 'joins' => [],
94 ]
95 ];
96 }
97
98 public function provideGetQueryInfo() {
99 yield [
100 [],
101 [
102 'tables' => [ 'revision' ],
103 'fields' => array_merge(
104 $this->getDefaultQueryFields(),
105 $this->getCommentQueryFields(),
106 $this->getActorQueryFields(),
107 $this->getContentHandlerQueryFields()
108 ),
109 'joins' => [],
110 ]
111 ];
112 yield [
113 [ 'page', 'user' ],
114 [
115 'tables' => [ 'revision', 'page', 'user' ],
116 'fields' => array_merge(
117 $this->getDefaultQueryFields(),
118 $this->getCommentQueryFields(),
119 $this->getActorQueryFields(),
120 $this->getContentHandlerQueryFields(),
121 [
122 'page_namespace',
123 'page_title',
124 'page_id',
125 'page_latest',
126 'page_is_redirect',
127 'page_len',
128 'user_name',
129 ]
130 ),
131 'joins' => [
132 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
133 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
134 ],
135 ]
136 ];
137 }
138
139 public function provideGetSlotsQueryInfo() {
140 $db = wfGetDB( DB_REPLICA );
141
142 yield [
143 [],
144 [
145 'tables' => [
146 'slots' => 'revision',
147 ],
148 'fields' => array_merge(
149 [
150 'slot_revision_id' => 'slots.rev_id',
151 'slot_content_id' => 'NULL',
152 'slot_origin' => 'slots.rev_id',
153 'role_name' => $db->addQuotes( 'main' ),
154 ]
155 ),
156 'joins' => [],
157 ]
158 ];
159 yield [
160 [ 'content' ],
161 [
162 'tables' => [
163 'slots' => 'revision',
164 ],
165 'fields' => array_merge(
166 [
167 'slot_revision_id' => 'slots.rev_id',
168 'slot_content_id' => 'NULL',
169 'slot_origin' => 'slots.rev_id',
170 'role_name' => $db->addQuotes( 'main' ),
171 'content_size' => 'slots.rev_len',
172 'content_sha1' => 'slots.rev_sha1',
173 'content_address' => $db->buildConcat( [
174 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
175 'model_name' => 'slots.rev_content_model',
176 ]
177 ),
178 'joins' => [],
179 ]
180 ];
181 }
182
183 public function provideInsertRevisionOn_failures() {
184 foreach ( parent::provideInsertRevisionOn_failures() as $case ) {
185 yield $case;
186 }
187
188 yield 'slot that is not main slot' => [
189 [
190 'content' => [
191 'main' => new WikitextContent( 'Chicken' ),
192 'lalala' => new WikitextContent( 'Duck' ),
193 ],
194 'comment' => $this->getRandomCommentStoreComment(),
195 'timestamp' => '20171117010101',
196 'user' => true,
197 ],
198 new InvalidArgumentException( 'Only the main slot is supported' )
199 ];
200 }
201
202 public function provideNewMutableRevisionFromArray() {
203 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
204 yield $case;
205 }
206
207 yield 'Basic array, with page & id' => [
208 [
209 'id' => 2,
210 'page' => 1,
211 'text_id' => 2,
212 'timestamp' => '20171017114835',
213 'user_text' => '111.0.1.2',
214 'user' => 0,
215 'minor_edit' => false,
216 'deleted' => 0,
217 'len' => 46,
218 'parent_id' => 1,
219 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
220 'comment' => 'Goat Comment!',
221 'content_format' => 'text/x-wiki',
222 'content_model' => 'wikitext',
223 ]
224 ];
225 }
226
227 }