wiki.techinc.nl/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php
Thiemo Kreuz 9314453c93 Make use of the list() feature where it makes sense
This code is functionally identical, but less error prone (not so easy
to forget or mix these numerical indexes).

This patch happens to touch the Parser, which might be a bit scary. We
can remove this file from this patch if you prefer.

Change-Id: I8cbe3a9a6725d1c42b86e67678c1af15fbc5961a
2019-03-24 20:12:23 +00:00

82 lines
2 KiB
PHP

<?php
/**
* Test class to run the query of most of all our special pages
*
* Copyright © 2011, Antoine Musso
*
* @author Antoine Musso
*/
use MediaWiki\MediaWikiServices;
/**
* @group Database
* @covers QueryPage<extended>
*/
class QueryAllSpecialPagesTest extends MediaWikiTestCase {
/**
* @var SpecialPage[]
*/
private $queryPages;
/** List query pages that can not be tested automatically */
protected $manualTest = [
LinkSearchPage::class
];
/**
* Pages whose query use the same DB table more than once.
* This is used to skip testing those pages when run against a MySQL backend
* which does not support reopening a temporary table. See upstream bug:
* https://bugs.mysql.com/bug.php?id=10327
*/
protected $reopensTempTable = [
BrokenRedirects::class,
];
/**
* Initialize all query page objects
*/
function __construct() {
parent::__construct();
foreach ( QueryPage::getPages() as $page ) {
list( $class, $name ) = $page;
if ( !in_array( $class, $this->manualTest ) ) {
$this->queryPages[$class] =
MediaWikiServices::getInstance()->getSpecialPageFactory()->getPage( $name );
}
}
}
/**
* Test SQL for each of our QueryPages objects
* @group Database
*/
public function testQuerypageSqlQuery() {
global $wgDBtype;
foreach ( $this->queryPages as $page ) {
// With MySQL, skips special pages reopening a temporary table
// See https://bugs.mysql.com/bug.php?id=10327
if (
$wgDBtype === 'mysql'
&& in_array( $page->getName(), $this->reopensTempTable )
) {
$this->markTestSkipped( "SQL query for page {$page->getName()} "
. "can not be tested on MySQL backend (it reopens a temporary table)" );
continue;
}
$msg = "SQL query for page {$page->getName()} should give a result wrapper object";
$result = $page->reallyDoQuery( 50 );
if ( $result instanceof ResultWrapper ) {
$this->assertTrue( true, $msg );
} else {
$this->assertFalse( false, $msg );
}
}
}
}