Merge "Drop cache interwiki"
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryBasicTest.php
blob07c6c5a16a760d7af79245585cbd3a618e3220c5
1 <?php
2 /**
3 * Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 namespace MediaWiki\Tests\Api\Query;
25 use Exception;
26 use MediaWiki\Title\Title;
28 /**
29 * These tests validate basic functionality of the api query module
31 * @group API
32 * @group Database
33 * @group medium
34 * @covers MediaWiki\Api\ApiQuery
36 class ApiQueryBasicTest extends ApiQueryTestBase {
37 /** @var Exception|null */
38 protected $exceptionFromAddDBData;
40 /**
41 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
43 * @see MediaWikiIntegrationTestCase::addDBDataOnce()
45 public function addDBDataOnce() {
46 try {
47 if ( Title::makeTitle( NS_MAIN, 'AQBT-All' )->exists() ) {
48 return;
51 // Ordering is important, as it will be returned in the same order as stored in the index
52 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
53 $this->editPage( 'AQBT-Categories', '[[Category:AQBT-Cat]]' );
54 $this->editPage( 'AQBT-Links', '[[AQBT-All]] [[AQBT-Categories]] [[AQBT-Templates]]' );
55 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
56 $this->editPage( 'AQBT-T', 'Content', '', NS_TEMPLATE );
58 // Refresh due to the bug with listing transclusions as links if they don't exist
59 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
60 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
61 } catch ( Exception $e ) {
62 $this->exceptionFromAddDBData = $e;
66 private const LINKS = [
67 [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
68 [ 'pages' => [
69 '1' => [
70 'pageid' => 1,
71 'ns' => NS_MAIN,
72 'title' => 'AQBT-All',
73 'links' => [
74 [ 'ns' => NS_MAIN, 'title' => 'AQBT-Links' ],
77 ] ]
80 private const TEMPLATES = [
81 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
82 [ 'pages' => [
83 '1' => [
84 'pageid' => 1,
85 'ns' => NS_MAIN,
86 'title' => 'AQBT-All',
87 'templates' => [
88 [ 'ns' => NS_TEMPLATE, 'title' => 'Template:AQBT-T' ],
91 ] ]
94 private const CATEGORIES = [
95 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
96 [ 'pages' => [
97 '1' => [
98 'pageid' => 1,
99 'ns' => NS_MAIN,
100 'title' => 'AQBT-All',
101 'categories' => [
102 [ 'ns' => NS_CATEGORY, 'title' => 'Category:AQBT-Cat' ],
108 private const ALLPAGES = [
109 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
110 [ 'allpages' => [
111 [ 'pageid' => 1, 'ns' => NS_MAIN, 'title' => 'AQBT-All' ],
112 [ 'pageid' => 2, 'ns' => NS_MAIN, 'title' => 'AQBT-Categories' ],
113 [ 'pageid' => 3, 'ns' => NS_MAIN, 'title' => 'AQBT-Links' ],
114 [ 'pageid' => 4, 'ns' => NS_MAIN, 'title' => 'AQBT-Templates' ],
118 private const ALLLINKS = [
119 [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
120 [ 'alllinks' => [
121 [ 'ns' => NS_MAIN, 'title' => 'AQBT-Links' ],
122 [ 'ns' => NS_MAIN, 'title' => 'AQBT-All' ],
123 [ 'ns' => NS_MAIN, 'title' => 'AQBT-Categories' ],
124 [ 'ns' => NS_MAIN, 'title' => 'AQBT-Templates' ],
128 private const ALLTRANSCLUSIONS = [
129 [ 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ],
130 [ 'alltransclusions' => [
131 [ 'ns' => NS_TEMPLATE, 'title' => 'Template:AQBT-T' ],
132 [ 'ns' => NS_TEMPLATE, 'title' => 'Template:AQBT-T' ],
136 /** Although this appears to have no use it is used by testLists() */
137 private const ALLCATEGORIES = [
138 [ 'list' => 'allcategories', 'acprefix' => 'AQBT-' ],
139 [ 'allcategories' => [
140 [ 'category' => 'AQBT-Cat' ],
144 private const BACKLINKS = [
145 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
146 [ 'backlinks' => [
147 [ 'pageid' => 1, 'ns' => NS_MAIN, 'title' => 'AQBT-All' ],
151 private const EMBEDDEDIN = [
152 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
153 [ 'embeddedin' => [
154 [ 'pageid' => 1, 'ns' => NS_MAIN, 'title' => 'AQBT-All' ],
155 [ 'pageid' => 4, 'ns' => NS_MAIN, 'title' => 'AQBT-Templates' ],
159 private const CATEGORYMEMBERS = [
160 [ 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ],
161 [ 'categorymembers' => [
162 [ 'pageid' => 1, 'ns' => NS_MAIN, 'title' => 'AQBT-All' ],
163 [ 'pageid' => 2, 'ns' => NS_MAIN, 'title' => 'AQBT-Categories' ],
167 private const GENERATOR_ALLPAGES = [
168 [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
169 [ 'pages' => [
170 '1' => [
171 'pageid' => 1,
172 'ns' => NS_MAIN,
173 'title' => 'AQBT-All' ],
174 '2' => [
175 'pageid' => 2,
176 'ns' => NS_MAIN,
177 'title' => 'AQBT-Categories' ],
178 '3' => [
179 'pageid' => 3,
180 'ns' => NS_MAIN,
181 'title' => 'AQBT-Links' ],
182 '4' => [
183 'pageid' => 4,
184 'ns' => NS_MAIN,
185 'title' => 'AQBT-Templates' ],
189 private const GENERATOR_LINKS = [
190 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
191 [ 'pages' => [
192 '1' => [
193 'pageid' => 1,
194 'ns' => NS_MAIN,
195 'title' => 'AQBT-All' ],
196 '2' => [
197 'pageid' => 2,
198 'ns' => NS_MAIN,
199 'title' => 'AQBT-Categories' ],
200 '4' => [
201 'pageid' => 4,
202 'ns' => NS_MAIN,
203 'title' => 'AQBT-Templates' ],
207 private const GENERATOR_LINKS_PROP_LINKS = [
208 [ 'prop' => 'links' ],
209 [ 'pages' => [
210 '1' => [ 'links' => [
211 [ 'ns' => NS_MAIN, 'title' => 'AQBT-Links' ],
216 private const GENERATOR_LINKS_PROP_TEMPLATES = [
217 [ 'prop' => 'templates' ],
218 [ 'pages' => [
219 '1' => [ 'templates' => [
220 [ 'ns' => NS_TEMPLATE, 'title' => 'Template:AQBT-T' ] ] ],
221 '4' => [ 'templates' => [
222 [ 'ns' => NS_TEMPLATE, 'title' => 'Template:AQBT-T' ] ] ],
227 * Test basic props
229 public function testProps() {
230 $this->check( self::LINKS );
231 $this->check( self::TEMPLATES );
232 $this->check( self::CATEGORIES );
236 * Test basic lists
238 public function testLists() {
239 $this->check( self::ALLPAGES );
240 $this->check( self::ALLLINKS );
241 $this->check( self::ALLTRANSCLUSIONS );
242 $this->check( self::ALLCATEGORIES );
243 $this->check( self::BACKLINKS );
244 $this->check( self::EMBEDDEDIN );
245 $this->check( self::CATEGORYMEMBERS );
249 * Test basic lists
251 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::GENERATOR_ALLPAGES );
293 // generator=allpages & list=allpages
294 $this->check( $this->merge(
295 self::GENERATOR_ALLPAGES,
296 self::ALLPAGES ) );
297 // generator=links
298 $this->check( self::GENERATOR_LINKS );
299 // generator=links & prop=links
300 $this->check( $this->merge(
301 self::GENERATOR_LINKS,
302 self::GENERATOR_LINKS_PROP_LINKS ) );
303 // generator=links & prop=templates
304 $this->check( $this->merge(
305 self::GENERATOR_LINKS,
306 self::GENERATOR_LINKS_PROP_TEMPLATES ) );
307 // generator=links & prop=links|templates
308 $this->check( $this->merge(
309 self::GENERATOR_LINKS,
310 self::GENERATOR_LINKS_PROP_LINKS,
311 self::GENERATOR_LINKS_PROP_TEMPLATES ) );
312 // generator=links & prop=links|templates & list=allpages|...
313 $this->check( $this->merge(
314 self::GENERATOR_LINKS,
315 self::GENERATOR_LINKS_PROP_LINKS,
316 self::GENERATOR_LINKS_PROP_TEMPLATES,
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 T53821
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' => NS_MAIN,
346 'title' => 'AQBT-Target',
350 ] );