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