9ba4587b5d0461578ee2ad6fd219128802eee6a3
[lhc/web/wiklou.git] / tests / phpunit / includes / api / query / ApiQueryBasicTest.php
1 <?php
2 /**
3 *
4 * Created on Feb 6, 2013
5 *
6 * Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 */
25
26 /**
27 * These tests validate basic functionality of the api query module
28 *
29 * @group API
30 * @group Database
31 * @group medium
32 * @covers ApiQuery
33 */
34 class ApiQueryBasicTest extends ApiQueryTestBase {
35 protected $exceptionFromAddDBData;
36
37 /**
38 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
39 * @see MediaWikiTestCase::addDBData()
40 */
41 function addDBData() {
42 try {
43 if ( Title::newFromText( 'AQBT-All' )->exists() ) {
44 return;
45 }
46
47 // Ordering is important, as it will be returned in the same order as stored in the index
48 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
49 $this->editPage( 'AQBT-Categories', '[[Category:AQBT-Cat]]' );
50 $this->editPage( 'AQBT-Links', '[[AQBT-All]] [[AQBT-Categories]] [[AQBT-Templates]]' );
51 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
52 $this->editPage( 'AQBT-T', 'Content', '', NS_TEMPLATE );
53
54 // Refresh due to the bug with listing transclusions as links if they don't exist
55 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
56 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
57 } catch ( Exception $e ) {
58 $this->exceptionFromAddDBData = $e;
59 }
60 }
61
62 private static $links = [
63 [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
64 [ 'pages' => [
65 '1' => [
66 'pageid' => 1,
67 'ns' => 0,
68 'title' => 'AQBT-All',
69 'links' => [
70 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
71 ]
72 ]
73 ] ]
74 ];
75
76 private static $templates = [
77 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
78 [ 'pages' => [
79 '1' => [
80 'pageid' => 1,
81 'ns' => 0,
82 'title' => 'AQBT-All',
83 'templates' => [
84 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
85 ]
86 ]
87 ] ]
88 ];
89
90 private static $categories = [
91 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
92 [ 'pages' => [
93 '1' => [
94 'pageid' => 1,
95 'ns' => 0,
96 'title' => 'AQBT-All',
97 'categories' => [
98 [ 'ns' => 14, 'title' => 'Category:AQBT-Cat' ],
99 ]
100 ]
101 ] ]
102 ];
103
104 private static $allpages = [
105 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
106 [ 'allpages' => [
107 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
108 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
109 [ 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ],
110 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
111 ] ]
112 ];
113
114 private static $alllinks = [
115 [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
116 [ 'alllinks' => [
117 [ 'ns' => 0, 'title' => 'AQBT-All' ],
118 [ 'ns' => 0, 'title' => 'AQBT-Categories' ],
119 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
120 [ 'ns' => 0, 'title' => 'AQBT-Templates' ],
121 ] ]
122 ];
123
124 private static $alltransclusions = [
125 [ 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ],
126 [ 'alltransclusions' => [
127 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
128 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
129 ] ]
130 ];
131
132 // Although this appears to have no use it is used by testLists()
133 private static $allcategories = [
134 [ 'list' => 'allcategories', 'acprefix' => 'AQBT-' ],
135 [ 'allcategories' => [
136 [ '*' => 'AQBT-Cat' ],
137 ] ]
138 ];
139
140 private static $backlinks = [
141 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
142 [ 'backlinks' => [
143 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
144 ] ]
145 ];
146
147 private static $embeddedin = [
148 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
149 [ 'embeddedin' => [
150 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
151 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
152 ] ]
153 ];
154
155 private static $categorymembers = [
156 [ 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ],
157 [ 'categorymembers' => [
158 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
159 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
160 ] ]
161 ];
162
163 private static $generatorAllpages = [
164 [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
165 [ 'pages' => [
166 '1' => [
167 'pageid' => 1,
168 'ns' => 0,
169 'title' => 'AQBT-All' ],
170 '2' => [
171 'pageid' => 2,
172 'ns' => 0,
173 'title' => 'AQBT-Categories' ],
174 '3' => [
175 'pageid' => 3,
176 'ns' => 0,
177 'title' => 'AQBT-Links' ],
178 '4' => [
179 'pageid' => 4,
180 'ns' => 0,
181 'title' => 'AQBT-Templates' ],
182 ] ]
183 ];
184
185 private static $generatorLinks = [
186 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
187 [ 'pages' => [
188 '1' => [
189 'pageid' => 1,
190 'ns' => 0,
191 'title' => 'AQBT-All' ],
192 '2' => [
193 'pageid' => 2,
194 'ns' => 0,
195 'title' => 'AQBT-Categories' ],
196 '4' => [
197 'pageid' => 4,
198 'ns' => 0,
199 'title' => 'AQBT-Templates' ],
200 ] ]
201 ];
202
203 private static $generatorLinksPropLinks = [
204 [ 'prop' => 'links' ],
205 [ 'pages' => [
206 '1' => [ 'links' => [
207 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
208 ] ]
209 ] ]
210 ];
211
212 private static $generatorLinksPropTemplates = [
213 [ 'prop' => 'templates' ],
214 [ 'pages' => [
215 '1' => [ 'templates' => [
216 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
217 '4' => [ 'templates' => [
218 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
219 ] ]
220 ];
221
222 /**
223 * Test basic props
224 */
225 public function testProps() {
226 $this->check( self::$links );
227 $this->check( self::$templates );
228 $this->check( self::$categories );
229 }
230
231 /**
232 * Test basic lists
233 */
234 public function testLists() {
235 $this->check( self::$allpages );
236 $this->check( self::$alllinks );
237 $this->check( self::$alltransclusions );
238 // This test is temporarily disabled until a sqlite bug is fixed
239 // Confirmed still broken 15-nov-2013
240 // $this->check( self::$allcategories );
241 $this->check( self::$backlinks );
242 $this->check( self::$embeddedin );
243 $this->check( self::$categorymembers );
244 }
245
246 /**
247 * Test basic lists
248 */
249 public function testAllTogether() {
250
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
286 /**
287 * Test basic lists
288 */
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
326 /**
327 * Test bug 51821
328 */
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 }