Merge "Rename Skin::getUsableSkins() to Skin::getAllowedSkins()"
[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
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' );
79 }
80
81 /**
82 * Test smart continue - list=allpages|alltransclusions
83 * @medium
84 */
85 public function test2Lists() {
86 $this->mVerbose = false;
87 $mk = function ( $l1, $l2 ) {
88 return array(
89 'list' => 'allpages|alltransclusions',
90 'apprefix' => 'AQCT-',
91 'atprefix' => 'AQCT-',
92 'atunique' => '',
93 'aplimit' => "$l1",
94 'atlimit' => "$l2",
95 );
96 };
97 // 2 lists
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' );
104 }
105
106 /**
107 * Test smart continue - generator=allpages, prop=links
108 * @medium
109 */
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",
119 );
120 };
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' );
128 }
129
130 /**
131 * Test smart continue - generator=allpages, prop=links|templates
132 * @medium
133 */
134 public function testGen2Prop() {
135 $this->mVerbose = false;
136 $mk = function ( $g, $p1, $p2 ) {
137 return array(
138 'generator' => 'allpages',
139 'gapprefix' => 'AQCT-',
140 'gaplimit' => "$g",
141 'prop' => 'links|templates',
142 'pllimit' => "$p1",
143 'tllimit' => "$p2",
144 );
145 };
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' );
158 }
159
160 /**
161 * Test smart continue - generator=allpages, prop=links, list=alltransclusions
162 * @medium
163 */
164 public function testGen1Prop1List() {
165 $this->mVerbose = false;
166 $mk = function ( $g, $p, $l ) {
167 return array(
168 'generator' => 'allpages',
169 'gapprefix' => 'AQCT-',
170 'gaplimit' => "$g",
171 'prop' => 'links',
172 'pllimit' => "$p",
173 'list' => 'alltransclusions',
174 'atprefix' => 'AQCT-',
175 'atunique' => '',
176 'atlimit' => "$l",
177 );
178 };
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' );
188 }
189
190 /**
191 * Test smart continue - generator=allpages, prop=links|templates,
192 * list=alllinks|alltransclusions, meta=siteinfo
193 * @medium
194 */
195 public function testGen2Prop2List1Meta() {
196 $this->mVerbose = false;
197 $mk = function ( $g, $p1, $p2, $l1, $l2 ) {
198 return array(
199 'generator' => 'allpages',
200 'gapprefix' => 'AQCT-',
201 'gaplimit' => "$g",
202 'prop' => 'links|templates',
203 'pllimit' => "$p1",
204 'tllimit' => "$p2",
205 'list' => 'alllinks|alltransclusions',
206 'alprefix' => 'AQCT-',
207 'alunique' => '',
208 'allimit' => "$l1",
209 'atprefix' => 'AQCT-',
210 'atunique' => '',
211 'atlimit' => "$l2",
212 'meta' => 'siteinfo',
213 'siprop' => 'namespaces',
214 );
215 };
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' );
227 }
228
229 /**
230 * Test smart continue - generator=templates, prop=templates
231 * @medium
232 */
233 public function testSameGenAndProp() {
234 $this->mVerbose = false;
235 $mk = function ( $g, $gDir, $p, $pDir ) {
236 return array(
237 'titles' => 'AQCT-1',
238 'generator' => 'templates',
239 'gtllimit' => "$g",
240 'gtldir' => $gDir ? 'ascending' : 'descending',
241 'prop' => 'templates',
242 'tllimit' => "$p",
243 'tldir' => $pDir ? 'ascending' : 'descending',
244 );
245 };
246 // generator + 1 prop
247 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false );
248
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' );
254
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' );
260
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' );
266
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' );
272 }
273
274 /**
275 * Test smart continue - generator=allpages, list=allpages
276 * @medium
277 */
278 public function testSameGenList() {
279 $this->mVerbose = false;
280 $mk = function ( $g, $gDir, $l, $pDir ) {
281 return array(
282 'generator' => 'allpages',
283 'gapprefix' => 'AQCT-',
284 'gaplimit' => "$g",
285 'gapdir' => $gDir ? 'ascending' : 'descending',
286 'list' => 'allpages',
287 'apprefix' => 'AQCT-',
288 'aplimit' => "$l",
289 'apdir' => $pDir ? 'ascending' : 'descending',
290 );
291 };
292 // generator + 1 list
293 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false );
294
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' );
315 }
316 }