Debian Codegraph @

tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Test class to run the query of most of all our special pages
4 *
5 * Copyright © 2011, Antoine Musso
6 *
7 * @author Antoine Musso
8 */
9
10 use MediaWiki\SpecialPage\QueryPage;
11 use MediaWiki\SpecialPage\SpecialPage;
12 use MediaWiki\Specials\SpecialLinkSearch;
13 use Wikimedia\Rdbms\ResultWrapper;
14
15 /**
16 * @group Database
17 * @covers \MediaWiki\SpecialPage\QueryPage<extended>
18 */
19 class QueryAllSpecialPagesTest extends MediaWikiIntegrationTestCase {
20
21 /**
22 * @var SpecialPage[]
23 */
24 private $queryPages;
25
26 /** @var string[] List query pages that cannot be tested automatically */
27 protected $manualTest = [
28 SpecialLinkSearch::class
29 ];
30
31 /**
32 * @var string[] Names of pages whose query use the same DB table more than once.
33 * This is used to skip testing those pages when run against a MySQL backend
34 * which does not support reopening a temporary table.
35 * For more info, see https://phabricator.wikimedia.org/T256006
36 */
37 protected $reopensTempTable = [
38 'BrokenRedirects',
39 ];
40
41 /**
42 * Initialize all query page objects
43 */
44 protected function setUp(): void {
45 parent::setUp();
46
47 foreach ( QueryPage::getPages() as [ $class, $name ] ) {
48 if ( !in_array( $class, $this->manualTest ) ) {
49 $this->queryPages[$class] =
50 $this->getServiceContainer()->getSpecialPageFactory()->getPage( $name );
51 }
52 }
53 }
54
55 /**
56 * Test SQL for each of our QueryPages objects
57 */
58 public function testQuerypageSqlQuery() {
59 foreach ( $this->queryPages as $page ) {
60 // With MySQL, skips special pages reopening a temporary table
61 // See https://bugs.mysql.com/bug.php?id=10327
62 if (
63 $this->getDb()->getType() === 'mysql' &&
64 str_contains( $this->getDb()->getSoftwareLink(), 'MySQL' ) &&
65 in_array( $page->getName(), $this->reopensTempTable )
66 ) {
67 $this->markTestSkipped( "SQL query for page {$page->getName()} "
68 . "cannot be tested on MySQL backend (it reopens a temporary table)" );
69 continue;
70 }
71
72 $msg = "SQL query for page {$page->getName()} should give a result wrapper object";
73
74 $result = $page->reallyDoQuery( 50 );
75 $this->assertInstanceOf( ResultWrapper::class, $result, $msg );
76 }
77 }
78 }