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