Move DatabaseDomain to Rdbms namespace
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryBasicTest.php
blobe5971b4418789d6b46a0a91c697e44888c64ca3d
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.
40 *@see MediaWikiTestCase::addDBDataOnce()
42 function addDBDataOnce() {
43 try {
44 if ( Title::newFromText( 'AQBT-All' )->exists() ) {
45 return;
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 );
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;
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' ],
74 ] ]
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' ],
88 ] ]
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' ],
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' ],
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' ],
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' ],
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' ],
141 private static $backlinks = [
142 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
143 [ 'backlinks' => [
144 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
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' ],
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' ],
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' ],
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' ],
204 private static $generatorLinksPropLinks = [
205 [ 'prop' => 'links' ],
206 [ 'pages' => [
207 '1' => [ 'links' => [
208 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
213 private static $generatorLinksPropTemplates = [
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' ] ] ],
224 * Test basic props
226 public function testProps() {
227 $this->check( self::$links );
228 $this->check( self::$templates );
229 $this->check( self::$categories );
233 * Test basic lists
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 );
248 * Test basic lists
250 public function testAllTogether() {
252 // All props together
253 $this->check( $this->merge(
254 self::$links,
255 self::$templates,
256 self::$categories
257 ) );
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 ) );
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 ) );
288 * Test basic lists
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 ) );
328 * Test bug 51821
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' ],
336 'redirects' => [
338 'from' => 'AQBT-Redir',
339 'to' => 'AQBT-Target',
342 'pages' => [
343 '6' => [
344 'pageid' => 6,
345 'ns' => 0,
346 'title' => 'AQBT-Target',
350 ] );