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 require_once 'ApiQueryContinueTestBase.php';
24 * These tests validate the new continue functionality of the api query module by
25 * doing multiple requests with varying parameters, merging the results, and checking
26 * that the result matches the full data received in one no-limits call.
33 class ApiQueryContinueTest
extends ApiQueryContinueTestBase
{
34 protected $exceptionFromAddDBData;
37 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
38 * @see MediaWikiTestCase::addDBData()
40 function addDBData() {
42 $this->editPage( 'Template:AQCT-T1', '**Template:AQCT-T1**' );
43 $this->editPage( 'Template:AQCT-T2', '**Template:AQCT-T2**' );
44 $this->editPage( 'Template:AQCT-T3', '**Template:AQCT-T3**' );
45 $this->editPage( 'Template:AQCT-T4', '**Template:AQCT-T4**' );
46 $this->editPage( 'Template:AQCT-T5', '**Template:AQCT-T5**' );
48 $this->editPage( 'AQCT-1', '**AQCT-1** {{AQCT-T2}} {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
49 $this->editPage( 'AQCT-2', '[[AQCT-1]] **AQCT-2** {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
50 $this->editPage( 'AQCT-3', '[[AQCT-1]] [[AQCT-2]] **AQCT-3** {{AQCT-T4}} {{AQCT-T5}}' );
51 $this->editPage( 'AQCT-4', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] **AQCT-4** {{AQCT-T5}}' );
52 $this->editPage( 'AQCT-5', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] [[AQCT-4]] **AQCT-5**' );
53 } catch ( Exception
$e ) {
54 $this->exceptionFromAddDBData
= $e;
59 * Test smart continue - list=allpages
62 public function test1List() {
63 $this->mVerbose
= false;
64 $mk = function ( $l ) {
67 'apprefix' => 'AQCT-',
71 $data = $this->query( $mk( 99 ), 1, '1L', false );
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' );
82 * Test smart continue - list=allpages|alltransclusions
85 public function test2Lists() {
86 $this->mVerbose
= false;
87 $mk = function ( $l1, $l2 ) {
89 'list' => 'allpages|alltransclusions',
90 'apprefix' => 'AQCT-',
91 'atprefix' => 'AQCT-',
98 $data = $this->query( $mk( 99, 99 ), 1, '2L', false );
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
110 public function testGen1Prop() {
111 $this->mVerbose
= false;
112 $mk = function ( $g, $p ) {
114 'generator' => 'allpages',
115 'gapprefix' => 'AQCT-',
121 // generator + 1 prop
122 $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false );
123 $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
124 $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
125 $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
126 $this->checkC( $data, $mk( 4, 4 ), 3, 'G1P-44' );
127 $this->checkC( $data, $mk( 5, 5 ), 2, 'G1P-55' );
131 * Test smart continue - generator=allpages, prop=links|templates
134 public function testGen2Prop() {
135 $this->mVerbose
= false;
136 $mk = function ( $g, $p1, $p2 ) {
138 'generator' => 'allpages',
139 'gapprefix' => 'AQCT-',
141 'prop' => 'links|templates',
146 // generator + 2 props
147 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false );
148 $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
149 $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
150 $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
151 $this->checkC( $data, $mk( 4, 4, 4 ), 4, 'G2P-444' );
152 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G2P-555' );
153 $this->checkC( $data, $mk( 5, 1, 1 ), 10, 'G2P-511' );
154 $this->checkC( $data, $mk( 4, 2, 2 ), 7, 'G2P-422' );
155 $this->checkC( $data, $mk( 2, 3, 3 ), 7, 'G2P-233' );
156 $this->checkC( $data, $mk( 2, 4, 4 ), 5, 'G2P-244' );
157 $this->checkC( $data, $mk( 1, 5, 5 ), 5, 'G2P-155' );
161 * Test smart continue - generator=allpages, prop=links, list=alltransclusions
164 public function testGen1Prop1List() {
165 $this->mVerbose
= false;
166 $mk = function ( $g, $p, $l ) {
168 'generator' => 'allpages',
169 'gapprefix' => 'AQCT-',
173 'list' => 'alltransclusions',
174 'atprefix' => 'AQCT-',
179 // generator + 1 prop + 1 list
180 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false );
181 $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
182 $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
183 $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
184 $this->checkC( $data, $mk( 4, 4, 4 ), 3, 'G1P1L-444' );
185 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G1P1L-555' );
186 $this->checkC( $data, $mk( 5, 5, 1 ), 4, 'G1P1L-551' );
187 $this->checkC( $data, $mk( 5, 5, 2 ), 2, 'G1P1L-552' );
191 * Test smart continue - generator=allpages, prop=links|templates,
192 * list=alllinks|alltransclusions, meta=siteinfo
195 public function testGen2Prop2List1Meta() {
196 $this->mVerbose
= false;
197 $mk = function ( $g, $p1, $p2, $l1, $l2 ) {
199 'generator' => 'allpages',
200 'gapprefix' => 'AQCT-',
202 'prop' => 'links|templates',
205 'list' => 'alllinks|alltransclusions',
206 'alprefix' => 'AQCT-',
209 'atprefix' => 'AQCT-',
212 'meta' => 'siteinfo',
213 'siprop' => 'namespaces',
216 // generator + 1 prop + 1 list
217 $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false );
218 $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
219 $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
220 $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
221 $this->checkC( $data, $mk( 4, 4, 4, 4, 4 ), 4, 'G2P2L1M-44444' );
222 $this->checkC( $data, $mk( 5, 5, 5, 5, 5 ), 2, 'G2P2L1M-55555' );
223 $this->checkC( $data, $mk( 5, 5, 5, 1, 1 ), 4, 'G2P2L1M-55511' );
224 $this->checkC( $data, $mk( 5, 5, 5, 2, 2 ), 2, 'G2P2L1M-55522' );
225 $this->checkC( $data, $mk( 5, 1, 1, 5, 5 ), 10, 'G2P2L1M-51155' );
226 $this->checkC( $data, $mk( 5, 2, 2, 5, 5 ), 5, 'G2P2L1M-52255' );
230 * Test smart continue - generator=templates, prop=templates
233 public function testSameGenAndProp() {
234 $this->mVerbose
= false;
235 $mk = function ( $g, $gDir, $p, $pDir ) {
237 'titles' => 'AQCT-1',
238 'generator' => 'templates',
240 'gtldir' => $gDir ?
'ascending' : 'descending',
241 'prop' => 'templates',
243 'tldir' => $pDir ?
'ascending' : 'descending',
246 // generator + 1 prop
247 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false );
249 $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
250 $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
251 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=P-3t3t' );
252 $this->checkC( $data, $mk( 1, true, 3, true ), 4, 'G=P-1t3t' );
253 $this->checkC( $data, $mk( 3, true, 1, true ), 2, 'G=P-3t1t' );
255 $this->checkC( $data, $mk( 1, true, 1, false ), 4, 'G=P-1t1f' );
256 $this->checkC( $data, $mk( 2, true, 2, false ), 2, 'G=P-2t2f' );
257 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=P-3t3f' );
258 $this->checkC( $data, $mk( 1, true, 3, false ), 4, 'G=P-1t3f' );
259 $this->checkC( $data, $mk( 3, true, 1, false ), 2, 'G=P-3t1f' );
261 $this->checkC( $data, $mk( 1, false, 1, true ), 4, 'G=P-1f1t' );
262 $this->checkC( $data, $mk( 2, false, 2, true ), 2, 'G=P-2f2t' );
263 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=P-3f3t' );
264 $this->checkC( $data, $mk( 1, false, 3, true ), 4, 'G=P-1f3t' );
265 $this->checkC( $data, $mk( 3, false, 1, true ), 2, 'G=P-3f1t' );
267 $this->checkC( $data, $mk( 1, false, 1, false ), 4, 'G=P-1f1f' );
268 $this->checkC( $data, $mk( 2, false, 2, false ), 2, 'G=P-2f2f' );
269 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=P-3f3f' );
270 $this->checkC( $data, $mk( 1, false, 3, false ), 4, 'G=P-1f3f' );
271 $this->checkC( $data, $mk( 3, false, 1, false ), 2, 'G=P-3f1f' );
275 * Test smart continue - generator=allpages, list=allpages
278 public function testSameGenList() {
279 $this->mVerbose
= false;
280 $mk = function ( $g, $gDir, $l, $pDir ) {
282 'generator' => 'allpages',
283 'gapprefix' => 'AQCT-',
285 'gapdir' => $gDir ?
'ascending' : 'descending',
286 'list' => 'allpages',
287 'apprefix' => 'AQCT-',
289 'apdir' => $pDir ?
'ascending' : 'descending',
292 // generator + 1 list
293 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false );
295 $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
296 $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );
297 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=L-3t3t' );
298 $this->checkC( $data, $mk( 1, true, 3, true ), 5, 'G=L-1t3t' );
299 $this->checkC( $data, $mk( 3, true, 1, true ), 5, 'G=L-3t1t' );
300 $this->checkC( $data, $mk( 1, true, 1, false ), 5, 'G=L-1t1f' );
301 $this->checkC( $data, $mk( 2, true, 2, false ), 3, 'G=L-2t2f' );
302 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=L-3t3f' );
303 $this->checkC( $data, $mk( 1, true, 3, false ), 5, 'G=L-1t3f' );
304 $this->checkC( $data, $mk( 3, true, 1, false ), 5, 'G=L-3t1f' );
305 $this->checkC( $data, $mk( 1, false, 1, true ), 5, 'G=L-1f1t' );
306 $this->checkC( $data, $mk( 2, false, 2, true ), 3, 'G=L-2f2t' );
307 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=L-3f3t' );
308 $this->checkC( $data, $mk( 1, false, 3, true ), 5, 'G=L-1f3t' );
309 $this->checkC( $data, $mk( 3, false, 1, true ), 5, 'G=L-3f1t' );
310 $this->checkC( $data, $mk( 1, false, 1, false ), 5, 'G=L-1f1f' );
311 $this->checkC( $data, $mk( 2, false, 2, false ), 3, 'G=L-2f2f' );
312 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=L-3f3f' );
313 $this->checkC( $data, $mk( 1, false, 3, false ), 5, 'G=L-1f3f' );
314 $this->checkC( $data, $mk( 3, false, 1, false ), 5, 'G=L-3f1f' );