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
24 * These tests validate basic functionality of the api query module
31 class ApiQueryBasicTest
extends ApiQueryTestBase
{
32 protected $exceptionFromAddDBData;
35 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
37 *@see MediaWikiTestCase::addDBDataOnce()
39 function addDBDataOnce() {
41 if ( Title
::newFromText( 'AQBT-All' )->exists() ) {
45 // Ordering is important, as it will be returned in the same order as stored in the index
46 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
47 $this->editPage( 'AQBT-Categories', '[[Category:AQBT-Cat]]' );
48 $this->editPage( 'AQBT-Links', '[[AQBT-All]] [[AQBT-Categories]] [[AQBT-Templates]]' );
49 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
50 $this->editPage( 'AQBT-T', 'Content', '', NS_TEMPLATE
);
52 // Refresh due to the bug with listing transclusions as links if they don't exist
53 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
54 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
55 } catch ( Exception
$e ) {
56 $this->exceptionFromAddDBData
= $e;
60 private static $links = [
61 [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
66 'title' => 'AQBT-All',
68 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
74 private static $templates = [
75 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
80 'title' => 'AQBT-All',
82 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
88 private static $categories = [
89 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
94 'title' => 'AQBT-All',
96 [ 'ns' => 14, 'title' => 'Category:AQBT-Cat' ],
102 private static $allpages = [
103 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
105 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
106 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
107 [ 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ],
108 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
112 private static $alllinks = [
113 [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
115 [ 'ns' => 0, 'title' => 'AQBT-All' ],
116 [ 'ns' => 0, 'title' => 'AQBT-Categories' ],
117 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
118 [ 'ns' => 0, 'title' => 'AQBT-Templates' ],
122 private static $alltransclusions = [
123 [ 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ],
124 [ 'alltransclusions' => [
125 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
126 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
130 // Although this appears to have no use it is used by testLists()
131 private static $allcategories = [
132 [ 'list' => 'allcategories', 'acprefix' => 'AQBT-' ],
133 [ 'allcategories' => [
134 [ '*' => 'AQBT-Cat' ],
138 private static $backlinks = [
139 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
141 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
145 private static $embeddedin = [
146 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
148 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
149 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
153 private static $categorymembers = [
154 [ 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ],
155 [ 'categorymembers' => [
156 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
157 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
161 private static $generatorAllpages = [
162 [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
167 'title' => 'AQBT-All' ],
171 'title' => 'AQBT-Categories' ],
175 'title' => 'AQBT-Links' ],
179 'title' => 'AQBT-Templates' ],
183 private static $generatorLinks = [
184 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
189 'title' => 'AQBT-All' ],
193 'title' => 'AQBT-Categories' ],
197 'title' => 'AQBT-Templates' ],
201 private static $generatorLinksPropLinks = [
202 [ 'prop' => 'links' ],
204 '1' => [ 'links' => [
205 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
210 private static $generatorLinksPropTemplates = [
211 [ 'prop' => 'templates' ],
213 '1' => [ 'templates' => [
214 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
215 '4' => [ 'templates' => [
216 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
223 public function testProps() {
224 $this->check( self
::$links );
225 $this->check( self
::$templates );
226 $this->check( self
::$categories );
232 public function testLists() {
233 $this->check( self
::$allpages );
234 $this->check( self
::$alllinks );
235 $this->check( self
::$alltransclusions );
236 // This test is temporarily disabled until a sqlite bug is fixed
237 // Confirmed still broken 15-nov-2013
238 // $this->check( self::$allcategories );
239 $this->check( self
::$backlinks );
240 $this->check( self
::$embeddedin );
241 $this->check( self
::$categorymembers );
247 public function testAllTogether() {
248 // All props together
249 $this->check( $this->merge(
255 // All lists together
256 $this->check( $this->merge(
259 self
::$alltransclusions,
260 // This test is temporarily disabled until a sqlite bug is fixed
261 // self::$allcategories,
264 self
::$categorymembers
267 // All props+lists together
268 $this->check( $this->merge(
274 self
::$alltransclusions,
275 // This test is temporarily disabled until a sqlite bug is fixed
276 // self::$allcategories,
279 self
::$categorymembers
286 public function testGenerator() {
287 // generator=allpages
288 $this->check( self
::$generatorAllpages );
289 // generator=allpages & list=allpages
290 $this->check( $this->merge(
291 self
::$generatorAllpages,
294 $this->check( self
::$generatorLinks );
295 // generator=links & prop=links
296 $this->check( $this->merge(
297 self
::$generatorLinks,
298 self
::$generatorLinksPropLinks ) );
299 // generator=links & prop=templates
300 $this->check( $this->merge(
301 self
::$generatorLinks,
302 self
::$generatorLinksPropTemplates ) );
303 // generator=links & prop=links|templates
304 $this->check( $this->merge(
305 self
::$generatorLinks,
306 self
::$generatorLinksPropLinks,
307 self
::$generatorLinksPropTemplates ) );
308 // generator=links & prop=links|templates & list=allpages|...
309 $this->check( $this->merge(
310 self
::$generatorLinks,
311 self
::$generatorLinksPropLinks,
312 self
::$generatorLinksPropTemplates,
315 self
::$alltransclusions,
316 // This test is temporarily disabled until a sqlite bug is fixed
317 // self::$allcategories,
320 self
::$categorymembers ) );
326 public function testGeneratorRedirects() {
327 $this->editPage( 'AQBT-Target', 'test' );
328 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
330 [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
334 'from' => 'AQBT-Redir',
335 'to' => 'AQBT-Target',
342 'title' => 'AQBT-Target',