function setUp() { global $wgHooks; parent::setUp(); Hooks::clear('MediaWikiHooksTest001'); unset($wgHooks['MediaWikiHooksTest001']); }
public function finalSetup() { parent::finalSetup(); global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache; global $wgLanguageConverterCacheType, $wgUseDatabaseMessages; global $wgLocaltimezone, $wgLocalisationCacheConf; global $wgDevelopmentWarnings; // Inject test autoloader require_once __DIR__ . '/../TestsAutoLoader.php'; // wfWarn should cause tests to fail $wgDevelopmentWarnings = true; // Make sure all caches and stashes are either disabled or use // in-process cache only to prevent tests from using any preconfigured // cache meant for the local wiki from outside the test run. // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC. // Disabled in DefaultSettings, override local settings $wgMainWANCache = $wgMainCacheType = CACHE_NONE; // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db $wgMessageCacheType = $wgParserCacheType = $wgSessionCacheType = $wgLanguageConverterCacheType = 'hash'; // Uses db-replicated in DefaultSettings $wgMainStash = 'hash'; $wgUseDatabaseMessages = false; # Set for future resets // Assume UTC for testing purposes $wgLocaltimezone = 'UTC'; $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; // Bug 44192 Do not attempt to send a real e-mail Hooks::clear('AlternateUserMailer'); Hooks::register('AlternateUserMailer', function () { return false; }); // xdebug's default of 100 is too low for MediaWiki ini_set('xdebug.max_nesting_level', 1000); }
public function finalSetup() { parent::finalSetup(); global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache; global $wgLanguageConverterCacheType, $wgUseDatabaseMessages; global $wgLocaltimezone, $wgLocalisationCacheConf; global $wgDevelopmentWarnings; // Inject test autoloader require_once __DIR__ . '/../TestsAutoLoader.php'; // wfWarn should cause tests to fail $wgDevelopmentWarnings = true; $wgMainCacheType = CACHE_NONE; $wgMainWANCache = CACHE_NONE; $wgMessageCacheType = CACHE_NONE; $wgParserCacheType = CACHE_NONE; $wgLanguageConverterCacheType = CACHE_NONE; $wgUseDatabaseMessages = false; # Set for future resets // Assume UTC for testing purposes $wgLocaltimezone = 'UTC'; $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; // Bug 44192 Do not attempt to send a real e-mail Hooks::clear('AlternateUserMailer'); Hooks::register('AlternateUserMailer', function () { return false; }); // xdebug's default of 100 is too low for MediaWiki ini_set('xdebug.max_nesting_level', 1000); }
public function finalSetup() { parent::finalSetup(); global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache; global $wgMainStash; global $wgLanguageConverterCacheType, $wgUseDatabaseMessages; global $wgLocaltimezone, $wgLocalisationCacheConf; global $wgDevelopmentWarnings; global $wgSessionProviders; global $wgJobTypeConf; global $wgAuthManagerConfig, $wgAuth, $wgDisableAuthManager; // Inject test autoloader require_once __DIR__ . '/../TestsAutoLoader.php'; // wfWarn should cause tests to fail $wgDevelopmentWarnings = true; // Make sure all caches and stashes are either disabled or use // in-process cache only to prevent tests from using any preconfigured // cache meant for the local wiki from outside the test run. // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC. // Disabled in DefaultSettings, override local settings $wgMainWANCache = $wgMainCacheType = CACHE_NONE; // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db $wgMessageCacheType = $wgParserCacheType = $wgSessionCacheType = $wgLanguageConverterCacheType = 'hash'; // Uses db-replicated in DefaultSettings $wgMainStash = 'hash'; // Use memory job queue $wgJobTypeConf = ['default' => ['class' => 'JobQueueMemory', 'order' => 'fifo']]; $wgUseDatabaseMessages = false; # Set for future resets // Assume UTC for testing purposes $wgLocaltimezone = 'UTC'; $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; // Generic MediaWiki\Session\SessionManager configuration for tests // We use CookieSessionProvider because things might be expecting // cookies to show up in a FauxRequest somewhere. $wgSessionProviders = [['class' => MediaWiki\Session\CookieSessionProvider::class, 'args' => [['priority' => 30, 'callUserSetCookiesHook' => true]]]]; // Generic AuthManager configuration for testing $wgAuthManagerConfig = ['preauth' => [], 'primaryauth' => [['class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::class, 'args' => [['authoritative' => false]]], ['class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider::class, 'args' => [['authoritative' => true]]]], 'secondaryauth' => []]; $wgAuth = $wgDisableAuthManager ? new AuthPlugin() : new MediaWiki\Auth\AuthManagerAuthPlugin(); // Bug 44192 Do not attempt to send a real e-mail Hooks::clear('AlternateUserMailer'); Hooks::register('AlternateUserMailer', function () { return false; }); // xdebug's default of 100 is too low for MediaWiki ini_set('xdebug.max_nesting_level', 1000); // Bug T116683 serialize_precision of 100 // may break testing against floating point values // treated with PHP's serialize() ini_set('serialize_precision', 17); // TODO: we should call MediaWikiTestCase::prepareServices( new GlobalVarConfig() ) here. // But PHPUnit may not be loaded yet, so we have to wait until just // before PHPUnit_TextUI_Command::main() is executed at the end of this file. }
/** * @since 2.0 * * @return MwHooksHandler */ public function deregisterListedHooks() { $listOfHooks = array_merge($this->listOfSmwHooks, $this->getHookRegistry()->getHandlerList()); foreach ($listOfHooks as $hook) { // MW 1.19 if (method_exists('Hooks', 'clear')) { \Hooks::clear($hook); } if (!isset($GLOBALS['wgHooks'][$hook])) { continue; } $this->wgHooks[$hook] = $GLOBALS['wgHooks'][$hook]; $GLOBALS['wgHooks'][$hook] = array(); } return $this; }
public function finalSetup() { parent::finalSetup(); global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache; global $wgMainStash; global $wgLanguageConverterCacheType, $wgUseDatabaseMessages; global $wgLocaltimezone, $wgLocalisationCacheConf; global $wgDevelopmentWarnings; global $wgSessionProviders; global $wgJobTypeConf; // Inject test autoloader require_once __DIR__ . '/../TestsAutoLoader.php'; // wfWarn should cause tests to fail $wgDevelopmentWarnings = true; // Make sure all caches and stashes are either disabled or use // in-process cache only to prevent tests from using any preconfigured // cache meant for the local wiki from outside the test run. // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC. // Disabled in DefaultSettings, override local settings $wgMainWANCache = $wgMainCacheType = CACHE_NONE; // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db $wgMessageCacheType = $wgParserCacheType = $wgSessionCacheType = $wgLanguageConverterCacheType = 'hash'; // Uses db-replicated in DefaultSettings $wgMainStash = 'hash'; // Use memory job queue $wgJobTypeConf = array('default' => array('class' => 'JobQueueMemory', 'order' => 'fifo')); $wgUseDatabaseMessages = false; # Set for future resets // Assume UTC for testing purposes $wgLocaltimezone = 'UTC'; $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; // Generic MediaWiki\Session\SessionManager configuration for tests // We use CookieSessionProvider because things might be expecting // cookies to show up in a FauxRequest somewhere. $wgSessionProviders = array(array('class' => 'MediaWiki\\Session\\CookieSessionProvider', 'args' => array(array('priority' => 30, 'callUserSetCookiesHook' => true)))); // Bug 44192 Do not attempt to send a real e-mail Hooks::clear('AlternateUserMailer'); Hooks::register('AlternateUserMailer', function () { return false; }); // xdebug's default of 100 is too low for MediaWiki ini_set('xdebug.max_nesting_level', 1000); // Bug T116683 serialize_precision of 100 // may break testing against floating point values // treated with PHP's serialize() ini_set('serialize_precision', 17); }
public function testNewStyleHookInteraction() { global $wgHooks; $a = new NothingClass(); $b = new NothingClass(); // make sure to start with a clean slate Hooks::clear('MediaWikiHooksTest001'); unset($wgHooks['MediaWikiHooksTest001']); $wgHooks['MediaWikiHooksTest001'][] = $a; $this->assertTrue(Hooks::isRegistered('MediaWikiHooksTest001'), 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered'); Hooks::register('MediaWikiHooksTest001', $b); $this->assertEquals(2, count(Hooks::getHandlers('MediaWikiHooksTest001')), 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register'); $foo = 'quux'; $bar = 'qaax'; Hooks::run('MediaWikiHooksTest001', array(&$foo, &$bar)); $this->assertEquals(1, $a->calls, 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'); $this->assertEquals(1, $b->calls, 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'); // clean up Hooks::clear('MediaWikiHooksTest001'); unset($wgHooks['MediaWikiHooksTest001']); }
protected function hookMailer($func = null) { \Hooks::clear('AlternateUserMailer'); if ($func) { \Hooks::register('AlternateUserMailer', $func); // Safety \Hooks::register('AlternateUserMailer', function () { return false; }); } else { \Hooks::register('AlternateUserMailer', function () { $this->fail('AlternateUserMailer hook called unexpectedly'); return false; }); } return new \ScopedCallback(function () { \Hooks::clear('AlternateUserMailer'); \Hooks::register('AlternateUserMailer', function () { return false; }); }); }
public function finalSetup() { parent::finalSetup(); global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType; global $wgLanguageConverterCacheType, $wgUseDatabaseMessages; global $wgLocaltimezone, $wgLocalisationCacheConf; global $wgDevelopmentWarnings; // wfWarn should cause tests to fail $wgDevelopmentWarnings = true; $wgMainCacheType = CACHE_NONE; $wgMessageCacheType = CACHE_NONE; $wgParserCacheType = CACHE_NONE; $wgLanguageConverterCacheType = CACHE_NONE; $wgUseDatabaseMessages = false; # Set for future resets // Assume UTC for testing purposes $wgLocaltimezone = 'UTC'; $wgLocalisationCacheConf['storeClass'] = 'LCStore_Null'; // Bug 44192 Do not attempt to send a real e-mail Hooks::clear('AlternateUserMailer'); Hooks::register('AlternateUserMailer', function () { return false; }); }
/** * Insert hardcoded interwiki in the lookup table. * * This function insert a set of well known interwikis that are used in * the parser tests. They can be considered has fixtures are injected in * the interwiki cache by using the 'InterwikiLoadPrefix' hook. * Since we are not interested in looking up interwikis in the database, * the hook completely replace the existing mechanism (hook returns false). * * @return closure for teardown */ private function setupInterwikis() { # Hack: insert a few Wikipedia in-project interwiki prefixes, # for testing inter-language links Hooks::register('InterwikiLoadPrefix', function ($prefix, &$iwData) { static $testInterwikis = ['local' => ['iw_url' => 'http://doesnt.matter.org/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 0], 'wikipedia' => ['iw_url' => 'http://en.wikipedia.org/wiki/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 0], 'meatball' => ['iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 0], 'memoryalpha' => ['iw_url' => 'http://www.memory-alpha.org/en/index.php/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 0], 'zh' => ['iw_url' => 'http://zh.wikipedia.org/wiki/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 1], 'es' => ['iw_url' => 'http://es.wikipedia.org/wiki/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 1], 'fr' => ['iw_url' => 'http://fr.wikipedia.org/wiki/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 1], 'ru' => ['iw_url' => 'http://ru.wikipedia.org/wiki/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 1], 'mi' => ['iw_url' => 'http://mi.wikipedia.org/wiki/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 1], 'mul' => ['iw_url' => 'http://wikisource.org/wiki/$1', 'iw_api' => '', 'iw_wikiid' => '', 'iw_local' => 1]]; if (array_key_exists($prefix, $testInterwikis)) { $iwData = $testInterwikis[$prefix]; } // We only want to rely on the above fixtures return false; }); // hooks::register return function () { // Tear down Hooks::clear('InterwikiLoadPrefix'); }; }