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
23 namespace MediaWiki\Tests\Api\Query
;
26 use MediaWiki\Title\Title
;
29 * These tests validate basic functionality of the api query module
34 * @covers MediaWiki\Api\ApiQuery
36 class ApiQueryBasicTest
extends ApiQueryTestBase
{
37 /** @var Exception|null */
38 protected $exceptionFromAddDBData;
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() {
47 if ( Title
::makeTitle( NS_MAIN
, 'AQBT-All' )->exists() ) {
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' ],
72 'title' => 'AQBT-All',
74 [ 'ns' => NS_MAIN
, 'title' => 'AQBT-Links' ],
80 private const TEMPLATES
= [
81 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
86 'title' => 'AQBT-All',
88 [ 'ns' => NS_TEMPLATE
, 'title' => 'Template:AQBT-T' ],
94 private const CATEGORIES
= [
95 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
100 'title' => 'AQBT-All',
102 [ 'ns' => NS_CATEGORY
, 'title' => 'Category:AQBT-Cat' ],
108 private const ALLPAGES
= [
109 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
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-' ],
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' ],
147 [ 'pageid' => 1, 'ns' => NS_MAIN
, 'title' => 'AQBT-All' ],
151 private const EMBEDDEDIN
= [
152 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
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-' ],
173 'title' => 'AQBT-All' ],
177 'title' => 'AQBT-Categories' ],
181 'title' => 'AQBT-Links' ],
185 'title' => 'AQBT-Templates' ],
189 private const GENERATOR_LINKS
= [
190 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
195 'title' => 'AQBT-All' ],
199 'title' => 'AQBT-Categories' ],
203 'title' => 'AQBT-Templates' ],
207 private const GENERATOR_LINKS_PROP_LINKS
= [
208 [ 'prop' => 'links' ],
210 '1' => [ 'links' => [
211 [ 'ns' => NS_MAIN
, 'title' => 'AQBT-Links' ],
216 private const GENERATOR_LINKS_PROP_TEMPLATES
= [
217 [ 'prop' => 'templates' ],
219 '1' => [ 'templates' => [
220 [ 'ns' => NS_TEMPLATE
, 'title' => 'Template:AQBT-T' ] ] ],
221 '4' => [ 'templates' => [
222 [ 'ns' => NS_TEMPLATE
, 'title' => 'Template:AQBT-T' ] ] ],
229 public function testProps() {
230 $this->check( self
::LINKS
);
231 $this->check( self
::TEMPLATES
);
232 $this->check( self
::CATEGORIES
);
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
);
251 public function testAllTogether() {
252 // All props together
253 $this->check( $this->merge(
259 // All lists together
260 $this->check( $this->merge(
263 self
::ALLTRANSCLUSIONS
,
264 // This test is temporarily disabled until a sqlite bug is fixed
265 // self::ALLCATEGORIES,
268 self
::CATEGORYMEMBERS
271 // All props+lists together
272 $this->check( $this->merge(
278 self
::ALLTRANSCLUSIONS
,
279 // This test is temporarily disabled until a sqlite bug is fixed
280 // self::ALLCATEGORIES,
283 self
::CATEGORYMEMBERS
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
,
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
,
319 self
::ALLTRANSCLUSIONS
,
320 // This test is temporarily disabled until a sqlite bug is fixed
321 // self::ALLCATEGORIES,
324 self
::CATEGORYMEMBERS
) );
330 public function testGeneratorRedirects() {
331 $this->editPage( 'AQBT-Target', 'test' );
332 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
334 [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
338 'from' => 'AQBT-Redir',
339 'to' => 'AQBT-Target',
346 'title' => 'AQBT-Target',