MediaWiki REL1_33
ApiQueryContinueTest.php
Go to the documentation of this file.
1<?php
33
39 function addDBDataOnce() {
40 try {
41 $this->editPage( 'Template:AQCT-T1', '**Template:AQCT-T1**' );
42 $this->editPage( 'Template:AQCT-T2', '**Template:AQCT-T2**' );
43 $this->editPage( 'Template:AQCT-T3', '**Template:AQCT-T3**' );
44 $this->editPage( 'Template:AQCT-T4', '**Template:AQCT-T4**' );
45 $this->editPage( 'Template:AQCT-T5', '**Template:AQCT-T5**' );
46
47 $this->editPage( 'AQCT-1', '**AQCT-1** {{AQCT-T2}} {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
48 $this->editPage( 'AQCT-2', '[[AQCT-1]] **AQCT-2** {{AQCT-T3}} {{AQCT-T4}} {{AQCT-T5}}' );
49 $this->editPage( 'AQCT-3', '[[AQCT-1]] [[AQCT-2]] **AQCT-3** {{AQCT-T4}} {{AQCT-T5}}' );
50 $this->editPage( 'AQCT-4', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] **AQCT-4** {{AQCT-T5}}' );
51 $this->editPage( 'AQCT-5', '[[AQCT-1]] [[AQCT-2]] [[AQCT-3]] [[AQCT-4]] **AQCT-5**' );
52 } catch ( Exception $e ) {
53 $this->exceptionFromAddDBData = $e;
54 }
55 }
56
61 public function test1List() {
62 $this->mVerbose = false;
63 $mk = function ( $l ) {
64 return [
65 'list' => 'allpages',
66 'apprefix' => 'AQCT-',
67 'aplimit' => "$l",
68 ];
69 };
70 $data = $this->query( $mk( 99 ), 1, '1L', false ) +
71 [ 'batchcomplete' => true ];
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
85 public function test2Lists() {
86 $this->mVerbose = false;
87 $mk = function ( $l1, $l2 ) {
88 return [
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 [ 'batchcomplete' => true ];
100 $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
101 $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
102 $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
103 $this->checkC( $data, $mk( 4, 4 ), 2, '2L-44' );
104 $this->checkC( $data, $mk( 5, 5 ), 1, '2L-55' );
105 }
106
111 public function testGen1Prop() {
112 $this->mVerbose = false;
113 $mk = function ( $g, $p ) {
114 return [
115 'generator' => 'allpages',
116 'gapprefix' => 'AQCT-',
117 'gaplimit' => "$g",
118 'prop' => 'links',
119 'pllimit' => "$p",
120 ];
121 };
122 // generator + 1 prop
123 $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) +
124 [ 'batchcomplete' => true ];
125 $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
126 $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
127 $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
128 $this->checkC( $data, $mk( 4, 4 ), 3, 'G1P-44' );
129 $this->checkC( $data, $mk( 5, 5 ), 2, 'G1P-55' );
130 }
131
136 public function testGen2Prop() {
137 $this->mVerbose = false;
138 $mk = function ( $g, $p1, $p2 ) {
139 return [
140 'generator' => 'allpages',
141 'gapprefix' => 'AQCT-',
142 'gaplimit' => "$g",
143 'prop' => 'links|templates',
144 'pllimit' => "$p1",
145 'tllimit' => "$p2",
146 ];
147 };
148 // generator + 2 props
149 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) +
150 [ 'batchcomplete' => true ];
151 $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
152 $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
153 $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
154 $this->checkC( $data, $mk( 4, 4, 4 ), 4, 'G2P-444' );
155 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G2P-555' );
156 $this->checkC( $data, $mk( 5, 1, 1 ), 10, 'G2P-511' );
157 $this->checkC( $data, $mk( 4, 2, 2 ), 7, 'G2P-422' );
158 $this->checkC( $data, $mk( 2, 3, 3 ), 7, 'G2P-233' );
159 $this->checkC( $data, $mk( 2, 4, 4 ), 5, 'G2P-244' );
160 $this->checkC( $data, $mk( 1, 5, 5 ), 5, 'G2P-155' );
161 }
162
167 public function testGen1Prop1List() {
168 $this->mVerbose = false;
169 $mk = function ( $g, $p, $l ) {
170 return [
171 'generator' => 'allpages',
172 'gapprefix' => 'AQCT-',
173 'gaplimit' => "$g",
174 'prop' => 'links',
175 'pllimit' => "$p",
176 'list' => 'alltransclusions',
177 'atprefix' => 'AQCT-',
178 'atunique' => '',
179 'atlimit' => "$l",
180 ];
181 };
182 // generator + 1 prop + 1 list
183 $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) +
184 [ 'batchcomplete' => true ];
185 $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
186 $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
187 $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
188 $this->checkC( $data, $mk( 4, 4, 4 ), 3, 'G1P1L-444' );
189 $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G1P1L-555' );
190 $this->checkC( $data, $mk( 5, 5, 1 ), 4, 'G1P1L-551' );
191 $this->checkC( $data, $mk( 5, 5, 2 ), 2, 'G1P1L-552' );
192 }
193
199 public function testGen2Prop2List1Meta() {
200 $this->mVerbose = false;
201 $mk = function ( $g, $p1, $p2, $l1, $l2 ) {
202 return [
203 'generator' => 'allpages',
204 'gapprefix' => 'AQCT-',
205 'gaplimit' => "$g",
206 'prop' => 'links|templates',
207 'pllimit' => "$p1",
208 'tllimit' => "$p2",
209 'list' => 'alllinks|alltransclusions',
210 'alprefix' => 'AQCT-',
211 'alunique' => '',
212 'allimit' => "$l1",
213 'atprefix' => 'AQCT-',
214 'atunique' => '',
215 'atlimit' => "$l2",
216 'meta' => 'siteinfo',
217 'siprop' => 'namespaces',
218 ];
219 };
220 // generator + 1 prop + 1 list
221 $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) +
222 [ 'batchcomplete' => true ];
223 $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
224 $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
225 $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
226 $this->checkC( $data, $mk( 4, 4, 4, 4, 4 ), 4, 'G2P2L1M-44444' );
227 $this->checkC( $data, $mk( 5, 5, 5, 5, 5 ), 2, 'G2P2L1M-55555' );
228 $this->checkC( $data, $mk( 5, 5, 5, 1, 1 ), 4, 'G2P2L1M-55511' );
229 $this->checkC( $data, $mk( 5, 5, 5, 2, 2 ), 2, 'G2P2L1M-55522' );
230 $this->checkC( $data, $mk( 5, 1, 1, 5, 5 ), 10, 'G2P2L1M-51155' );
231 $this->checkC( $data, $mk( 5, 2, 2, 5, 5 ), 5, 'G2P2L1M-52255' );
232 }
233
238 public function testSameGenAndProp() {
239 $this->mVerbose = false;
240 $mk = function ( $g, $gDir, $p, $pDir ) {
241 return [
242 'titles' => 'AQCT-1',
243 'generator' => 'templates',
244 'gtllimit' => "$g",
245 'gtldir' => $gDir ? 'ascending' : 'descending',
246 'prop' => 'templates',
247 'tllimit' => "$p",
248 'tldir' => $pDir ? 'ascending' : 'descending',
249 ];
250 };
251 // generator + 1 prop
252 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) +
253 [ 'batchcomplete' => true ];
254
255 $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
256 $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
257 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=P-3t3t' );
258 $this->checkC( $data, $mk( 1, true, 3, true ), 4, 'G=P-1t3t' );
259 $this->checkC( $data, $mk( 3, true, 1, true ), 2, 'G=P-3t1t' );
260
261 $this->checkC( $data, $mk( 1, true, 1, false ), 4, 'G=P-1t1f' );
262 $this->checkC( $data, $mk( 2, true, 2, false ), 2, 'G=P-2t2f' );
263 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=P-3t3f' );
264 $this->checkC( $data, $mk( 1, true, 3, false ), 4, 'G=P-1t3f' );
265 $this->checkC( $data, $mk( 3, true, 1, false ), 2, 'G=P-3t1f' );
266
267 $this->checkC( $data, $mk( 1, false, 1, true ), 4, 'G=P-1f1t' );
268 $this->checkC( $data, $mk( 2, false, 2, true ), 2, 'G=P-2f2t' );
269 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=P-3f3t' );
270 $this->checkC( $data, $mk( 1, false, 3, true ), 4, 'G=P-1f3t' );
271 $this->checkC( $data, $mk( 3, false, 1, true ), 2, 'G=P-3f1t' );
272
273 $this->checkC( $data, $mk( 1, false, 1, false ), 4, 'G=P-1f1f' );
274 $this->checkC( $data, $mk( 2, false, 2, false ), 2, 'G=P-2f2f' );
275 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=P-3f3f' );
276 $this->checkC( $data, $mk( 1, false, 3, false ), 4, 'G=P-1f3f' );
277 $this->checkC( $data, $mk( 3, false, 1, false ), 2, 'G=P-3f1f' );
278 }
279
284 public function testSameGenList() {
285 $this->mVerbose = false;
286 $mk = function ( $g, $gDir, $l, $pDir ) {
287 return [
288 'generator' => 'allpages',
289 'gapprefix' => 'AQCT-',
290 'gaplimit' => "$g",
291 'gapdir' => $gDir ? 'ascending' : 'descending',
292 'list' => 'allpages',
293 'apprefix' => 'AQCT-',
294 'aplimit' => "$l",
295 'apdir' => $pDir ? 'ascending' : 'descending',
296 ];
297 };
298 // generator + 1 list
299 $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) +
300 [ 'batchcomplete' => true ];
301
302 $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
303 $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );
304 $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=L-3t3t' );
305 $this->checkC( $data, $mk( 1, true, 3, true ), 5, 'G=L-1t3t' );
306 $this->checkC( $data, $mk( 3, true, 1, true ), 5, 'G=L-3t1t' );
307 $this->checkC( $data, $mk( 1, true, 1, false ), 5, 'G=L-1t1f' );
308 $this->checkC( $data, $mk( 2, true, 2, false ), 3, 'G=L-2t2f' );
309 $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=L-3t3f' );
310 $this->checkC( $data, $mk( 1, true, 3, false ), 5, 'G=L-1t3f' );
311 $this->checkC( $data, $mk( 3, true, 1, false ), 5, 'G=L-3t1f' );
312 $this->checkC( $data, $mk( 1, false, 1, true ), 5, 'G=L-1f1t' );
313 $this->checkC( $data, $mk( 2, false, 2, true ), 3, 'G=L-2f2t' );
314 $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=L-3f3t' );
315 $this->checkC( $data, $mk( 1, false, 3, true ), 5, 'G=L-1f3t' );
316 $this->checkC( $data, $mk( 3, false, 1, true ), 5, 'G=L-3f1t' );
317 $this->checkC( $data, $mk( 1, false, 1, false ), 5, 'G=L-1f1f' );
318 $this->checkC( $data, $mk( 2, false, 2, false ), 3, 'G=L-2f2f' );
319 $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=L-3f3f' );
320 $this->checkC( $data, $mk( 1, false, 3, false ), 5, 'G=L-1f3f' );
321 $this->checkC( $data, $mk( 3, false, 1, false ), 5, 'G=L-3f1f' );
322 }
323}
query( $params, $expectedCount, $id, $useContinue=true)
Run query in a loop until no more values are available.
checkC( $expected, $params, $expectedCount, $id, $continue=true)
Run query() and compare against expected values.
Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com".
testGen1Prop()
Test smart continue - generator=allpages, prop=links medium.
testSameGenList()
Test smart continue - generator=allpages, list=allpages medium.
testSameGenAndProp()
Test smart continue - generator=templates, prop=templates medium.
testGen2Prop()
Test smart continue - generator=allpages, prop=links|templates medium.
testGen1Prop1List()
Test smart continue - generator=allpages, prop=links, list=alltransclusions medium.
test1List()
Test smart continue - list=allpages medium.
testGen2Prop2List1Meta()
Test smart continue - generator=allpages, prop=links|templates, list=alllinks|alltransclusions,...
test2Lists()
Test smart continue - list=allpages|alltransclusions medium.
editPage( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2004
returning false will NOT prevent logging $e
Definition hooks.txt:2175
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37