Move DatabaseDomain to Rdbms namespace
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryContinueTest.php
blobb31627b4d4fdac5ac91e12a6d8b247d2194fb47d
1 <?php
2 /**
3 * Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 /**
22 * These tests validate the new continue functionality of the api query module by
23 * doing multiple requests with varying parameters, merging the results, and checking
24 * that the result matches the full data received in one no-limits call.
26 * @group API
27 * @group Database
28 * @group medium
29 * @covers ApiQuery
31 class ApiQueryContinueTest extends ApiQueryContinueTestBase {
32 protected $exceptionFromAddDBData;
34 /**
35 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
37 *@see MediaWikiTestCase::addDBDataOnce()
39 function addDBDataOnce() {
40 try {
41 $this->editPage( 'Template:AQCT-T1', '**Template:AQCT-T1**' );
42 $this->editPage( 'Template:AQCT-T2', '**Template:AQCT-T2**' );
43 $this->editPage( 'Template:AQCT-T3', '**Template:AQCT-T3**' );
44 $this->editPage( 'Template:AQCT-T4', '**Template:AQCT-T4**' );
45 $this->editPage( 'Template:AQCT-T5', '**Template:AQCT-T5**' );
47 $this->editPage( 'AQCT-1', '**AQCT-1** {{AQCT-T2}} {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
48 $this->editPage( 'AQCT-2', '[[AQCT-1]] **AQCT-2** {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
49 $this->editPage( 'AQCT-3', '[[AQCT-1]] [[AQCT-2]] **AQCT-3** {{AQCT-T4}} {{AQCT-T5}}' );
50 $this->editPage( 'AQCT-4', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] **AQCT-4** {{AQCT-T5}}' );
51 $this->editPage( 'AQCT-5', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] [[AQCT-4]] **AQCT-5**' );
52 } catch ( Exception $e ) {
53 $this->exceptionFromAddDBData = $e;
57 /**
58 * Test smart continue - list=allpages
59 * @medium
61 public function test1List() {
62 $this->mVerbose = false;
63 $mk = function ( $l ) {
64 return [
65 'list' => 'allpages',
66 'apprefix' => 'AQCT-',
67 'aplimit' => "$l",
70 $data = $this->query( $mk( 99 ), 1, '1L', false ) +
71 [ 'batchcomplete' => true ];
73 // 1 list
74 $this->checkC( $data, $mk( 1 ), 5, '1L-1' );
75 $this->checkC( $data, $mk( 2 ), 3, '1L-2' );
76 $this->checkC( $data, $mk( 3 ), 2, '1L-3' );
77 $this->checkC( $data, $mk( 4 ), 2, '1L-4' );
78 $this->checkC( $data, $mk( 5 ), 1, '1L-5' );
81 /**
82 * Test smart continue - list=allpages|alltransclusions
83 * @medium
85 public function test2Lists() {
86 $this->mVerbose = false;
87 $mk = function ( $l1, $l2 ) {
88 return [
89 'list' => 'allpages|alltransclusions',
90 'apprefix' => 'AQCT-',
91 'atprefix' => 'AQCT-',
92 'atunique' => '',
93 'aplimit' => "$l1",
94 'atlimit' => "$l2",
97 // 2 lists
98 $data = $this->query( $mk( 99, 99 ), 1, '2L', false ) +
99 [ 'batchcomplete' => true ];
100 $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
101 $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
102 $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
103 $this->checkC( $data, $mk( 4, 4 ), 2, '2L-44' );
104 $this->checkC( $data, $mk( 5, 5 ), 1, '2L-55' );
108 * Test smart continue - generator=allpages, prop=links
109 * @medium
111 public function testGen1Prop() {
112 $this->mVerbose = false;
113 $mk = function ( $g, $p ) {
114 return [
115 'generator' => 'allpages',
116 'gapprefix' => 'AQCT-',
117 'gaplimit' => "$g",
118 'prop' => 'links',
119 'pllimit' => "$p",
122 // generator + 1 prop
123 $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) +
124 [ 'batchcomplete' => true ];
125 $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
126 $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
127 $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
128 $this->checkC( $data, $mk( 4, 4 ), 3, 'G1P-44' );
129 $this->checkC( $data, $mk( 5, 5 ), 2, 'G1P-55' );
133 * Test smart continue - generator=allpages, prop=links|templates
134 * @medium
136 public function testGen2Prop() {
137 $this->mVerbose = false;
138 $mk = function ( $g, $p1, $p2 ) {
139 return [
140 'generator' => 'allpages',
141 'gapprefix' => 'AQCT-',
142 'gaplimit' => "$g",
143 'prop' => 'links|templates',
144 'pllimit' => "$p1",
145 'tllimit' => "$p2",
148 // generator + 2 props
149 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) +
150 [ 'batchcomplete' => true ];
151 $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
152 $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
153 $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
154 $this->checkC( $data, $mk( 4, 4, 4 ), 4, 'G2P-444' );
155 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G2P-555' );
156 $this->checkC( $data, $mk( 5, 1, 1 ), 10, 'G2P-511' );
157 $this->checkC( $data, $mk( 4, 2, 2 ), 7, 'G2P-422' );
158 $this->checkC( $data, $mk( 2, 3, 3 ), 7, 'G2P-233' );
159 $this->checkC( $data, $mk( 2, 4, 4 ), 5, 'G2P-244' );
160 $this->checkC( $data, $mk( 1, 5, 5 ), 5, 'G2P-155' );
164 * Test smart continue - generator=allpages, prop=links, list=alltransclusions
165 * @medium
167 public function testGen1Prop1List() {
168 $this->mVerbose = false;
169 $mk = function ( $g, $p, $l ) {
170 return [
171 'generator' => 'allpages',
172 'gapprefix' => 'AQCT-',
173 'gaplimit' => "$g",
174 'prop' => 'links',
175 'pllimit' => "$p",
176 'list' => 'alltransclusions',
177 'atprefix' => 'AQCT-',
178 'atunique' => '',
179 'atlimit' => "$l",
182 // generator + 1 prop + 1 list
183 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) +
184 [ 'batchcomplete' => true ];
185 $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
186 $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
187 $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
188 $this->checkC( $data, $mk( 4, 4, 4 ), 3, 'G1P1L-444' );
189 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G1P1L-555' );
190 $this->checkC( $data, $mk( 5, 5, 1 ), 4, 'G1P1L-551' );
191 $this->checkC( $data, $mk( 5, 5, 2 ), 2, 'G1P1L-552' );
195 * Test smart continue - generator=allpages, prop=links|templates,
196 * list=alllinks|alltransclusions, meta=siteinfo
197 * @medium
199 public function testGen2Prop2List1Meta() {
200 $this->mVerbose = false;
201 $mk = function ( $g, $p1, $p2, $l1, $l2 ) {
202 return [
203 'generator' => 'allpages',
204 'gapprefix' => 'AQCT-',
205 'gaplimit' => "$g",
206 'prop' => 'links|templates',
207 'pllimit' => "$p1",
208 'tllimit' => "$p2",
209 'list' => 'alllinks|alltransclusions',
210 'alprefix' => 'AQCT-',
211 'alunique' => '',
212 'allimit' => "$l1",
213 'atprefix' => 'AQCT-',
214 'atunique' => '',
215 'atlimit' => "$l2",
216 'meta' => 'siteinfo',
217 'siprop' => 'namespaces',
220 // generator + 1 prop + 1 list
221 $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) +
222 [ 'batchcomplete' => true ];
223 $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
224 $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
225 $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
226 $this->checkC( $data, $mk( 4, 4, 4, 4, 4 ), 4, 'G2P2L1M-44444' );
227 $this->checkC( $data, $mk( 5, 5, 5, 5, 5 ), 2, 'G2P2L1M-55555' );
228 $this->checkC( $data, $mk( 5, 5, 5, 1, 1 ), 4, 'G2P2L1M-55511' );
229 $this->checkC( $data, $mk( 5, 5, 5, 2, 2 ), 2, 'G2P2L1M-55522' );
230 $this->checkC( $data, $mk( 5, 1, 1, 5, 5 ), 10, 'G2P2L1M-51155' );
231 $this->checkC( $data, $mk( 5, 2, 2, 5, 5 ), 5, 'G2P2L1M-52255' );
235 * Test smart continue - generator=templates, prop=templates
236 * @medium
238 public function testSameGenAndProp() {
239 $this->mVerbose = false;
240 $mk = function ( $g, $gDir, $p, $pDir ) {
241 return [
242 'titles' => 'AQCT-1',
243 'generator' => 'templates',
244 'gtllimit' => "$g",
245 'gtldir' => $gDir ? 'ascending' : 'descending',
246 'prop' => 'templates',
247 'tllimit' => "$p",
248 'tldir' => $pDir ? 'ascending' : 'descending',
251 // generator + 1 prop
252 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) +
253 [ 'batchcomplete' => true ];
255 $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
256 $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
257 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=P-3t3t' );
258 $this->checkC( $data, $mk( 1, true, 3, true ), 4, 'G=P-1t3t' );
259 $this->checkC( $data, $mk( 3, true, 1, true ), 2, 'G=P-3t1t' );
261 $this->checkC( $data, $mk( 1, true, 1, false ), 4, 'G=P-1t1f' );
262 $this->checkC( $data, $mk( 2, true, 2, false ), 2, 'G=P-2t2f' );
263 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=P-3t3f' );
264 $this->checkC( $data, $mk( 1, true, 3, false ), 4, 'G=P-1t3f' );
265 $this->checkC( $data, $mk( 3, true, 1, false ), 2, 'G=P-3t1f' );
267 $this->checkC( $data, $mk( 1, false, 1, true ), 4, 'G=P-1f1t' );
268 $this->checkC( $data, $mk( 2, false, 2, true ), 2, 'G=P-2f2t' );
269 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=P-3f3t' );
270 $this->checkC( $data, $mk( 1, false, 3, true ), 4, 'G=P-1f3t' );
271 $this->checkC( $data, $mk( 3, false, 1, true ), 2, 'G=P-3f1t' );
273 $this->checkC( $data, $mk( 1, false, 1, false ), 4, 'G=P-1f1f' );
274 $this->checkC( $data, $mk( 2, false, 2, false ), 2, 'G=P-2f2f' );
275 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=P-3f3f' );
276 $this->checkC( $data, $mk( 1, false, 3, false ), 4, 'G=P-1f3f' );
277 $this->checkC( $data, $mk( 3, false, 1, false ), 2, 'G=P-3f1f' );
281 * Test smart continue - generator=allpages, list=allpages
282 * @medium
284 public function testSameGenList() {
285 $this->mVerbose = false;
286 $mk = function ( $g, $gDir, $l, $pDir ) {
287 return [
288 'generator' => 'allpages',
289 'gapprefix' => 'AQCT-',
290 'gaplimit' => "$g",
291 'gapdir' => $gDir ? 'ascending' : 'descending',
292 'list' => 'allpages',
293 'apprefix' => 'AQCT-',
294 'aplimit' => "$l",
295 'apdir' => $pDir ? 'ascending' : 'descending',
298 // generator + 1 list
299 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) +
300 [ 'batchcomplete' => true ];
302 $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
303 $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );
304 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=L-3t3t' );
305 $this->checkC( $data, $mk( 1, true, 3, true ), 5, 'G=L-1t3t' );
306 $this->checkC( $data, $mk( 3, true, 1, true ), 5, 'G=L-3t1t' );
307 $this->checkC( $data, $mk( 1, true, 1, false ), 5, 'G=L-1t1f' );
308 $this->checkC( $data, $mk( 2, true, 2, false ), 3, 'G=L-2t2f' );
309 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=L-3t3f' );
310 $this->checkC( $data, $mk( 1, true, 3, false ), 5, 'G=L-1t3f' );
311 $this->checkC( $data, $mk( 3, true, 1, false ), 5, 'G=L-3t1f' );
312 $this->checkC( $data, $mk( 1, false, 1, true ), 5, 'G=L-1f1t' );
313 $this->checkC( $data, $mk( 2, false, 2, true ), 3, 'G=L-2f2t' );
314 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=L-3f3t' );
315 $this->checkC( $data, $mk( 1, false, 3, true ), 5, 'G=L-1f3t' );
316 $this->checkC( $data, $mk( 3, false, 1, true ), 5, 'G=L-3f1t' );
317 $this->checkC( $data, $mk( 1, false, 1, false ), 5, 'G=L-1f1f' );
318 $this->checkC( $data, $mk( 2, false, 2, false ), 3, 'G=L-2f2f' );
319 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=L-3f3f' );
320 $this->checkC( $data, $mk( 1, false, 3, false ), 5, 'G=L-1f3f' );
321 $this->checkC( $data, $mk( 3, false, 1, false ), 5, 'G=L-3f1f' );