mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist
synced 2024-11-23 21:53:40 +00:00
TitleBlacklistTest singleton can now be destroyed
The test suite set $wgTitleBlacklistSources with a fixture source of directories. Unfortunately when running tests from MediaWiki core the TitleBlacklist has already been set with empty value and thus setting the global is a noop. That later causes a test to fail because the blacklist is emtpy. Add TitleBlacklistTest::destroySingleton() so a test can reset the singleton when changing $wgTitleBlacklistSources. Since that is solely for testing, throw an exception unless we had MW_PHPUNIT_TEST defined. Bug: T155980 Change-Id: I99c3185811ed7b2225953fa6960096985e97c4d2
This commit is contained in:
parent
c384bfd8f9
commit
8e09acc804
|
@ -17,6 +17,10 @@
|
|||
*/
|
||||
class TitleBlacklist {
|
||||
private $mBlacklist = null, $mWhitelist = null;
|
||||
|
||||
/** @var TitleBlacklist */
|
||||
protected static $instance = null;
|
||||
|
||||
const VERSION = 3; // Blacklist format
|
||||
|
||||
/**
|
||||
|
@ -25,12 +29,28 @@ class TitleBlacklist {
|
|||
* @return TitleBlacklist
|
||||
*/
|
||||
public static function singleton() {
|
||||
static $instance = null;
|
||||
|
||||
if ( $instance === null ) {
|
||||
$instance = new self;
|
||||
if ( self::$instance === null ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
return $instance;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy/reset the current singleton instance.
|
||||
*
|
||||
* This is solely for testing and will fail unless MW_PHPUNIT_TEST is
|
||||
* defined.
|
||||
*/
|
||||
public static function destroySingleton() {
|
||||
|
||||
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
|
||||
throw new MWException(
|
||||
'Can not invoke ' . __METHOD__ . '() ' .
|
||||
'out of tests (MW_PHPUNIT_TEST not set).'
|
||||
);
|
||||
}
|
||||
|
||||
self::$instance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|||
parent::setUp();
|
||||
$this->doLogin();
|
||||
|
||||
TitleBlacklist::destroySingleton();
|
||||
$this->setMwGlobals( 'wgTitleBlacklistSources', array(
|
||||
array(
|
||||
'type' => 'file',
|
||||
|
@ -30,6 +31,11 @@ class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|||
) );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
TitleBlacklist::destroySingleton();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify we allow a title which is not blacklisted
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue