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:
Antoine Musso 2017-01-23 11:58:52 +01:00
parent c384bfd8f9
commit 8e09acc804
2 changed files with 31 additions and 5 deletions

View file

@ -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;
}
/**

View file

@ -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
*/