MediaWiki REL1_31
ApiQueryBasicTest.php
Go to the documentation of this file.
1<?php
33
39 function addDBDataOnce() {
40 try {
41 if ( Title::newFromText( 'AQBT-All' )->exists() ) {
42 return;
43 }
44
45 // Ordering is important, as it will be returned in the same order as stored in the index
46 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
47 $this->editPage( 'AQBT-Categories', '[[Category:AQBT-Cat]]' );
48 $this->editPage( 'AQBT-Links', '[[AQBT-All]] [[AQBT-Categories]] [[AQBT-Templates]]' );
49 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
50 $this->editPage( 'AQBT-T', 'Content', '', NS_TEMPLATE );
51
52 // Refresh due to the bug with listing transclusions as links if they don't exist
53 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
54 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
55 } catch ( Exception $e ) {
56 $this->exceptionFromAddDBData = $e;
57 }
58 }
59
60 private static $links = [
61 [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
62 [ 'pages' => [
63 '1' => [
64 'pageid' => 1,
65 'ns' => 0,
66 'title' => 'AQBT-All',
67 'links' => [
68 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
69 ]
70 ]
71 ] ]
72 ];
73
74 private static $templates = [
75 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
76 [ 'pages' => [
77 '1' => [
78 'pageid' => 1,
79 'ns' => 0,
80 'title' => 'AQBT-All',
81 'templates' => [
82 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
83 ]
84 ]
85 ] ]
86 ];
87
88 private static $categories = [
89 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
90 [ 'pages' => [
91 '1' => [
92 'pageid' => 1,
93 'ns' => 0,
94 'title' => 'AQBT-All',
95 'categories' => [
96 [ 'ns' => 14, 'title' => 'Category:AQBT-Cat' ],
97 ]
98 ]
99 ] ]
100 ];
101
102 private static $allpages = [
103 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
104 [ 'allpages' => [
105 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
106 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
107 [ 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ],
108 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
109 ] ]
110 ];
111
112 private static $alllinks = [
113 [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
114 [ 'alllinks' => [
115 [ 'ns' => 0, 'title' => 'AQBT-All' ],
116 [ 'ns' => 0, 'title' => 'AQBT-Categories' ],
117 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
118 [ 'ns' => 0, 'title' => 'AQBT-Templates' ],
119 ] ]
120 ];
121
122 private static $alltransclusions = [
123 [ 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ],
124 [ 'alltransclusions' => [
125 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
126 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
127 ] ]
128 ];
129
130 // Although this appears to have no use it is used by testLists()
131 private static $allcategories = [
132 [ 'list' => 'allcategories', 'acprefix' => 'AQBT-' ],
133 [ 'allcategories' => [
134 [ 'category' => 'AQBT-Cat' ],
135 ] ]
136 ];
137
138 private static $backlinks = [
139 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
140 [ 'backlinks' => [
141 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
142 ] ]
143 ];
144
145 private static $embeddedin = [
146 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
147 [ 'embeddedin' => [
148 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
149 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
150 ] ]
151 ];
152
153 private static $categorymembers = [
154 [ 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ],
155 [ 'categorymembers' => [
156 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
157 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
158 ] ]
159 ];
160
161 private static $generatorAllpages = [
162 [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
163 [ 'pages' => [
164 '1' => [
165 'pageid' => 1,
166 'ns' => 0,
167 'title' => 'AQBT-All' ],
168 '2' => [
169 'pageid' => 2,
170 'ns' => 0,
171 'title' => 'AQBT-Categories' ],
172 '3' => [
173 'pageid' => 3,
174 'ns' => 0,
175 'title' => 'AQBT-Links' ],
176 '4' => [
177 'pageid' => 4,
178 'ns' => 0,
179 'title' => 'AQBT-Templates' ],
180 ] ]
181 ];
182
183 private static $generatorLinks = [
184 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
185 [ 'pages' => [
186 '1' => [
187 'pageid' => 1,
188 'ns' => 0,
189 'title' => 'AQBT-All' ],
190 '2' => [
191 'pageid' => 2,
192 'ns' => 0,
193 'title' => 'AQBT-Categories' ],
194 '4' => [
195 'pageid' => 4,
196 'ns' => 0,
197 'title' => 'AQBT-Templates' ],
198 ] ]
199 ];
200
201 private static $generatorLinksPropLinks = [
202 [ 'prop' => 'links' ],
203 [ 'pages' => [
204 '1' => [ 'links' => [
205 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
206 ] ]
207 ] ]
208 ];
209
211 [ 'prop' => 'templates' ],
212 [ 'pages' => [
213 '1' => [ 'templates' => [
214 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
215 '4' => [ 'templates' => [
216 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
217 ] ]
218 ];
219
223 public function testProps() {
224 $this->check( self::$links );
225 $this->check( self::$templates );
226 $this->check( self::$categories );
227 }
228
232 public function testLists() {
233 $this->check( self::$allpages );
234 $this->check( self::$alllinks );
235 $this->check( self::$alltransclusions );
236 $this->check( self::$allcategories );
237 $this->check( self::$backlinks );
238 $this->check( self::$embeddedin );
239 $this->check( self::$categorymembers );
240 }
241
245 public function testAllTogether() {
246 // All props together
247 $this->check( $this->merge(
248 self::$links,
249 self::$templates,
250 self::$categories
251 ) );
252
253 // All lists together
254 $this->check( $this->merge(
255 self::$allpages,
256 self::$alllinks,
257 self::$alltransclusions,
258 // This test is temporarily disabled until a sqlite bug is fixed
259 // self::$allcategories,
260 self::$backlinks,
261 self::$embeddedin,
262 self::$categorymembers
263 ) );
264
265 // All props+lists together
266 $this->check( $this->merge(
267 self::$links,
268 self::$templates,
269 self::$categories,
270 self::$allpages,
271 self::$alllinks,
272 self::$alltransclusions,
273 // This test is temporarily disabled until a sqlite bug is fixed
274 // self::$allcategories,
275 self::$backlinks,
276 self::$embeddedin,
277 self::$categorymembers
278 ) );
279 }
280
284 public function testGenerator() {
285 // generator=allpages
286 $this->check( self::$generatorAllpages );
287 // generator=allpages & list=allpages
288 $this->check( $this->merge(
289 self::$generatorAllpages,
290 self::$allpages ) );
291 // generator=links
292 $this->check( self::$generatorLinks );
293 // generator=links & prop=links
294 $this->check( $this->merge(
295 self::$generatorLinks,
296 self::$generatorLinksPropLinks ) );
297 // generator=links & prop=templates
298 $this->check( $this->merge(
299 self::$generatorLinks,
300 self::$generatorLinksPropTemplates ) );
301 // generator=links & prop=links|templates
302 $this->check( $this->merge(
303 self::$generatorLinks,
304 self::$generatorLinksPropLinks,
305 self::$generatorLinksPropTemplates ) );
306 // generator=links & prop=links|templates & list=allpages|...
307 $this->check( $this->merge(
308 self::$generatorLinks,
309 self::$generatorLinksPropLinks,
310 self::$generatorLinksPropTemplates,
311 self::$allpages,
312 self::$alllinks,
313 self::$alltransclusions,
314 // This test is temporarily disabled until a sqlite bug is fixed
315 // self::$allcategories,
316 self::$backlinks,
317 self::$embeddedin,
318 self::$categorymembers ) );
319 }
320
324 public function testGeneratorRedirects() {
325 $this->editPage( 'AQBT-Target', 'test' );
326 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
327 $this->check( [
328 [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
329 [
330 'redirects' => [
331 [
332 'from' => 'AQBT-Redir',
333 'to' => 'AQBT-Target',
334 ]
335 ],
336 'pages' => [
337 '6' => [
338 'pageid' => 6,
339 'ns' => 0,
340 'title' => 'AQBT-Target',
341 ]
342 ],
343 ]
344 ] );
345 }
346}
These tests validate basic functionality of the api query module.
testLists()
Test basic lists.
testProps()
Test basic props.
testGenerator()
Test basic lists.
testGeneratorRedirects()
Test T53821.
testAllTogether()
Test basic lists.
This class has some common functionality for testing query module.
merge()
Merges all requests parameter + expected values into one.
editPage( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
in this case you re responsible for computing and outputting the entire conflict i the difference between revisions and your text headers and sections and Diff or overridable Default is either copyrightwarning or copyrightwarning2 overridable Default is editpage tos summary such as anonymity and the real check
Definition hooks.txt:1481
returning false will NOT prevent logging $e
Definition hooks.txt:2176
const NS_TEMPLATE
Definition Defines.php:84