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