MediaWiki REL1_30
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 // All props together
252 $this->check( $this->merge(
253 self::$links,
254 self::$templates,
255 self::$categories
256 ) );
257
258 // All lists together
259 $this->check( $this->merge(
260 self::$allpages,
261 self::$alllinks,
262 self::$alltransclusions,
263 // This test is temporarily disabled until a sqlite bug is fixed
264 // self::$allcategories,
265 self::$backlinks,
266 self::$embeddedin,
267 self::$categorymembers
268 ) );
269
270 // All props+lists together
271 $this->check( $this->merge(
272 self::$links,
273 self::$templates,
274 self::$categories,
275 self::$allpages,
276 self::$alllinks,
277 self::$alltransclusions,
278 // This test is temporarily disabled until a sqlite bug is fixed
279 // self::$allcategories,
280 self::$backlinks,
281 self::$embeddedin,
282 self::$categorymembers
283 ) );
284 }
285
289 public function testGenerator() {
290 // generator=allpages
291 $this->check( self::$generatorAllpages );
292 // generator=allpages & list=allpages
293 $this->check( $this->merge(
294 self::$generatorAllpages,
295 self::$allpages ) );
296 // generator=links
297 $this->check( self::$generatorLinks );
298 // generator=links & prop=links
299 $this->check( $this->merge(
300 self::$generatorLinks,
301 self::$generatorLinksPropLinks ) );
302 // generator=links & prop=templates
303 $this->check( $this->merge(
304 self::$generatorLinks,
305 self::$generatorLinksPropTemplates ) );
306 // generator=links & prop=links|templates
307 $this->check( $this->merge(
308 self::$generatorLinks,
309 self::$generatorLinksPropLinks,
310 self::$generatorLinksPropTemplates ) );
311 // generator=links & prop=links|templates & list=allpages|...
312 $this->check( $this->merge(
313 self::$generatorLinks,
314 self::$generatorLinksPropLinks,
315 self::$generatorLinksPropTemplates,
316 self::$allpages,
317 self::$alllinks,
318 self::$alltransclusions,
319 // This test is temporarily disabled until a sqlite bug is fixed
320 // self::$allcategories,
321 self::$backlinks,
322 self::$embeddedin,
323 self::$categorymembers ) );
324 }
325
329 public function testGeneratorRedirects() {
330 $this->editPage( 'AQBT-Target', 'test' );
331 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
332 $this->check( [
333 [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
334 [
335 'redirects' => [
336 [
337 'from' => 'AQBT-Redir',
338 'to' => 'AQBT-Target',
339 ]
340 ],
341 'pages' => [
342 '6' => [
343 'pageid' => 6,
344 'ns' => 0,
345 'title' => 'AQBT-Target',
346 ]
347 ],
348 ]
349 ] );
350 }
351}
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.
const NS_TEMPLATE
Definition Defines.php:75
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:1471
returning false will NOT prevent logging $e
Definition hooks.txt:2146
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