Merge "Revert "Introduce RevisionStoreFactory & Tests""
[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 $this->assertSelect(
36 'slots',
37 [ 'count(*)' ],
38 [ 'slot_revision_id' => $rev->getId() ],
39 [ [ '1' ] ]
40 );
41
42 $this->assertSelect(
43 'content',
44 [ 'count(*)' ],
45 [ 'content_address' => $rev->getSlot( 'main' )->getAddress() ],
46 [ [ '1' ] ]
47 );
48
49 parent::assertRevisionExistsInDatabase( $rev );
50 }
51
52 /**
53 * @param SlotRecord $a
54 * @param SlotRecord $b
55 */
56 protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
57 parent::assertSameSlotContent( $a, $b );
58
59 // Assert that the same content ID has been used
60 if ( $a->hasContentId() && $b->hasContentId() ) {
61 $this->assertSame( $a->getContentId(), $b->getContentId() );
62 }
63 }
64
65 public function provideGetArchiveQueryInfo() {
66 yield [
67 [
68 'tables' => [ 'archive' ],
69 'fields' => array_merge(
70 $this->getDefaultArchiveFields(),
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 'ar_content_format',
79 'ar_content_model',
80 ]
81 ),
82 'joins' => [],
83 ]
84 ];
85 }
86
87 public function provideGetQueryInfo() {
88 yield [
89 [],
90 [
91 'tables' => [ 'revision' ],
92 'fields' => array_merge(
93 $this->getDefaultQueryFields(),
94 $this->getCommentQueryFields(),
95 $this->getActorQueryFields(),
96 $this->getContentHandlerQueryFields()
97 ),
98 'joins' => [],
99 ]
100 ];
101 yield [
102 [ 'page', 'user' ],
103 [
104 'tables' => [ 'revision', 'page', 'user' ],
105 'fields' => array_merge(
106 $this->getDefaultQueryFields(),
107 $this->getCommentQueryFields(),
108 $this->getActorQueryFields(),
109 $this->getContentHandlerQueryFields(),
110 [
111 'page_namespace',
112 'page_title',
113 'page_id',
114 'page_latest',
115 'page_is_redirect',
116 'page_len',
117 'user_name',
118 ]
119 ),
120 'joins' => [
121 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
122 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
123 ],
124 ]
125 ];
126 }
127
128 public function provideGetSlotsQueryInfo() {
129 $db = wfGetDB( DB_REPLICA );
130
131 yield [
132 [],
133 [
134 'tables' => [
135 'slots' => 'revision',
136 ],
137 'fields' => array_merge(
138 [
139 'slot_revision_id' => 'slots.rev_id',
140 'slot_content_id' => 'NULL',
141 'slot_origin' => 'slots.rev_id',
142 'role_name' => $db->addQuotes( 'main' ),
143 ]
144 ),
145 'joins' => [],
146 ]
147 ];
148 yield [
149 [ 'content' ],
150 [
151 'tables' => [
152 'slots' => 'revision',
153 ],
154 'fields' => array_merge(
155 [
156 'slot_revision_id' => 'slots.rev_id',
157 'slot_content_id' => 'NULL',
158 'slot_origin' => 'slots.rev_id',
159 'role_name' => $db->addQuotes( 'main' ),
160 'content_size' => 'slots.rev_len',
161 'content_sha1' => 'slots.rev_sha1',
162 'content_address' => $db->buildConcat( [
163 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
164 'model_name' => 'slots.rev_content_model',
165 ]
166 ),
167 'joins' => [],
168 ]
169 ];
170 }
171
172 public function provideInsertRevisionOn_failures() {
173 foreach ( parent::provideInsertRevisionOn_failures() as $case ) {
174 yield $case;
175 }
176
177 yield 'slot that is not main slot' => [
178 [
179 'content' => [
180 'main' => new WikitextContent( 'Chicken' ),
181 'lalala' => new WikitextContent( 'Duck' ),
182 ],
183 'comment' => $this->getRandomCommentStoreComment(),
184 'timestamp' => '20171117010101',
185 'user' => true,
186 ],
187 new InvalidArgumentException( 'Only the main slot is supported' )
188 ];
189 }
190
191 public function provideNewMutableRevisionFromArray() {
192 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
193 yield $case;
194 }
195
196 yield 'Basic array, with page & id' => [
197 [
198 'id' => 2,
199 'page' => 1,
200 'text_id' => 2,
201 'timestamp' => '20171017114835',
202 'user_text' => '111.0.1.2',
203 'user' => 0,
204 'minor_edit' => false,
205 'deleted' => 0,
206 'len' => 46,
207 'parent_id' => 1,
208 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
209 'comment' => 'Goat Comment!',
210 'content_format' => 'text/x-wiki',
211 'content_model' => 'wikitext',
212 ]
213 ];
214 }
215
216 }