MediaWiki  1.32.5
ApiQueryBasicTest.php
Go to the documentation of this file.
1 <?php
33 
39  function addDBDataOnce() {
40  try {
41  if ( Title::newFromText( 'AQBT-All' )->exists() ) {
42  return;
43  }
44 
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 );
51 
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;
57  }
58  }
59 
60  private static $links = [
61  [ 'prop' => 'links', 'titles' => 'AQBT-All' ],
62  [ 'pages' => [
63  '1' => [
64  'pageid' => 1,
65  'ns' => 0,
66  'title' => 'AQBT-All',
67  'links' => [
68  [ 'ns' => 0, 'title' => 'AQBT-Links' ],
69  ]
70  ]
71  ] ]
72  ];
73 
74  private static $templates = [
75  [ 'prop' => 'templates', 'titles' => 'AQBT-All' ],
76  [ 'pages' => [
77  '1' => [
78  'pageid' => 1,
79  'ns' => 0,
80  'title' => 'AQBT-All',
81  'templates' => [
82  [ 'ns' => 10, 'title' => 'Template:AQBT-T' ],
83  ]
84  ]
85  ] ]
86  ];
87 
88  private static $categories = [
89  [ 'prop' => 'categories', 'titles' => 'AQBT-All' ],
90  [ 'pages' => [
91  '1' => [
92  'pageid' => 1,
93  'ns' => 0,
94  'title' => 'AQBT-All',
95  'categories' => [
96  [ 'ns' => 14, 'title' => 'Category:AQBT-Cat' ],
97  ]
98  ]
99  ] ]
100  ];
101 
102  private static $allpages = [
103  [ 'list' => 'allpages', 'apprefix' => 'AQBT-' ],
104  [ 'allpages' => [
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' ],
109  ] ]
110  ];
111 
112  private static $alllinks = [
113  [ 'list' => 'alllinks', 'alprefix' => 'AQBT-' ],
114  [ 'alllinks' => [
115  [ 'ns' => 0, 'title' => 'AQBT-All' ],
116  [ 'ns' => 0, 'title' => 'AQBT-Categories' ],
117  [ 'ns' => 0, 'title' => 'AQBT-Links' ],
118  [ 'ns' => 0, 'title' => 'AQBT-Templates' ],
119  ] ]
120  ];
121 
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' ],
127  ] ]
128  ];
129 
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' ],
135  ] ]
136  ];
137 
138  private static $backlinks = [
139  [ 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ],
140  [ 'backlinks' => [
141  [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
142  ] ]
143  ];
144 
145  private static $embeddedin = [
146  [ 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ],
147  [ 'embeddedin' => [
148  [ 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ],
149  [ 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ],
150  ] ]
151  ];
152 
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' ],
158  ] ]
159  ];
160 
161  private static $generatorAllpages = [
162  [ 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ],
163  [ 'pages' => [
164  '1' => [
165  'pageid' => 1,
166  'ns' => 0,
167  'title' => 'AQBT-All' ],
168  '2' => [
169  'pageid' => 2,
170  'ns' => 0,
171  'title' => 'AQBT-Categories' ],
172  '3' => [
173  'pageid' => 3,
174  'ns' => 0,
175  'title' => 'AQBT-Links' ],
176  '4' => [
177  'pageid' => 4,
178  'ns' => 0,
179  'title' => 'AQBT-Templates' ],
180  ] ]
181  ];
182 
183  private static $generatorLinks = [
184  [ 'generator' => 'links', 'titles' => 'AQBT-Links' ],
185  [ 'pages' => [
186  '1' => [
187  'pageid' => 1,
188  'ns' => 0,
189  'title' => 'AQBT-All' ],
190  '2' => [
191  'pageid' => 2,
192  'ns' => 0,
193  'title' => 'AQBT-Categories' ],
194  '4' => [
195  'pageid' => 4,
196  'ns' => 0,
197  'title' => 'AQBT-Templates' ],
198  ] ]
199  ];
200 
201  private static $generatorLinksPropLinks = [
202  [ 'prop' => 'links' ],
203  [ 'pages' => [
204  '1' => [ 'links' => [
205  [ 'ns' => 0, 'title' => 'AQBT-Links' ],
206  ] ]
207  ] ]
208  ];
209 
210  private static $generatorLinksPropTemplates = [
211  [ 'prop' => 'templates' ],
212  [ 'pages' => [
213  '1' => [ 'templates' => [
214  [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
215  '4' => [ 'templates' => [
216  [ 'ns' => 10, 'title' => 'Template:AQBT-T' ] ] ],
217  ] ]
218  ];
219 
223  public function testProps() {
224  $this->check( self::$links );
225  $this->check( self::$templates );
226  $this->check( self::$categories );
227  }
228 
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 );
240  }
241 
245  public function testAllTogether() {
246  // All props together
247  $this->check( $this->merge(
248  self::$links,
249  self::$templates,
250  self::$categories
251  ) );
252 
253  // All lists together
254  $this->check( $this->merge(
255  self::$allpages,
256  self::$alllinks,
257  self::$alltransclusions,
258  // This test is temporarily disabled until a sqlite bug is fixed
259  // self::$allcategories,
260  self::$backlinks,
261  self::$embeddedin,
262  self::$categorymembers
263  ) );
264 
265  // All props+lists together
266  $this->check( $this->merge(
267  self::$links,
268  self::$templates,
269  self::$categories,
270  self::$allpages,
271  self::$alllinks,
272  self::$alltransclusions,
273  // This test is temporarily disabled until a sqlite bug is fixed
274  // self::$allcategories,
275  self::$backlinks,
276  self::$embeddedin,
277  self::$categorymembers
278  ) );
279  }
280 
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,
290  self::$allpages ) );
291  // generator=links
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,
311  self::$allpages,
312  self::$alllinks,
313  self::$alltransclusions,
314  // This test is temporarily disabled until a sqlite bug is fixed
315  // self::$allcategories,
316  self::$backlinks,
317  self::$embeddedin,
318  self::$categorymembers ) );
319  }
320 
324  public function testGeneratorRedirects() {
325  $this->editPage( 'AQBT-Target', 'test' );
326  $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
327  $this->check( [
328  [ 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ],
329  [
330  'redirects' => [
331  [
332  'from' => 'AQBT-Redir',
333  'to' => 'AQBT-Target',
334  ]
335  ],
336  'pages' => [
337  '6' => [
338  'pageid' => 6,
339  'ns' => 0,
340  'title' => 'AQBT-Target',
341  ]
342  ],
343  ]
344  ] );
345  }
346 }
ApiQueryBasicTest\$alllinks
static $alllinks
Definition: ApiQueryBasicTest.php:112
ApiQueryBasicTest\$generatorLinksPropLinks
static $generatorLinksPropLinks
Definition: ApiQueryBasicTest.php:201
ApiQueryBasicTest\testGenerator
testGenerator()
Test basic lists.
Definition: ApiQueryBasicTest.php:284
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:280
ApiQueryBasicTest\$generatorLinksPropTemplates
static $generatorLinksPropTemplates
Definition: ApiQueryBasicTest.php:210
ApiQueryBasicTest\testGeneratorRedirects
testGeneratorRedirects()
Test T53821.
Definition: ApiQueryBasicTest.php:324
ApiQueryBasicTest\$categories
static $categories
Definition: ApiQueryBasicTest.php:88
ApiQueryTestBase\check
check( $values, array $session=null, $appendModule=false, User $user=null)
Checks that the request's result matches the expected results.
Definition: ApiQueryTestBase.php:94
ApiQueryTestBase\merge
merge()
Merges all requests parameter + expected values into one.
Definition: ApiQueryTestBase.php:38
ApiQueryBasicTest\$allpages
static $allpages
Definition: ApiQueryBasicTest.php:102
NS_TEMPLATE
const NS_TEMPLATE
Definition: Defines.php:74
ApiQueryBasicTest\addDBDataOnce
addDBDataOnce()
Definition: ApiQueryBasicTest.php:39
ApiQueryBasicTest\$categorymembers
static $categorymembers
Definition: ApiQueryBasicTest.php:153
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ApiQueryBasicTest\$allcategories
static $allcategories
Definition: ApiQueryBasicTest.php:131
ApiQueryBasicTest\testAllTogether
testAllTogether()
Test basic lists.
Definition: ApiQueryBasicTest.php:245
ApiQueryBasicTest\$exceptionFromAddDBData
$exceptionFromAddDBData
Definition: ApiQueryBasicTest.php:32
ApiQueryBasicTest\$generatorLinks
static $generatorLinks
Definition: ApiQueryBasicTest.php:183
ApiQueryBasicTest\$backlinks
static $backlinks
Definition: ApiQueryBasicTest.php:138
MediaWikiTestCase\editPage
editPage( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
Definition: MediaWikiTestCase.php:2333
ApiQueryBasicTest\testProps
testProps()
Test basic props.
Definition: ApiQueryBasicTest.php:223
ApiQueryBasicTest\$links
static $links
Definition: ApiQueryBasicTest.php:60
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2221
ApiQueryTestBase
This class has some common functionality for testing query module.
Definition: ApiQueryTestBase.php:25
ApiQueryBasicTest\$embeddedin
static $embeddedin
Definition: ApiQueryBasicTest.php:145
ApiQueryBasicTest\$templates
static $templates
Definition: ApiQueryBasicTest.php:74
ApiQueryBasicTest\testLists
testLists()
Test basic lists.
Definition: ApiQueryBasicTest.php:232
ApiQueryBasicTest\$alltransclusions
static $alltransclusions
Definition: ApiQueryBasicTest.php:122
ApiQueryBasicTest\$generatorAllpages
static $generatorAllpages
Definition: ApiQueryBasicTest.php:161
ApiQueryBasicTest
These tests validate basic functionality of the api query module.
Definition: ApiQueryBasicTest.php:31