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