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
27 * These tests validate basic functionality of the api query module
34 class ApiQueryBasicTest
extends ApiQueryTestBase
{
35 protected $exceptionFromAddDBData;
38 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
39 * @see MediaWikiTestCase::addDBData()
41 function addDBData() {
43 if ( Title
::newFromText( 'AQBT-All' )->exists() ) {
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(
68 'title' => 'AQBT-All',
70 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
76 private static $templates = array(
77 array( 'prop' => 'templates', 'titles' => 'AQBT-All' ),
78 array( 'pages' => array(
82 'title' => 'AQBT-All',
84 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
90 private static $categories = array(
91 array( 'prop' => 'categories', 'titles' => 'AQBT-All' ),
92 array( 'pages' => array(
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(
169 'title' => 'AQBT-All' ),
173 'title' => 'AQBT-Categories' ),
177 'title' => 'AQBT-Links' ),
181 'title' => 'AQBT-Templates' ),
185 private static $generatorLinks = array(
186 array( 'generator' => 'links', 'titles' => 'AQBT-Links' ),
187 array( 'pages' => array(
191 'title' => 'AQBT-All' ),
195 'title' => 'AQBT-Categories' ),
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' ) ) ),
225 public function testProps() {
226 $this->check( self
::$links );
227 $this->check( self
::$templates );
228 $this->check( self
::$categories );
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 );
249 public function testAllTogether() {
251 // All props together
252 $this->check( $this->merge(
258 // All lists together
259 $this->check( $this->merge(
262 self
::$alltransclusions,
263 // This test is temporarily disabled until a sqlite bug is fixed
264 // self::$allcategories,
267 self
::$categorymembers
270 // All props+lists together
271 $this->check( $this->merge(
277 self
::$alltransclusions,
278 // This test is temporarily disabled until a sqlite bug is fixed
279 // self::$allcategories,
282 self
::$categorymembers
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,
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,
318 self
::$alltransclusions,
319 // This test is temporarily disabled until a sqlite bug is fixed
320 // self::$allcategories,
323 self
::$categorymembers ) );
329 public function testGeneratorRedirects() {
330 $this->editPage( 'AQBT-Target', 'test' );
331 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
333 array( 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ),
335 'redirects' => array(
337 'from' => 'AQBT-Redir',
338 'to' => 'AQBT-Target',
345 'title' => 'AQBT-Target',