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
26 require_once 'ApiQueryTestBase.php';
29 * These tests validate basic functionality of the api query module
36 class ApiQueryBasicTest
extends ApiQueryTestBase
{
37 protected $exceptionFromAddDBData;
40 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
41 * @see MediaWikiTestCase::addDBData()
43 function addDBData() {
45 if ( Title
::newFromText( 'AQBT-All' )->exists() ) {
49 // Ordering is important, as it will be returned in the same order as stored in the index
50 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
51 $this->editPage( 'AQBT-Categories', '[[Category:AQBT-Cat]]' );
52 $this->editPage( 'AQBT-Links', '[[AQBT-All]] [[AQBT-Categories]] [[AQBT-Templates]]' );
53 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
54 $this->editPage( 'AQBT-T', 'Content', '', NS_TEMPLATE
);
56 // Refresh due to the bug with listing transclusions as links if they don't exist
57 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
58 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
59 } catch ( Exception
$e ) {
60 $this->exceptionFromAddDBData
= $e;
64 private static $links = array(
65 array( 'prop' => 'links', 'titles' => 'AQBT-All' ),
66 array( 'pages' => array(
70 'title' => 'AQBT-All',
72 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
78 private static $templates = array(
79 array( 'prop' => 'templates', 'titles' => 'AQBT-All' ),
80 array( 'pages' => array(
84 'title' => 'AQBT-All',
86 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
92 private static $categories = array(
93 array( 'prop' => 'categories', 'titles' => 'AQBT-All' ),
94 array( 'pages' => array(
98 'title' => 'AQBT-All',
99 'categories' => array(
100 array( 'ns' => 14, 'title' => 'Category:AQBT-Cat' ),
106 private static $allpages = array(
107 array( 'list' => 'allpages', 'apprefix' => 'AQBT-' ),
108 array( 'allpages' => array(
109 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
110 array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
111 array( 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ),
112 array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
116 private static $alllinks = array(
117 array( 'list' => 'alllinks', 'alprefix' => 'AQBT-' ),
118 array( 'alllinks' => array(
119 array( 'ns' => 0, 'title' => 'AQBT-All' ),
120 array( 'ns' => 0, 'title' => 'AQBT-Categories' ),
121 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
122 array( 'ns' => 0, 'title' => 'AQBT-Templates' ),
126 private static $alltransclusions = array(
127 array( 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ),
128 array( 'alltransclusions' => array(
129 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
130 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
134 // Although this appears to have no use it is used by testLists()
135 private static $allcategories = array(
136 array( 'list' => 'allcategories', 'acprefix' => 'AQBT-' ),
137 array( 'allcategories' => array(
138 array( '*' => 'AQBT-Cat' ),
142 private static $backlinks = array(
143 array( 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ),
144 array( 'backlinks' => array(
145 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
149 private static $embeddedin = array(
150 array( 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ),
151 array( 'embeddedin' => array(
152 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
153 array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
157 private static $categorymembers = array(
158 array( 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ),
159 array( 'categorymembers' => array(
160 array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
161 array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
165 private static $generatorAllpages = array(
166 array( 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ),
167 array( 'pages' => array(
171 'title' => 'AQBT-All' ),
175 'title' => 'AQBT-Categories' ),
179 'title' => 'AQBT-Links' ),
183 'title' => 'AQBT-Templates' ),
187 private static $generatorLinks = array(
188 array( 'generator' => 'links', 'titles' => 'AQBT-Links' ),
189 array( 'pages' => array(
193 'title' => 'AQBT-All' ),
197 'title' => 'AQBT-Categories' ),
201 'title' => 'AQBT-Templates' ),
205 private static $generatorLinksPropLinks = array(
206 array( 'prop' => 'links' ),
207 array( 'pages' => array(
208 '1' => array( 'links' => array(
209 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
214 private static $generatorLinksPropTemplates = array(
215 array( 'prop' => 'templates' ),
216 array( 'pages' => array(
217 '1' => array( 'templates' => array(
218 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
219 '4' => array( 'templates' => array(
220 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
227 public function testProps() {
228 $this->check( self
::$links );
229 $this->check( self
::$templates );
230 $this->check( self
::$categories );
236 public function testLists() {
237 $this->check( self
::$allpages );
238 $this->check( self
::$alllinks );
239 $this->check( self
::$alltransclusions );
240 // This test is temporarily disabled until a sqlite bug is fixed
241 // Confirmed still broken 15-nov-2013
242 // $this->check( self::$allcategories );
243 $this->check( self
::$backlinks );
244 $this->check( self
::$embeddedin );
245 $this->check( self
::$categorymembers );
251 public function testAllTogether() {
253 // All props together
254 $this->check( $this->merge(
260 // All lists together
261 $this->check( $this->merge(
264 self
::$alltransclusions,
265 // This test is temporarily disabled until a sqlite bug is fixed
266 // self::$allcategories,
269 self
::$categorymembers
272 // All props+lists together
273 $this->check( $this->merge(
279 self
::$alltransclusions,
280 // This test is temporarily disabled until a sqlite bug is fixed
281 // self::$allcategories,
284 self
::$categorymembers
291 public function testGenerator() {
292 // generator=allpages
293 $this->check( self
::$generatorAllpages );
294 // generator=allpages & list=allpages
295 $this->check( $this->merge(
296 self
::$generatorAllpages,
299 $this->check( self
::$generatorLinks );
300 // generator=links & prop=links
301 $this->check( $this->merge(
302 self
::$generatorLinks,
303 self
::$generatorLinksPropLinks ) );
304 // generator=links & prop=templates
305 $this->check( $this->merge(
306 self
::$generatorLinks,
307 self
::$generatorLinksPropTemplates ) );
308 // generator=links & prop=links|templates
309 $this->check( $this->merge(
310 self
::$generatorLinks,
311 self
::$generatorLinksPropLinks,
312 self
::$generatorLinksPropTemplates ) );
313 // generator=links & prop=links|templates & list=allpages|...
314 $this->check( $this->merge(
315 self
::$generatorLinks,
316 self
::$generatorLinksPropLinks,
317 self
::$generatorLinksPropTemplates,
320 self
::$alltransclusions,
321 // This test is temporarily disabled until a sqlite bug is fixed
322 // self::$allcategories,
325 self
::$categorymembers ) );
331 public function testGeneratorRedirects() {
332 $this->editPage( 'AQBT-Target', 'test' );
333 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
335 array( 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ),
337 'redirects' => array(
339 'from' => 'AQBT-Redir',
340 'to' => 'AQBT-Target',
347 'title' => 'AQBT-Target',