MediaWiki  1.23.0
ApiQueryBasicTest.php
Go to the documentation of this file.
1 <?php
26 require_once 'ApiQueryTestBase.php';
27 
38 
43  function addDBData() {
44  try {
45  if ( Title::newFromText( 'AQBT-All' )->exists() ) {
46  return;
47  }
48 
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 );
55 
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;
61  }
62  }
63 
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' ),
73  )
74  )
75  ) )
76  );
77 
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' ),
87  )
88  )
89  ) )
90  );
91 
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' ),
101  )
102  )
103  ) )
104  );
105 
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' ),
113  ) )
114  );
115 
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' ),
123  ) )
124  );
125 
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' ),
131  ) )
132  );
133 
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' ),
139  ) )
140  );
141 
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' ),
146  ) )
147  );
148 
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' ),
154  ) )
155  );
156 
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' ),
162  ) )
163  );
164 
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' ),
184  ) )
185  );
186 
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' ),
202  ) )
203  );
204 
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' ),
210  ) )
211  ) )
212  );
213 
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' ) ) ),
221  ) )
222  );
223 
227  public function testProps() {
228  $this->check( self::$links );
229  $this->check( self::$templates );
230  $this->check( self::$categories );
231  }
232 
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 );
246  }
247 
251  public function testAllTogether() {
252 
253  // All props together
254  $this->check( $this->merge(
255  self::$links,
256  self::$templates,
257  self::$categories
258  ) );
259 
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  ) );
271 
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  ) );
286  }
287 
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 ) );
326  }
327 
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',
341  )
342  ),
343  'pages' => array(
344  '6' => array(
345  'pageid' => 6,
346  'ns' => 0,
347  'title' => 'AQBT-Target',
348  )
349  ),
350  )
351  ) );
352  }
353 }
ApiQueryBasicTest\$alllinks
static $alllinks
Definition: ApiQueryBasicTest.php:116
ApiQueryBasicTest\$generatorLinksPropLinks
static $generatorLinksPropLinks
Definition: ApiQueryBasicTest.php:205
ApiQueryBasicTest\testGenerator
testGenerator()
Test basic lists.
Definition: ApiQueryBasicTest.php:291
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiQueryBasicTest\$generatorLinksPropTemplates
static $generatorLinksPropTemplates
Definition: ApiQueryBasicTest.php:214
ApiQueryBasicTest\testGeneratorRedirects
testGeneratorRedirects()
Test bug 51821.
Definition: ApiQueryBasicTest.php:331
ApiQueryBasicTest\$categories
static $categories
Definition: ApiQueryBasicTest.php:92
ApiQueryTestBase\merge
merge()
Merges all requests parameter + expected values into one.
Definition: ApiQueryTestBase.php:40
ApiQueryBasicTest\$allpages
static $allpages
Definition: ApiQueryBasicTest.php:106
NS_TEMPLATE
const NS_TEMPLATE
Definition: Defines.php:89
ApiQueryBasicTest\$categorymembers
static $categorymembers
Definition: ApiQueryBasicTest.php:157
ApiQueryBasicTest\addDBData
addDBData()
Create a set of pages.
Definition: ApiQueryBasicTest.php:43
ApiQueryBasicTest\$allcategories
static $allcategories
Definition: ApiQueryBasicTest.php:135
ApiQueryBasicTest\testAllTogether
testAllTogether()
Test basic lists.
Definition: ApiQueryBasicTest.php:251
ApiQueryTestBase\check
check( $values)
Checks that the request's result matches the expected results.
Definition: ApiQueryTestBase.php:89
ApiQueryBasicTest\$exceptionFromAddDBData
$exceptionFromAddDBData
Definition: ApiQueryBasicTest.php:37
ApiQueryBasicTest\$generatorLinks
static $generatorLinks
Definition: ApiQueryBasicTest.php:187
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiQueryBasicTest\$backlinks
static $backlinks
Definition: ApiQueryBasicTest.php:142
ApiQueryBasicTest\testProps
testProps()
Test basic props.
Definition: ApiQueryBasicTest.php:227
ApiQueryBasicTest\$links
static $links
Definition: ApiQueryBasicTest.php:64
ApiTestCase\editPage
editPage( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
Definition: ApiTestCase.php:51
ApiQueryTestBase
This class has some common functionality for testing query module.
Definition: ApiQueryTestBase.php:27
ApiQueryBasicTest\$embeddedin
static $embeddedin
Definition: ApiQueryBasicTest.php:149
ApiQueryBasicTest\$templates
static $templates
Definition: ApiQueryBasicTest.php:78
ApiQueryBasicTest\testLists
testLists()
Test basic lists.
Definition: ApiQueryBasicTest.php:236
$e
if( $useReadline) $e
Definition: eval.php:66
ApiQueryBasicTest\$alltransclusions
static $alltransclusions
Definition: ApiQueryBasicTest.php:126
ApiQueryBasicTest\$generatorAllpages
static $generatorAllpages
Definition: ApiQueryBasicTest.php:165
ApiQueryBasicTest
These tests validate basic functionality of the api query module.
Definition: ApiQueryBasicTest.php:36