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 [ 'category' => '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->check( self
::$allcategories );
237 $this->check( self
::$backlinks );
238 $this->check( self
::$embeddedin );
239 $this->check( self
::$categorymembers );
245 public function testAllTogether() {
246 // All props together
247 $this->check( $this->merge(
253 // All lists together
254 $this->check( $this->merge(
257 self
::$alltransclusions,
258 // This test is temporarily disabled until a sqlite bug is fixed
259 // self::$allcategories,
262 self
::$categorymembers
265 // All props+lists together
266 $this->check( $this->merge(
272 self
::$alltransclusions,
273 // This test is temporarily disabled until a sqlite bug is fixed
274 // self::$allcategories,
277 self
::$categorymembers
284 public function testGenerator() {
285 // generator=allpages
286 $this->check( self
::$generatorAllpages );
287 // generator=allpages & list=allpages
288 $this->check( $this->merge(
289 self
::$generatorAllpages,
292 $this->check( self
::$generatorLinks );
293 // generator=links & prop=links
294 $this->check( $this->merge(
295 self
::$generatorLinks,
296 self
::$generatorLinksPropLinks ) );
297 // generator=links & prop=templates
298 $this->check( $this->merge(
299 self
::$generatorLinks,
300 self
::$generatorLinksPropTemplates ) );
301 // generator=links & prop=links|templates
302 $this->check( $this->merge(
303 self
::$generatorLinks,
304 self
::$generatorLinksPropLinks,
305 self
::$generatorLinksPropTemplates ) );
306 // generator=links & prop=links|templates & list=allpages|...
307 $this->check( $this->merge(
308 self
::$generatorLinks,
309 self
::$generatorLinksPropLinks,
310 self
::$generatorLinksPropTemplates,
313 self
::$alltransclusions,
314 // This test is temporarily disabled until a sqlite bug is fixed
315 // self::$allcategories,
318 self
::$categorymembers ) );
324 public function testGeneratorRedirects() {
325 $this->editPage( 'AQBT-Target', 'test' );
326 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
328 [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
332 'from' => 'AQBT-Redir',
333 'to' => 'AQBT-Target',
340 'title' => 'AQBT-Target',