Merge "Allow partially blocked users to tag unrelated revisions"
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / QueryAllSpecialPagesTest.php
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\MediaWikiServices;
11
12 /**
13 * @group Database
14 * @covers QueryPage<extended>
15 */
16 class QueryAllSpecialPagesTest extends MediaWikiTestCase {
17
18 /**
19 * @var SpecialPage[]
20 */
21 private $queryPages;
22
23 /** List query pages that can not be tested automatically */
24 protected $manualTest = [
25 SpecialLinkSearch::class
26 ];
27
28 /**
29 * Pages whose query use the same DB table more than once.
30 * This is used to skip testing those pages when run against a MySQL backend
31 * which does not support reopening a temporary table. See upstream bug:
32 * https://bugs.mysql.com/bug.php?id=10327
33 */
34 protected $reopensTempTable = [
35 BrokenRedirects::class,
36 ];
37
38 /**
39 * Initialize all query page objects
40 */
41 function __construct() {
42 parent::__construct();
43
44 foreach ( QueryPage::getPages() as $page ) {
45 list( $class, $name ) = $page;
46 if ( !in_array( $class, $this->manualTest ) ) {
47 $this->queryPages[$class] =
48 MediaWikiServices::getInstance()->getSpecialPageFactory()->getPage( $name );
49 }
50 }
51 }
52
53 /**
54 * Test SQL for each of our QueryPages objects
55 * @group Database
56 */
57 public function testQuerypageSqlQuery() {
58 global $wgDBtype;
59
60 foreach ( $this->queryPages as $page ) {
61 // With MySQL, skips special pages reopening a temporary table
62 // See https://bugs.mysql.com/bug.php?id=10327
63 if (
64 $wgDBtype === 'mysql'
65 && in_array( $page->getName(), $this->reopensTempTable )
66 ) {
67 $this->markTestSkipped( "SQL query for page {$page->getName()} "
68 . "can not 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 if ( $result instanceof ResultWrapper ) {
76 $this->assertTrue( true, $msg );
77 } else {
78 $this->assertFalse( false, $msg );
79 }
80 }
81 }
82 }