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.
40 *@see MediaWikiTestCase::addDBDataOnce()
42 function addDBDataOnce() {
44 if ( Title
::newFromText( 'AQBT-All' )->exists() ) {
48 // Ordering is important, as it will be returned in the same order as stored in the index
49 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
50 $this->editPage( 'AQBT-Categories', '[[Category:AQBT-Cat]]' );
51 $this->editPage( 'AQBT-Links', '[[AQBT-All]] [[AQBT-Categories]] [[AQBT-Templates]]' );
52 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
53 $this->editPage( 'AQBT-T', 'Content', '', NS_TEMPLATE
);
55 // Refresh due to the bug with listing transclusions as links if they don't exist
56 $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
57 $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
58 } catch ( Exception
$e ) {
59 $this->exceptionFromAddDBData
= $e;
63 private static $links = [
64 [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
69 'title' => 'AQBT-All',
71 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
77 private static $templates = [
78 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
83 'title' => 'AQBT-All',
85 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
91 private static $categories = [
92 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
97 'title' => 'AQBT-All',
99 [ 'ns' => 14, 'title' => 'Category:AQBT-Cat' ],
105 private static $allpages = [
106 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
108 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
109 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
110 [ 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ],
111 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
115 private static $alllinks = [
116 [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
118 [ 'ns' => 0, 'title' => 'AQBT-All' ],
119 [ 'ns' => 0, 'title' => 'AQBT-Categories' ],
120 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
121 [ 'ns' => 0, 'title' => 'AQBT-Templates' ],
125 private static $alltransclusions = [
126 [ 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ],
127 [ 'alltransclusions' => [
128 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
129 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
133 // Although this appears to have no use it is used by testLists()
134 private static $allcategories = [
135 [ 'list' => 'allcategories', 'acprefix' => 'AQBT-' ],
136 [ 'allcategories' => [
137 [ '*' => 'AQBT-Cat' ],
141 private static $backlinks = [
142 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
144 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
148 private static $embeddedin = [
149 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
151 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
152 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
156 private static $categorymembers = [
157 [ 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ],
158 [ 'categorymembers' => [
159 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
160 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
164 private static $generatorAllpages = [
165 [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
170 'title' => 'AQBT-All' ],
174 'title' => 'AQBT-Categories' ],
178 'title' => 'AQBT-Links' ],
182 'title' => 'AQBT-Templates' ],
186 private static $generatorLinks = [
187 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
192 'title' => 'AQBT-All' ],
196 'title' => 'AQBT-Categories' ],
200 'title' => 'AQBT-Templates' ],
204 private static $generatorLinksPropLinks = [
205 [ 'prop' => 'links' ],
207 '1' => [ 'links' => [
208 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
213 private static $generatorLinksPropTemplates = [
214 [ 'prop' => 'templates' ],
216 '1' => [ 'templates' => [
217 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
218 '4' => [ 'templates' => [
219 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
226 public function testProps() {
227 $this->check( self
::$links );
228 $this->check( self
::$templates );
229 $this->check( self
::$categories );
235 public function testLists() {
236 $this->check( self
::$allpages );
237 $this->check( self
::$alllinks );
238 $this->check( self
::$alltransclusions );
239 // This test is temporarily disabled until a sqlite bug is fixed
240 // Confirmed still broken 15-nov-2013
241 // $this->check( self::$allcategories );
242 $this->check( self
::$backlinks );
243 $this->check( self
::$embeddedin );
244 $this->check( self
::$categorymembers );
250 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
::$generatorAllpages );
293 // generator=allpages & list=allpages
294 $this->check( $this->merge(
295 self
::$generatorAllpages,
298 $this->check( self
::$generatorLinks );
299 // generator=links & prop=links
300 $this->check( $this->merge(
301 self
::$generatorLinks,
302 self
::$generatorLinksPropLinks ) );
303 // generator=links & prop=templates
304 $this->check( $this->merge(
305 self
::$generatorLinks,
306 self
::$generatorLinksPropTemplates ) );
307 // generator=links & prop=links|templates
308 $this->check( $this->merge(
309 self
::$generatorLinks,
310 self
::$generatorLinksPropLinks,
311 self
::$generatorLinksPropTemplates ) );
312 // generator=links & prop=links|templates & list=allpages|...
313 $this->check( $this->merge(
314 self
::$generatorLinks,
315 self
::$generatorLinksPropLinks,
316 self
::$generatorLinksPropTemplates,
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',