]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - tests/phpunit/includes/api/query/ApiQueryBasicTest.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryBasicTest.php
1 <?php
2 /**
3  *
4  * Created on Feb 6, 2013
5  *
6  * Copyright © 2013 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
7  *
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.
12  *
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.
17  *
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
22  *
23  * @file
24  */
25
26 /**
27  * These tests validate basic functionality of the api query module
28  *
29  * @group API
30  * @group Database
31  * @group medium
32  * @covers ApiQuery
33  */
34 class ApiQueryBasicTest extends ApiQueryTestBase {
35         protected $exceptionFromAddDBData;
36
37         /**
38          * Create a set of pages. These must not change, otherwise the tests might give wrong results.
39          *
40 *@see MediaWikiTestCase::addDBDataOnce()
41          */
42         function addDBDataOnce() {
43                 try {
44                         if ( Title::newFromText( 'AQBT-All' )->exists() ) {
45                                 return;
46                         }
47
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 );
54
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;
60                 }
61         }
62
63         private static $links = [
64                 [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
65                 [ 'pages' => [
66                         '1' => [
67                                 'pageid' => 1,
68                                 'ns' => 0,
69                                 'title' => 'AQBT-All',
70                                 'links' => [
71                                         [ 'ns' => 0, 'title' => 'AQBT-Links' ],
72                                 ]
73                         ]
74                 ] ]
75         ];
76
77         private static $templates = [
78                 [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
79                 [ 'pages' => [
80                         '1' => [
81                                 'pageid' => 1,
82                                 'ns' => 0,
83                                 'title' => 'AQBT-All',
84                                 'templates' => [
85                                         [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
86                                 ]
87                         ]
88                 ] ]
89         ];
90
91         private static $categories = [
92                 [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
93                 [ 'pages' => [
94                         '1' => [
95                                 'pageid' => 1,
96                                 'ns' => 0,
97                                 'title' => 'AQBT-All',
98                                 'categories' => [
99                                         [ 'ns' => 14, 'title' => 'Category:AQBT-Cat' ],
100                                 ]
101                         ]
102                 ] ]
103         ];
104
105         private static $allpages = [
106                 [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
107                 [ 'allpages' => [
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' ],
112                 ] ]
113         ];
114
115         private static $alllinks = [
116                 [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
117                 [ 'alllinks' => [
118                         [ 'ns' => 0, 'title' => 'AQBT-All' ],
119                         [ 'ns' => 0, 'title' => 'AQBT-Categories' ],
120                         [ 'ns' => 0, 'title' => 'AQBT-Links' ],
121                         [ 'ns' => 0, 'title' => 'AQBT-Templates' ],
122                 ] ]
123         ];
124
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' ],
130                 ] ]
131         ];
132
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' ],
138                 ] ]
139         ];
140
141         private static $backlinks = [
142                 [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
143                 [ 'backlinks' => [
144                         [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
145                 ] ]
146         ];
147
148         private static $embeddedin = [
149                 [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
150                 [ 'embeddedin' => [
151                         [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
152                         [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
153                 ] ]
154         ];
155
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' ],
161                 ] ]
162         ];
163
164         private static $generatorAllpages = [
165                 [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
166                 [ 'pages' => [
167                         '1' => [
168                                 'pageid' => 1,
169                                 'ns' => 0,
170                                 'title' => 'AQBT-All' ],
171                         '2' => [
172                                 'pageid' => 2,
173                                 'ns' => 0,
174                                 'title' => 'AQBT-Categories' ],
175                         '3' => [
176                                 'pageid' => 3,
177                                 'ns' => 0,
178                                 'title' => 'AQBT-Links' ],
179                         '4' => [
180                                 'pageid' => 4,
181                                 'ns' => 0,
182                                 'title' => 'AQBT-Templates' ],
183                 ] ]
184         ];
185
186         private static $generatorLinks = [
187                 [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
188                 [ 'pages' => [
189                         '1' => [
190                                 'pageid' => 1,
191                                 'ns' => 0,
192                                 'title' => 'AQBT-All' ],
193                         '2' => [
194                                 'pageid' => 2,
195                                 'ns' => 0,
196                                 'title' => 'AQBT-Categories' ],
197                         '4' => [
198                                 'pageid' => 4,
199                                 'ns' => 0,
200                                 'title' => 'AQBT-Templates' ],
201                 ] ]
202         ];
203
204         private static $generatorLinksPropLinks = [
205                 [ 'prop' => 'links' ],
206                 [ 'pages' => [
207                         '1' => [ 'links' => [
208                                 [ 'ns' => 0, 'title' => 'AQBT-Links' ],
209                         ] ]
210                 ] ]
211         ];
212
213         private static $generatorLinksPropTemplates = [
214                 [ 'prop' => 'templates' ],
215                 [ 'pages' => [
216                         '1' => [ 'templates' => [
217                                 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
218                         '4' => [ 'templates' => [
219                                 [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
220                 ] ]
221         ];
222
223         /**
224          * Test basic props
225          */
226         public function testProps() {
227                 $this->check( self::$links );
228                 $this->check( self::$templates );
229                 $this->check( self::$categories );
230         }
231
232         /**
233          * Test basic lists
234          */
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 );
245         }
246
247         /**
248          * Test basic lists
249          */
250         public function testAllTogether() {
251                 // All props together
252                 $this->check( $this->merge(
253                         self::$links,
254                         self::$templates,
255                         self::$categories
256                 ) );
257
258                 // All lists together
259                 $this->check( $this->merge(
260                         self::$allpages,
261                         self::$alllinks,
262                         self::$alltransclusions,
263                         // This test is temporarily disabled until a sqlite bug is fixed
264                         // self::$allcategories,
265                         self::$backlinks,
266                         self::$embeddedin,
267                         self::$categorymembers
268                 ) );
269
270                 // All props+lists together
271                 $this->check( $this->merge(
272                         self::$links,
273                         self::$templates,
274                         self::$categories,
275                         self::$allpages,
276                         self::$alllinks,
277                         self::$alltransclusions,
278                         // This test is temporarily disabled until a sqlite bug is fixed
279                         // self::$allcategories,
280                         self::$backlinks,
281                         self::$embeddedin,
282                         self::$categorymembers
283                 ) );
284         }
285
286         /**
287          * Test basic lists
288          */
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,
295                         self::$allpages ) );
296                 // generator=links
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,
316                         self::$allpages,
317                         self::$alllinks,
318                         self::$alltransclusions,
319                         // This test is temporarily disabled until a sqlite bug is fixed
320                         // self::$allcategories,
321                         self::$backlinks,
322                         self::$embeddedin,
323                         self::$categorymembers ) );
324         }
325
326         /**
327          * Test T53821
328          */
329         public function testGeneratorRedirects() {
330                 $this->editPage( 'AQBT-Target', 'test' );
331                 $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
332                 $this->check( [
333                         [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
334                         [
335                                 'redirects' => [
336                                         [
337                                                 'from' => 'AQBT-Redir',
338                                                 'to' => 'AQBT-Target',
339                                         ]
340                                 ],
341                                 'pages' => [
342                                         '6' => [
343                                                 'pageid' => 6,
344                                                 'ns' => 0,
345                                                 'title' => 'AQBT-Target',
346                                         ]
347                                 ],
348                         ]
349                 ] );
350         }
351 }