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