4 * Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
22 namespace MediaWiki\Tests\Api\Query
;
27 * These tests validate the new continue functionality of the api query module by
28 * doing multiple requests with varying parameters, merging the results, and checking
29 * that the result matches the full data received in one no-limits call.
34 * @covers \MediaWiki\Api\ApiQuery
36 class ApiQueryContinueTest
extends ApiQueryContinueTestBase
{
37 /** @var Exception|null */
38 protected $exceptionFromAddDBData;
41 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
43 * @see MediaWikiIntegrationTestCase::addDBDataOnce()
45 public function addDBDataOnce() {
47 $this->editPage( 'Template:AQCT-T1', '**Template:AQCT-T1**' );
48 $this->editPage( 'Template:AQCT-T2', '**Template:AQCT-T2**' );
49 $this->editPage( 'Template:AQCT-T3', '**Template:AQCT-T3**' );
50 $this->editPage( 'Template:AQCT-T4', '**Template:AQCT-T4**' );
51 $this->editPage( 'Template:AQCT-T5', '**Template:AQCT-T5**' );
53 $this->editPage( 'AQCT-1', '**AQCT-1** {{AQCT-T2}} {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
54 $this->editPage( 'AQCT-2', '[[AQCT-1]] **AQCT-2** {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
55 $this->editPage( 'AQCT-3', '[[AQCT-1]] [[AQCT-2]] **AQCT-3** {{AQCT-T4}} {{AQCT-T5}}' );
56 $this->editPage( 'AQCT-4', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] **AQCT-4** {{AQCT-T5}}' );
57 $this->editPage( 'AQCT-5', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] [[AQCT-4]] **AQCT-5**' );
58 } catch ( Exception
$e ) {
59 $this->exceptionFromAddDBData
= $e;
64 * Test smart continue - list=allpages
67 public function test1List() {
68 $this->mVerbose
= false;
69 $mk = static function ( $l ) {
72 'apprefix' => 'AQCT-',
76 $data = $this->query( $mk( 99 ), 1, '1L', false ) +
77 [ 'batchcomplete' => true ];
80 $this->checkC( $data, $mk( 1 ), 5, '1L-1' );
81 $this->checkC( $data, $mk( 2 ), 3, '1L-2' );
82 $this->checkC( $data, $mk( 3 ), 2, '1L-3' );
83 $this->checkC( $data, $mk( 4 ), 2, '1L-4' );
84 $this->checkC( $data, $mk( 5 ), 1, '1L-5' );
88 * Test smart continue - list=allpages|alltransclusions
91 public function test2Lists() {
92 $this->mVerbose
= false;
93 $mk = static function ( $l1, $l2 ) {
95 'list' => 'allpages|alltransclusions',
96 'apprefix' => 'AQCT-',
97 'atprefix' => 'AQCT-',
104 $data = $this->query( $mk( 99, 99 ), 1, '2L', false ) +
105 [ 'batchcomplete' => true ];
106 $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
107 $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
108 $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
109 $this->checkC( $data, $mk( 4, 4 ), 2, '2L-44' );
110 $this->checkC( $data, $mk( 5, 5 ), 1, '2L-55' );
114 * Test smart continue - generator=allpages, prop=links
117 public function testGen1Prop() {
118 $this->mVerbose
= false;
119 $mk = static function ( $g, $p ) {
121 'generator' => 'allpages',
122 'gapprefix' => 'AQCT-',
128 // generator + 1 prop
129 $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) +
130 [ 'batchcomplete' => true ];
131 $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
132 $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
133 $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
134 $this->checkC( $data, $mk( 4, 4 ), 3, 'G1P-44' );
135 $this->checkC( $data, $mk( 5, 5 ), 2, 'G1P-55' );
139 * Test smart continue - generator=allpages, prop=links|templates
142 public function testGen2Prop() {
143 $this->mVerbose
= false;
144 $mk = static function ( $g, $p1, $p2 ) {
146 'generator' => 'allpages',
147 'gapprefix' => 'AQCT-',
149 'prop' => 'links|templates',
154 // generator + 2 props
155 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) +
156 [ 'batchcomplete' => true ];
157 $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
158 $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
159 $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
160 $this->checkC( $data, $mk( 4, 4, 4 ), 4, 'G2P-444' );
161 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G2P-555' );
162 $this->checkC( $data, $mk( 5, 1, 1 ), 10, 'G2P-511' );
163 $this->checkC( $data, $mk( 4, 2, 2 ), 7, 'G2P-422' );
164 $this->checkC( $data, $mk( 2, 3, 3 ), 7, 'G2P-233' );
165 $this->checkC( $data, $mk( 2, 4, 4 ), 5, 'G2P-244' );
166 $this->checkC( $data, $mk( 1, 5, 5 ), 5, 'G2P-155' );
170 * Test smart continue - generator=allpages, prop=links, list=alltransclusions
173 public function testGen1Prop1List() {
174 $this->mVerbose
= false;
175 $mk = static function ( $g, $p, $l ) {
177 'generator' => 'allpages',
178 'gapprefix' => 'AQCT-',
182 'list' => 'alltransclusions',
183 'atprefix' => 'AQCT-',
188 // generator + 1 prop + 1 list
189 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) +
190 [ 'batchcomplete' => true ];
191 $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
192 $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
193 $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
194 $this->checkC( $data, $mk( 4, 4, 4 ), 3, 'G1P1L-444' );
195 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G1P1L-555' );
196 $this->checkC( $data, $mk( 5, 5, 1 ), 4, 'G1P1L-551' );
197 $this->checkC( $data, $mk( 5, 5, 2 ), 2, 'G1P1L-552' );
201 * Test smart continue - generator=allpages, prop=links|templates,
202 * list=alllinks|alltransclusions, meta=siteinfo
205 public function testGen2Prop2List1Meta() {
206 $this->mVerbose
= false;
207 $mk = static function ( $g, $p1, $p2, $l1, $l2 ) {
209 'generator' => 'allpages',
210 'gapprefix' => 'AQCT-',
212 'prop' => 'links|templates',
215 'list' => 'alllinks|alltransclusions',
216 'alprefix' => 'AQCT-',
219 'atprefix' => 'AQCT-',
222 'meta' => 'siteinfo',
223 'siprop' => 'namespaces',
226 // generator + 1 prop + 1 list
227 $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) +
228 [ 'batchcomplete' => true ];
229 $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
230 $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
231 $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
232 $this->checkC( $data, $mk( 4, 4, 4, 4, 4 ), 4, 'G2P2L1M-44444' );
233 $this->checkC( $data, $mk( 5, 5, 5, 5, 5 ), 2, 'G2P2L1M-55555' );
234 $this->checkC( $data, $mk( 5, 5, 5, 1, 1 ), 4, 'G2P2L1M-55511' );
235 $this->checkC( $data, $mk( 5, 5, 5, 2, 2 ), 2, 'G2P2L1M-55522' );
236 $this->checkC( $data, $mk( 5, 1, 1, 5, 5 ), 10, 'G2P2L1M-51155' );
237 $this->checkC( $data, $mk( 5, 2, 2, 5, 5 ), 5, 'G2P2L1M-52255' );
241 * Test smart continue - generator=templates, prop=templates
244 public function testSameGenAndProp() {
245 $this->mVerbose
= false;
246 $mk = static function ( $g, $gDir, $p, $pDir ) {
248 'titles' => 'AQCT-1',
249 'generator' => 'templates',
251 'gtldir' => $gDir ?
'ascending' : 'descending',
252 'prop' => 'templates',
254 'tldir' => $pDir ?
'ascending' : 'descending',
257 // generator + 1 prop
258 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) +
259 [ 'batchcomplete' => true ];
261 $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
262 $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
263 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=P-3t3t' );
264 $this->checkC( $data, $mk( 1, true, 3, true ), 4, 'G=P-1t3t' );
265 $this->checkC( $data, $mk( 3, true, 1, true ), 2, 'G=P-3t1t' );
267 $this->checkC( $data, $mk( 1, true, 1, false ), 4, 'G=P-1t1f' );
268 $this->checkC( $data, $mk( 2, true, 2, false ), 2, 'G=P-2t2f' );
269 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=P-3t3f' );
270 $this->checkC( $data, $mk( 1, true, 3, false ), 4, 'G=P-1t3f' );
271 $this->checkC( $data, $mk( 3, true, 1, false ), 2, 'G=P-3t1f' );
273 $this->checkC( $data, $mk( 1, false, 1, true ), 4, 'G=P-1f1t' );
274 $this->checkC( $data, $mk( 2, false, 2, true ), 2, 'G=P-2f2t' );
275 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=P-3f3t' );
276 $this->checkC( $data, $mk( 1, false, 3, true ), 4, 'G=P-1f3t' );
277 $this->checkC( $data, $mk( 3, false, 1, true ), 2, 'G=P-3f1t' );
279 $this->checkC( $data, $mk( 1, false, 1, false ), 4, 'G=P-1f1f' );
280 $this->checkC( $data, $mk( 2, false, 2, false ), 2, 'G=P-2f2f' );
281 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=P-3f3f' );
282 $this->checkC( $data, $mk( 1, false, 3, false ), 4, 'G=P-1f3f' );
283 $this->checkC( $data, $mk( 3, false, 1, false ), 2, 'G=P-3f1f' );
287 * Test smart continue - generator=allpages, list=allpages
290 public function testSameGenList() {
291 $this->mVerbose
= false;
292 $mk = static function ( $g, $gDir, $l, $pDir ) {
294 'generator' => 'allpages',
295 'gapprefix' => 'AQCT-',
297 'gapdir' => $gDir ?
'ascending' : 'descending',
298 'list' => 'allpages',
299 'apprefix' => 'AQCT-',
301 'apdir' => $pDir ?
'ascending' : 'descending',
304 // generator + 1 list
305 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) +
306 [ 'batchcomplete' => true ];
308 $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
309 $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );
310 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=L-3t3t' );
311 $this->checkC( $data, $mk( 1, true, 3, true ), 5, 'G=L-1t3t' );
312 $this->checkC( $data, $mk( 3, true, 1, true ), 5, 'G=L-3t1t' );
313 $this->checkC( $data, $mk( 1, true, 1, false ), 5, 'G=L-1t1f' );
314 $this->checkC( $data, $mk( 2, true, 2, false ), 3, 'G=L-2t2f' );
315 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=L-3t3f' );
316 $this->checkC( $data, $mk( 1, true, 3, false ), 5, 'G=L-1t3f' );
317 $this->checkC( $data, $mk( 3, true, 1, false ), 5, 'G=L-3t1f' );
318 $this->checkC( $data, $mk( 1, false, 1, true ), 5, 'G=L-1f1t' );
319 $this->checkC( $data, $mk( 2, false, 2, true ), 3, 'G=L-2f2t' );
320 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=L-3f3t' );
321 $this->checkC( $data, $mk( 1, false, 3, true ), 5, 'G=L-1f3t' );
322 $this->checkC( $data, $mk( 3, false, 1, true ), 5, 'G=L-3f1t' );
323 $this->checkC( $data, $mk( 1, false, 1, false ), 5, 'G=L-1f1f' );
324 $this->checkC( $data, $mk( 2, false, 2, false ), 3, 'G=L-2f2f' );
325 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=L-3f3f' );
326 $this->checkC( $data, $mk( 1, false, 3, false ), 5, 'G=L-1f3f' );
327 $this->checkC( $data, $mk( 3, false, 1, false ), 5, 'G=L-3f1f' );