Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryBasicTest.php
blobfa0e4cb53ab40126d04f7789d5ae0b166804b2c1
1 <?php
2 /**
4 * Created on Feb 6, 2013
6 * Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
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.
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.
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
23 * @file
26 /**
27 * These tests validate basic functionality of the api query module
29 * @group API
30 * @group Database
31 * @group medium
32 * @covers ApiQuery
34 class ApiQueryBasicTest extends ApiQueryTestBase {
35 protected $exceptionFromAddDBData;
37 /**
38 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
39 * @see MediaWikiTestCase::addDBData()
41 function addDBData() {
42 try {
43 if ( Title::newFromText( 'AQBT-All' )->exists() ) {
44 return;
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 );
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;
62 private static $links = array(
63 array( 'prop' => 'links', 'titles' => 'AQBT-All' ),
64 array( 'pages' => array(
65 '1' => array(
66 'pageid' => 1,
67 'ns' => 0,
68 'title' => 'AQBT-All',
69 'links' => array(
70 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
73 ) )
76 private static $templates = array(
77 array( 'prop' => 'templates', 'titles' => 'AQBT-All' ),
78 array( 'pages' => array(
79 '1' => array(
80 'pageid' => 1,
81 'ns' => 0,
82 'title' => 'AQBT-All',
83 'templates' => array(
84 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
87 ) )
90 private static $categories = array(
91 array( 'prop' => 'categories', 'titles' => 'AQBT-All' ),
92 array( 'pages' => array(
93 '1' => array(
94 'pageid' => 1,
95 'ns' => 0,
96 'title' => 'AQBT-All',
97 'categories' => array(
98 array( 'ns' => 14, 'title' => 'Category:AQBT-Cat' ),
104 private static $allpages = array(
105 array( 'list' => 'allpages', 'apprefix' => 'AQBT-' ),
106 array( 'allpages' => array(
107 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
108 array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
109 array( 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ),
110 array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
114 private static $alllinks = array(
115 array( 'list' => 'alllinks', 'alprefix' => 'AQBT-' ),
116 array( 'alllinks' => array(
117 array( 'ns' => 0, 'title' => 'AQBT-All' ),
118 array( 'ns' => 0, 'title' => 'AQBT-Categories' ),
119 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
120 array( 'ns' => 0, 'title' => 'AQBT-Templates' ),
124 private static $alltransclusions = array(
125 array( 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ),
126 array( 'alltransclusions' => array(
127 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
128 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
132 // Although this appears to have no use it is used by testLists()
133 private static $allcategories = array(
134 array( 'list' => 'allcategories', 'acprefix' => 'AQBT-' ),
135 array( 'allcategories' => array(
136 array( '*' => 'AQBT-Cat' ),
140 private static $backlinks = array(
141 array( 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ),
142 array( 'backlinks' => array(
143 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
147 private static $embeddedin = array(
148 array( 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ),
149 array( 'embeddedin' => array(
150 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
151 array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
155 private static $categorymembers = array(
156 array( 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ),
157 array( 'categorymembers' => array(
158 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
159 array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
163 private static $generatorAllpages = array(
164 array( 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ),
165 array( 'pages' => array(
166 '1' => array(
167 'pageid' => 1,
168 'ns' => 0,
169 'title' => 'AQBT-All' ),
170 '2' => array(
171 'pageid' => 2,
172 'ns' => 0,
173 'title' => 'AQBT-Categories' ),
174 '3' => array(
175 'pageid' => 3,
176 'ns' => 0,
177 'title' => 'AQBT-Links' ),
178 '4' => array(
179 'pageid' => 4,
180 'ns' => 0,
181 'title' => 'AQBT-Templates' ),
185 private static $generatorLinks = array(
186 array( 'generator' => 'links', 'titles' => 'AQBT-Links' ),
187 array( 'pages' => array(
188 '1' => array(
189 'pageid' => 1,
190 'ns' => 0,
191 'title' => 'AQBT-All' ),
192 '2' => array(
193 'pageid' => 2,
194 'ns' => 0,
195 'title' => 'AQBT-Categories' ),
196 '4' => array(
197 'pageid' => 4,
198 'ns' => 0,
199 'title' => 'AQBT-Templates' ),
203 private static $generatorLinksPropLinks = array(
204 array( 'prop' => 'links' ),
205 array( 'pages' => array(
206 '1' => array( 'links' => array(
207 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
212 private static $generatorLinksPropTemplates = array(
213 array( 'prop' => 'templates' ),
214 array( 'pages' => array(
215 '1' => array( 'templates' => array(
216 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
217 '4' => array( 'templates' => array(
218 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
223 * Test basic props
225 public function testProps() {
226 $this->check( self::$links );
227 $this->check( self::$templates );
228 $this->check( self::$categories );
232 * Test basic lists
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 );
247 * Test basic lists
249 public function testAllTogether() {
251 // All props together
252 $this->check( $this->merge(
253 self::$links,
254 self::$templates,
255 self::$categories
256 ) );
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 ) );
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 ) );
287 * Test basic lists
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 ) );
327 * Test bug 51821
329 public function testGeneratorRedirects() {
330 $this->editPage( 'AQBT-Target', 'test' );
331 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
332 $this->check( array(
333 array( 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ),
334 array(
335 'redirects' => array(
336 array(
337 'from' => 'AQBT-Redir',
338 'to' => 'AQBT-Target',
341 'pages' => array(
342 '6' => array(
343 'pageid' => 6,
344 'ns' => 0,
345 'title' => 'AQBT-Target',
349 ) );