Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryBasicTest.php
blobe486c4f4bc1404da8eb40d11b277624c50c79485
1 <?php
2 /**
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
23 * @file
26 require_once 'ApiQueryTestBase.php';
28 /**
29 * These tests validate basic functionality of the api query module
31 * @group API
32 * @group Database
33 * @group medium
34 * @covers ApiQuery
36 class ApiQueryBasicTest extends ApiQueryTestBase {
37 protected $exceptionFromAddDBData;
39 /**
40 * Create a set of pages. These must not change, otherwise the tests might give wrong results.
41 * @see MediaWikiTestCase::addDBData()
43 function addDBData() {
44 try {
45 if ( Title::newFromText( 'AQBT-All' )->exists() ) {
46 return;
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(
67 '1' => array(
68 'pageid' => 1,
69 'ns' => 0,
70 'title' => 'AQBT-All',
71 'links' => array(
72 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
75 ) )
78 private static $templates = array(
79 array( 'prop' => 'templates', 'titles' => 'AQBT-All' ),
80 array( 'pages' => array(
81 '1' => array(
82 'pageid' => 1,
83 'ns' => 0,
84 'title' => 'AQBT-All',
85 'templates' => array(
86 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
89 ) )
92 private static $categories = array(
93 array( 'prop' => 'categories', 'titles' => 'AQBT-All' ),
94 array( 'pages' => array(
95 '1' => array(
96 'pageid' => 1,
97 'ns' => 0,
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(
168 '1' => array(
169 'pageid' => 1,
170 'ns' => 0,
171 'title' => 'AQBT-All' ),
172 '2' => array(
173 'pageid' => 2,
174 'ns' => 0,
175 'title' => 'AQBT-Categories' ),
176 '3' => array(
177 'pageid' => 3,
178 'ns' => 0,
179 'title' => 'AQBT-Links' ),
180 '4' => array(
181 'pageid' => 4,
182 'ns' => 0,
183 'title' => 'AQBT-Templates' ),
187 private static $generatorLinks = array(
188 array( 'generator' => 'links', 'titles' => 'AQBT-Links' ),
189 array( 'pages' => array(
190 '1' => array(
191 'pageid' => 1,
192 'ns' => 0,
193 'title' => 'AQBT-All' ),
194 '2' => array(
195 'pageid' => 2,
196 'ns' => 0,
197 'title' => 'AQBT-Categories' ),
198 '4' => array(
199 'pageid' => 4,
200 'ns' => 0,
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' ) ) ),
225 * Test basic props
227 public function testProps() {
228 $this->check( self::$links );
229 $this->check( self::$templates );
230 $this->check( self::$categories );
234 * Test basic lists
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 );
249 * Test basic lists
251 public function testAllTogether() {
253 // All props together
254 $this->check( $this->merge(
255 self::$links,
256 self::$templates,
257 self::$categories
258 ) );
260 // All lists together
261 $this->check( $this->merge(
262 self::$allpages,
263 self::$alllinks,
264 self::$alltransclusions,
265 // This test is temporarily disabled until a sqlite bug is fixed
266 // self::$allcategories,
267 self::$backlinks,
268 self::$embeddedin,
269 self::$categorymembers
270 ) );
272 // All props+lists together
273 $this->check( $this->merge(
274 self::$links,
275 self::$templates,
276 self::$categories,
277 self::$allpages,
278 self::$alllinks,
279 self::$alltransclusions,
280 // This test is temporarily disabled until a sqlite bug is fixed
281 // self::$allcategories,
282 self::$backlinks,
283 self::$embeddedin,
284 self::$categorymembers
285 ) );
289 * Test basic lists
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,
297 self::$allpages ) );
298 // generator=links
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,
318 self::$allpages,
319 self::$alllinks,
320 self::$alltransclusions,
321 // This test is temporarily disabled until a sqlite bug is fixed
322 // self::$allcategories,
323 self::$backlinks,
324 self::$embeddedin,
325 self::$categorymembers ) );
329 * Test bug 51821
331 public function testGeneratorRedirects() {
332 $this->editPage( 'AQBT-Target', 'test' );
333 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
334 $this->check( array(
335 array( 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ),
336 array(
337 'redirects' => array(
338 array(
339 'from' => 'AQBT-Redir',
340 'to' => 'AQBT-Target',
343 'pages' => array(
344 '6' => array(
345 'pageid' => 6,
346 'ns' => 0,
347 'title' => 'AQBT-Target',
351 ) );