9ba4587b5d0461578ee2ad6fd219128802eee6a3
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 = [
63 [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
68 'title' => 'AQBT-All',
70 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
76 private static $templates = [
77 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
82 'title' => 'AQBT-All',
84 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
90 private static $categories = [
91 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
96 'title' => 'AQBT-All',
98 [ 'ns' => 14, 'title' => 'Category:AQBT-Cat' ],
104 private static $allpages = [
105 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
107 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
108 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
109 [ 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ],
110 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
114 private static $alllinks = [
115 [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
117 [ 'ns' => 0, 'title' => 'AQBT-All' ],
118 [ 'ns' => 0, 'title' => 'AQBT-Categories' ],
119 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
120 [ 'ns' => 0, 'title' => 'AQBT-Templates' ],
124 private static $alltransclusions = [
125 [ 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ],
126 [ 'alltransclusions' => [
127 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
128 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
132 // Although this appears to have no use it is used by testLists()
133 private static $allcategories = [
134 [ 'list' => 'allcategories', 'acprefix' => 'AQBT-' ],
135 [ 'allcategories' => [
136 [ '*' => 'AQBT-Cat' ],
140 private static $backlinks = [
141 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
143 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
147 private static $embeddedin = [
148 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
150 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
151 [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
155 private static $categorymembers = [
156 [ 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ],
157 [ 'categorymembers' => [
158 [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
159 [ 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ],
163 private static $generatorAllpages = [
164 [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
169 'title' => 'AQBT-All' ],
173 'title' => 'AQBT-Categories' ],
177 'title' => 'AQBT-Links' ],
181 'title' => 'AQBT-Templates' ],
185 private static $generatorLinks = [
186 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
191 'title' => 'AQBT-All' ],
195 'title' => 'AQBT-Categories' ],
199 'title' => 'AQBT-Templates' ],
203 private static $generatorLinksPropLinks = [
204 [ 'prop' => 'links' ],
206 '1' => [ 'links' => [
207 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
212 private static $generatorLinksPropTemplates = [
213 [ 'prop' => 'templates' ],
215 '1' => [ 'templates' => [
216 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
217 '4' => [ 'templates' => [
218 [ '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 [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
337 'from' => 'AQBT-Redir',
338 'to' => 'AQBT-Target',
345 'title' => 'AQBT-Target',