Merge "Create tooltip for "Page information" link"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / query / ApiQueryContinueTest.php
1 <?php
2 /**
3 * Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
4 *
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.
9 *
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.
14 *
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
19 */
20
21 require_once 'ApiQueryContinueTestBase.php';
22
23 /**
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.
27 *
28 * @group API
29 * @group Database
30 * @group medium
31 * @covers ApiQuery
32 */
33 class ApiQueryContinueTest extends ApiQueryContinueTestBase {
34 protected $exceptionFromAddDBData;
35
36 /**
37 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
38 * @see MediaWikiTestCase::addDBData()
39 */
40 function addDBData() {
41 try {
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**' );
47
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;
55 }
56 }
57
58 /**
59 * Test smart continue - list=allpages
60 * @medium
61 */
62 public function test1List() {
63 $this->mVerbose = false;
64 $mk = function ( $l ) {
65 return array(
66 'list' => 'allpages',
67 'apprefix' => 'AQCT-',
68 'aplimit' => "$l",
69 );
70 };
71 $data = $this->query( $mk( 99 ), 1, '1L', false ) +
72 array( 'batchcomplete' => '' );
73
74 // 1 list
75 $this->checkC( $data, $mk( 1 ), 5, '1L-1' );
76 $this->checkC( $data, $mk( 2 ), 3, '1L-2' );
77 $this->checkC( $data, $mk( 3 ), 2, '1L-3' );
78 $this->checkC( $data, $mk( 4 ), 2, '1L-4' );
79 $this->checkC( $data, $mk( 5 ), 1, '1L-5' );
80 }
81
82 /**
83 * Test smart continue - list=allpages|alltransclusions
84 * @medium
85 */
86 public function test2Lists() {
87 $this->mVerbose = false;
88 $mk = function ( $l1, $l2 ) {
89 return array(
90 'list' => 'allpages|alltransclusions',
91 'apprefix' => 'AQCT-',
92 'atprefix' => 'AQCT-',
93 'atunique' => '',
94 'aplimit' => "$l1",
95 'atlimit' => "$l2",
96 );
97 };
98 // 2 lists
99 $data = $this->query( $mk( 99, 99 ), 1, '2L', false ) +
100 array( 'batchcomplete' => '' );
101 $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
102 $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
103 $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
104 $this->checkC( $data, $mk( 4, 4 ), 2, '2L-44' );
105 $this->checkC( $data, $mk( 5, 5 ), 1, '2L-55' );
106 }
107
108 /**
109 * Test smart continue - generator=allpages, prop=links
110 * @medium
111 */
112 public function testGen1Prop() {
113 $this->mVerbose = false;
114 $mk = function ( $g, $p ) {
115 return array(
116 'generator' => 'allpages',
117 'gapprefix' => 'AQCT-',
118 'gaplimit' => "$g",
119 'prop' => 'links',
120 'pllimit' => "$p",
121 );
122 };
123 // generator + 1 prop
124 $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) +
125 array( 'batchcomplete' => '' );
126 $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
127 $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
128 $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
129 $this->checkC( $data, $mk( 4, 4 ), 3, 'G1P-44' );
130 $this->checkC( $data, $mk( 5, 5 ), 2, 'G1P-55' );
131 }
132
133 /**
134 * Test smart continue - generator=allpages, prop=links|templates
135 * @medium
136 */
137 public function testGen2Prop() {
138 $this->mVerbose = false;
139 $mk = function ( $g, $p1, $p2 ) {
140 return array(
141 'generator' => 'allpages',
142 'gapprefix' => 'AQCT-',
143 'gaplimit' => "$g",
144 'prop' => 'links|templates',
145 'pllimit' => "$p1",
146 'tllimit' => "$p2",
147 );
148 };
149 // generator + 2 props
150 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) +
151 array( 'batchcomplete' => '' );;
152 $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
153 $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
154 $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
155 $this->checkC( $data, $mk( 4, 4, 4 ), 4, 'G2P-444' );
156 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G2P-555' );
157 $this->checkC( $data, $mk( 5, 1, 1 ), 10, 'G2P-511' );
158 $this->checkC( $data, $mk( 4, 2, 2 ), 7, 'G2P-422' );
159 $this->checkC( $data, $mk( 2, 3, 3 ), 7, 'G2P-233' );
160 $this->checkC( $data, $mk( 2, 4, 4 ), 5, 'G2P-244' );
161 $this->checkC( $data, $mk( 1, 5, 5 ), 5, 'G2P-155' );
162 }
163
164 /**
165 * Test smart continue - generator=allpages, prop=links, list=alltransclusions
166 * @medium
167 */
168 public function testGen1Prop1List() {
169 $this->mVerbose = false;
170 $mk = function ( $g, $p, $l ) {
171 return array(
172 'generator' => 'allpages',
173 'gapprefix' => 'AQCT-',
174 'gaplimit' => "$g",
175 'prop' => 'links',
176 'pllimit' => "$p",
177 'list' => 'alltransclusions',
178 'atprefix' => 'AQCT-',
179 'atunique' => '',
180 'atlimit' => "$l",
181 );
182 };
183 // generator + 1 prop + 1 list
184 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) +
185 array( 'batchcomplete' => '' );
186 $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
187 $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
188 $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
189 $this->checkC( $data, $mk( 4, 4, 4 ), 3, 'G1P1L-444' );
190 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G1P1L-555' );
191 $this->checkC( $data, $mk( 5, 5, 1 ), 4, 'G1P1L-551' );
192 $this->checkC( $data, $mk( 5, 5, 2 ), 2, 'G1P1L-552' );
193 }
194
195 /**
196 * Test smart continue - generator=allpages, prop=links|templates,
197 * list=alllinks|alltransclusions, meta=siteinfo
198 * @medium
199 */
200 public function testGen2Prop2List1Meta() {
201 $this->mVerbose = false;
202 $mk = function ( $g, $p1, $p2, $l1, $l2 ) {
203 return array(
204 'generator' => 'allpages',
205 'gapprefix' => 'AQCT-',
206 'gaplimit' => "$g",
207 'prop' => 'links|templates',
208 'pllimit' => "$p1",
209 'tllimit' => "$p2",
210 'list' => 'alllinks|alltransclusions',
211 'alprefix' => 'AQCT-',
212 'alunique' => '',
213 'allimit' => "$l1",
214 'atprefix' => 'AQCT-',
215 'atunique' => '',
216 'atlimit' => "$l2",
217 'meta' => 'siteinfo',
218 'siprop' => 'namespaces',
219 );
220 };
221 // generator + 1 prop + 1 list
222 $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) +
223 array( 'batchcomplete' => '' );
224 $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
225 $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
226 $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
227 $this->checkC( $data, $mk( 4, 4, 4, 4, 4 ), 4, 'G2P2L1M-44444' );
228 $this->checkC( $data, $mk( 5, 5, 5, 5, 5 ), 2, 'G2P2L1M-55555' );
229 $this->checkC( $data, $mk( 5, 5, 5, 1, 1 ), 4, 'G2P2L1M-55511' );
230 $this->checkC( $data, $mk( 5, 5, 5, 2, 2 ), 2, 'G2P2L1M-55522' );
231 $this->checkC( $data, $mk( 5, 1, 1, 5, 5 ), 10, 'G2P2L1M-51155' );
232 $this->checkC( $data, $mk( 5, 2, 2, 5, 5 ), 5, 'G2P2L1M-52255' );
233 }
234
235 /**
236 * Test smart continue - generator=templates, prop=templates
237 * @medium
238 */
239 public function testSameGenAndProp() {
240 $this->mVerbose = false;
241 $mk = function ( $g, $gDir, $p, $pDir ) {
242 return array(
243 'titles' => 'AQCT-1',
244 'generator' => 'templates',
245 'gtllimit' => "$g",
246 'gtldir' => $gDir ? 'ascending' : 'descending',
247 'prop' => 'templates',
248 'tllimit' => "$p",
249 'tldir' => $pDir ? 'ascending' : 'descending',
250 );
251 };
252 // generator + 1 prop
253 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) +
254 array( 'batchcomplete' => '' );
255
256 $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
257 $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
258 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=P-3t3t' );
259 $this->checkC( $data, $mk( 1, true, 3, true ), 4, 'G=P-1t3t' );
260 $this->checkC( $data, $mk( 3, true, 1, true ), 2, 'G=P-3t1t' );
261
262 $this->checkC( $data, $mk( 1, true, 1, false ), 4, 'G=P-1t1f' );
263 $this->checkC( $data, $mk( 2, true, 2, false ), 2, 'G=P-2t2f' );
264 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=P-3t3f' );
265 $this->checkC( $data, $mk( 1, true, 3, false ), 4, 'G=P-1t3f' );
266 $this->checkC( $data, $mk( 3, true, 1, false ), 2, 'G=P-3t1f' );
267
268 $this->checkC( $data, $mk( 1, false, 1, true ), 4, 'G=P-1f1t' );
269 $this->checkC( $data, $mk( 2, false, 2, true ), 2, 'G=P-2f2t' );
270 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=P-3f3t' );
271 $this->checkC( $data, $mk( 1, false, 3, true ), 4, 'G=P-1f3t' );
272 $this->checkC( $data, $mk( 3, false, 1, true ), 2, 'G=P-3f1t' );
273
274 $this->checkC( $data, $mk( 1, false, 1, false ), 4, 'G=P-1f1f' );
275 $this->checkC( $data, $mk( 2, false, 2, false ), 2, 'G=P-2f2f' );
276 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=P-3f3f' );
277 $this->checkC( $data, $mk( 1, false, 3, false ), 4, 'G=P-1f3f' );
278 $this->checkC( $data, $mk( 3, false, 1, false ), 2, 'G=P-3f1f' );
279 }
280
281 /**
282 * Test smart continue - generator=allpages, list=allpages
283 * @medium
284 */
285 public function testSameGenList() {
286 $this->mVerbose = false;
287 $mk = function ( $g, $gDir, $l, $pDir ) {
288 return array(
289 'generator' => 'allpages',
290 'gapprefix' => 'AQCT-',
291 'gaplimit' => "$g",
292 'gapdir' => $gDir ? 'ascending' : 'descending',
293 'list' => 'allpages',
294 'apprefix' => 'AQCT-',
295 'aplimit' => "$l",
296 'apdir' => $pDir ? 'ascending' : 'descending',
297 );
298 };
299 // generator + 1 list
300 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) +
301 array( 'batchcomplete' => '' );
302
303 $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
304 $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );
305 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=L-3t3t' );
306 $this->checkC( $data, $mk( 1, true, 3, true ), 5, 'G=L-1t3t' );
307 $this->checkC( $data, $mk( 3, true, 1, true ), 5, 'G=L-3t1t' );
308 $this->checkC( $data, $mk( 1, true, 1, false ), 5, 'G=L-1t1f' );
309 $this->checkC( $data, $mk( 2, true, 2, false ), 3, 'G=L-2t2f' );
310 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=L-3t3f' );
311 $this->checkC( $data, $mk( 1, true, 3, false ), 5, 'G=L-1t3f' );
312 $this->checkC( $data, $mk( 3, true, 1, false ), 5, 'G=L-3t1f' );
313 $this->checkC( $data, $mk( 1, false, 1, true ), 5, 'G=L-1f1t' );
314 $this->checkC( $data, $mk( 2, false, 2, true ), 3, 'G=L-2f2t' );
315 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=L-3f3t' );
316 $this->checkC( $data, $mk( 1, false, 3, true ), 5, 'G=L-1f3t' );
317 $this->checkC( $data, $mk( 3, false, 1, true ), 5, 'G=L-3f1t' );
318 $this->checkC( $data, $mk( 1, false, 1, false ), 5, 'G=L-1f1f' );
319 $this->checkC( $data, $mk( 2, false, 2, false ), 3, 'G=L-2f2f' );
320 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=L-3f3f' );
321 $this->checkC( $data, $mk( 1, false, 3, false ), 5, 'G=L-1f3f' );
322 $this->checkC( $data, $mk( 3, false, 1, false ), 5, 'G=L-3f1f' );
323 }
324 }