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