Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryContinueTest.php
blobde9965b6e9dd3512abe7c0705002470ca7e344aa
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.
36 * @see MediaWikiTestCase::addDBData()
38 function addDBData() {
39 try {
40 $this->editPage( 'Template:AQCT-T1', '**Template:AQCT-T1**' );
41 $this->editPage( 'Template:AQCT-T2', '**Template:AQCT-T2**' );
42 $this->editPage( 'Template:AQCT-T3', '**Template:AQCT-T3**' );
43 $this->editPage( 'Template:AQCT-T4', '**Template:AQCT-T4**' );
44 $this->editPage( 'Template:AQCT-T5', '**Template:AQCT-T5**' );
46 $this->editPage( 'AQCT-1', '**AQCT-1** {{AQCT-T2}} {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
47 $this->editPage( 'AQCT-2', '[[AQCT-1]] **AQCT-2** {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
48 $this->editPage( 'AQCT-3', '[[AQCT-1]] [[AQCT-2]] **AQCT-3** {{AQCT-T4}} {{AQCT-T5}}' );
49 $this->editPage( 'AQCT-4', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] **AQCT-4** {{AQCT-T5}}' );
50 $this->editPage( 'AQCT-5', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] [[AQCT-4]] **AQCT-5**' );
51 } catch ( Exception $e ) {
52 $this->exceptionFromAddDBData = $e;
56 /**
57 * Test smart continue - list=allpages
58 * @medium
60 public function test1List() {
61 $this->mVerbose = false;
62 $mk = function ( $l ) {
63 return array(
64 'list' => 'allpages',
65 'apprefix' => 'AQCT-',
66 'aplimit' => "$l",
69 $data = $this->query( $mk( 99 ), 1, '1L', false ) +
70 array( 'batchcomplete' => '' );
72 // 1 list
73 $this->checkC( $data, $mk( 1 ), 5, '1L-1' );
74 $this->checkC( $data, $mk( 2 ), 3, '1L-2' );
75 $this->checkC( $data, $mk( 3 ), 2, '1L-3' );
76 $this->checkC( $data, $mk( 4 ), 2, '1L-4' );
77 $this->checkC( $data, $mk( 5 ), 1, '1L-5' );
80 /**
81 * Test smart continue - list=allpages|alltransclusions
82 * @medium
84 public function test2Lists() {
85 $this->mVerbose = false;
86 $mk = function ( $l1, $l2 ) {
87 return array(
88 'list' => 'allpages|alltransclusions',
89 'apprefix' => 'AQCT-',
90 'atprefix' => 'AQCT-',
91 'atunique' => '',
92 'aplimit' => "$l1",
93 'atlimit' => "$l2",
96 // 2 lists
97 $data = $this->query( $mk( 99, 99 ), 1, '2L', false ) +
98 array( 'batchcomplete' => '' );
99 $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
100 $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
101 $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
102 $this->checkC( $data, $mk( 4, 4 ), 2, '2L-44' );
103 $this->checkC( $data, $mk( 5, 5 ), 1, '2L-55' );
107 * Test smart continue - generator=allpages, prop=links
108 * @medium
110 public function testGen1Prop() {
111 $this->mVerbose = false;
112 $mk = function ( $g, $p ) {
113 return array(
114 'generator' => 'allpages',
115 'gapprefix' => 'AQCT-',
116 'gaplimit' => "$g",
117 'prop' => 'links',
118 'pllimit' => "$p",
121 // generator + 1 prop
122 $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) +
123 array( 'batchcomplete' => '' );
124 $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
125 $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
126 $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
127 $this->checkC( $data, $mk( 4, 4 ), 3, 'G1P-44' );
128 $this->checkC( $data, $mk( 5, 5 ), 2, 'G1P-55' );
132 * Test smart continue - generator=allpages, prop=links|templates
133 * @medium
135 public function testGen2Prop() {
136 $this->mVerbose = false;
137 $mk = function ( $g, $p1, $p2 ) {
138 return array(
139 'generator' => 'allpages',
140 'gapprefix' => 'AQCT-',
141 'gaplimit' => "$g",
142 'prop' => 'links|templates',
143 'pllimit' => "$p1",
144 'tllimit' => "$p2",
147 // generator + 2 props
148 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) +
149 array( 'batchcomplete' => '' );
150 $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
151 $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
152 $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
153 $this->checkC( $data, $mk( 4, 4, 4 ), 4, 'G2P-444' );
154 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G2P-555' );
155 $this->checkC( $data, $mk( 5, 1, 1 ), 10, 'G2P-511' );
156 $this->checkC( $data, $mk( 4, 2, 2 ), 7, 'G2P-422' );
157 $this->checkC( $data, $mk( 2, 3, 3 ), 7, 'G2P-233' );
158 $this->checkC( $data, $mk( 2, 4, 4 ), 5, 'G2P-244' );
159 $this->checkC( $data, $mk( 1, 5, 5 ), 5, 'G2P-155' );
163 * Test smart continue - generator=allpages, prop=links, list=alltransclusions
164 * @medium
166 public function testGen1Prop1List() {
167 $this->mVerbose = false;
168 $mk = function ( $g, $p, $l ) {
169 return array(
170 'generator' => 'allpages',
171 'gapprefix' => 'AQCT-',
172 'gaplimit' => "$g",
173 'prop' => 'links',
174 'pllimit' => "$p",
175 'list' => 'alltransclusions',
176 'atprefix' => 'AQCT-',
177 'atunique' => '',
178 'atlimit' => "$l",
181 // generator + 1 prop + 1 list
182 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) +
183 array( 'batchcomplete' => '' );
184 $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
185 $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
186 $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
187 $this->checkC( $data, $mk( 4, 4, 4 ), 3, 'G1P1L-444' );
188 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G1P1L-555' );
189 $this->checkC( $data, $mk( 5, 5, 1 ), 4, 'G1P1L-551' );
190 $this->checkC( $data, $mk( 5, 5, 2 ), 2, 'G1P1L-552' );
194 * Test smart continue - generator=allpages, prop=links|templates,
195 * list=alllinks|alltransclusions, meta=siteinfo
196 * @medium
198 public function testGen2Prop2List1Meta() {
199 $this->mVerbose = false;
200 $mk = function ( $g, $p1, $p2, $l1, $l2 ) {
201 return array(
202 'generator' => 'allpages',
203 'gapprefix' => 'AQCT-',
204 'gaplimit' => "$g",
205 'prop' => 'links|templates',
206 'pllimit' => "$p1",
207 'tllimit' => "$p2",
208 'list' => 'alllinks|alltransclusions',
209 'alprefix' => 'AQCT-',
210 'alunique' => '',
211 'allimit' => "$l1",
212 'atprefix' => 'AQCT-',
213 'atunique' => '',
214 'atlimit' => "$l2",
215 'meta' => 'siteinfo',
216 'siprop' => 'namespaces',
219 // generator + 1 prop + 1 list
220 $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) +
221 array( 'batchcomplete' => '' );
222 $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
223 $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
224 $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
225 $this->checkC( $data, $mk( 4, 4, 4, 4, 4 ), 4, 'G2P2L1M-44444' );
226 $this->checkC( $data, $mk( 5, 5, 5, 5, 5 ), 2, 'G2P2L1M-55555' );
227 $this->checkC( $data, $mk( 5, 5, 5, 1, 1 ), 4, 'G2P2L1M-55511' );
228 $this->checkC( $data, $mk( 5, 5, 5, 2, 2 ), 2, 'G2P2L1M-55522' );
229 $this->checkC( $data, $mk( 5, 1, 1, 5, 5 ), 10, 'G2P2L1M-51155' );
230 $this->checkC( $data, $mk( 5, 2, 2, 5, 5 ), 5, 'G2P2L1M-52255' );
234 * Test smart continue - generator=templates, prop=templates
235 * @medium
237 public function testSameGenAndProp() {
238 $this->mVerbose = false;
239 $mk = function ( $g, $gDir, $p, $pDir ) {
240 return array(
241 'titles' => 'AQCT-1',
242 'generator' => 'templates',
243 'gtllimit' => "$g",
244 'gtldir' => $gDir ? 'ascending' : 'descending',
245 'prop' => 'templates',
246 'tllimit' => "$p",
247 'tldir' => $pDir ? 'ascending' : 'descending',
250 // generator + 1 prop
251 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) +
252 array( 'batchcomplete' => '' );
254 $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
255 $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
256 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=P-3t3t' );
257 $this->checkC( $data, $mk( 1, true, 3, true ), 4, 'G=P-1t3t' );
258 $this->checkC( $data, $mk( 3, true, 1, true ), 2, 'G=P-3t1t' );
260 $this->checkC( $data, $mk( 1, true, 1, false ), 4, 'G=P-1t1f' );
261 $this->checkC( $data, $mk( 2, true, 2, false ), 2, 'G=P-2t2f' );
262 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=P-3t3f' );
263 $this->checkC( $data, $mk( 1, true, 3, false ), 4, 'G=P-1t3f' );
264 $this->checkC( $data, $mk( 3, true, 1, false ), 2, 'G=P-3t1f' );
266 $this->checkC( $data, $mk( 1, false, 1, true ), 4, 'G=P-1f1t' );
267 $this->checkC( $data, $mk( 2, false, 2, true ), 2, 'G=P-2f2t' );
268 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=P-3f3t' );
269 $this->checkC( $data, $mk( 1, false, 3, true ), 4, 'G=P-1f3t' );
270 $this->checkC( $data, $mk( 3, false, 1, true ), 2, 'G=P-3f1t' );
272 $this->checkC( $data, $mk( 1, false, 1, false ), 4, 'G=P-1f1f' );
273 $this->checkC( $data, $mk( 2, false, 2, false ), 2, 'G=P-2f2f' );
274 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=P-3f3f' );
275 $this->checkC( $data, $mk( 1, false, 3, false ), 4, 'G=P-1f3f' );
276 $this->checkC( $data, $mk( 3, false, 1, false ), 2, 'G=P-3f1f' );
280 * Test smart continue - generator=allpages, list=allpages
281 * @medium
283 public function testSameGenList() {
284 $this->mVerbose = false;
285 $mk = function ( $g, $gDir, $l, $pDir ) {
286 return array(
287 'generator' => 'allpages',
288 'gapprefix' => 'AQCT-',
289 'gaplimit' => "$g",
290 'gapdir' => $gDir ? 'ascending' : 'descending',
291 'list' => 'allpages',
292 'apprefix' => 'AQCT-',
293 'aplimit' => "$l",
294 'apdir' => $pDir ? 'ascending' : 'descending',
297 // generator + 1 list
298 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) +
299 array( 'batchcomplete' => '' );
301 $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
302 $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );
303 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=L-3t3t' );
304 $this->checkC( $data, $mk( 1, true, 3, true ), 5, 'G=L-1t3t' );
305 $this->checkC( $data, $mk( 3, true, 1, true ), 5, 'G=L-3t1t' );
306 $this->checkC( $data, $mk( 1, true, 1, false ), 5, 'G=L-1t1f' );
307 $this->checkC( $data, $mk( 2, true, 2, false ), 3, 'G=L-2t2f' );
308 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=L-3t3f' );
309 $this->checkC( $data, $mk( 1, true, 3, false ), 5, 'G=L-1t3f' );
310 $this->checkC( $data, $mk( 3, true, 1, false ), 5, 'G=L-3t1f' );
311 $this->checkC( $data, $mk( 1, false, 1, true ), 5, 'G=L-1f1t' );
312 $this->checkC( $data, $mk( 2, false, 2, true ), 3, 'G=L-2f2t' );
313 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=L-3f3t' );
314 $this->checkC( $data, $mk( 1, false, 3, true ), 5, 'G=L-1f3t' );
315 $this->checkC( $data, $mk( 3, false, 1, true ), 5, 'G=L-3f1t' );
316 $this->checkC( $data, $mk( 1, false, 1, false ), 5, 'G=L-1f1f' );
317 $this->checkC( $data, $mk( 2, false, 2, false ), 3, 'G=L-2f2f' );
318 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=L-3f3f' );
319 $this->checkC( $data, $mk( 1, false, 3, false ), 5, 'G=L-1f3f' );
320 $this->checkC( $data, $mk( 3, false, 1, false ), 5, 'G=L-3f1f' );