public function doTestLogFormatter($row, $extra) { RequestContext::resetMain(); $row = $this->expandDatabaseRow($row, $this->isLegacy($extra)); $formatter = LogFormatter::newFromRow($row); $this->assertEquals($extra['text'], self::removeSomeHtml($formatter->getActionText()), 'Action text is equal to expected text'); $this->assertSame($extra['api'], self::removeApiMetaData($formatter->formatParametersForApi()), 'Api log params is equal to expected array'); }
protected function setUp() { global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc; $tmpDir = $this->getNewTempDirectory(); $tmpGlobals = []; $tmpGlobals['wgScript'] = '/index.php'; $tmpGlobals['wgScriptPath'] = '/'; $tmpGlobals['wgArticlePath'] = '/wiki/$1'; $tmpGlobals['wgStylePath'] = '/skins'; $tmpGlobals['wgThumbnailScriptPath'] = false; $tmpGlobals['wgLocalFileRepo'] = ['class' => 'LocalRepo', 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => new FSFileBackend(['name' => 'local-backend', 'wikiId' => wfWikiID(), 'containerPaths' => ['local-public' => "{$tmpDir}/test-repo/public", 'local-thumb' => "{$tmpDir}/test-repo/thumb", 'local-temp' => "{$tmpDir}/test-repo/temp", 'local-deleted' => "{$tmpDir}/test-repo/delete"]])]; foreach ($tmpGlobals as $var => $val) { if (array_key_exists($var, $GLOBALS)) { $this->savedGlobals[$var] = $GLOBALS[$var]; } $GLOBALS[$var] = $val; } $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface'; $wgNamespaceAliases['Image'] = NS_FILE; $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; $wgParserCacheType = CACHE_NONE; DeferredUpdates::clearPendingUpdates(); $wgMemc = wfGetMainCache(); $messageMemc = wfGetMessageCacheStorage(); $parserMemc = wfGetParserCacheStorage(); RequestContext::resetMain(); $context = RequestContext::getMain(); $wgUser = new User(); $wgLang = $context->getLanguage(); $wgOut = $context->getOutput(); $wgParser = new StubObject('wgParser', $wgParserConf['class'], [$wgParserConf]); $wgRequest = $context->getRequest(); if ($wgStyleDirectory === false) { $wgStyleDirectory = "{$IP}/skins"; } RepoGroup::destroySingleton(); FileBackendGroup::destroySingleton(); }
protected function tearDown() { global $wgRequest; $status = ob_get_status(); if (isset($status['name']) && $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier') { ob_end_flush(); } $this->called['tearDown'] = true; // Cleaning up temporary files foreach ($this->tmpFiles as $fileName) { if (is_file($fileName) || is_link($fileName)) { unlink($fileName); } elseif (is_dir($fileName)) { wfRecursiveRemoveDir($fileName); } } if ($this->needsDB() && $this->db) { // Clean up open transactions while ($this->db->trxLevel() > 0) { $this->db->rollback(__METHOD__, 'flush'); } } // Restore mw globals foreach ($this->mwGlobals as $key => $value) { $GLOBALS[$key] = $value; } $this->mwGlobals = array(); RequestContext::resetMain(); MediaHandler::resetCache(); if (session_id() !== '') { session_write_close(); session_id(''); } $wgRequest = new FauxRequest(); MediaWiki\Session\SessionManager::resetCache(); $phpErrorLevel = intval(ini_get('error_reporting')); if ($phpErrorLevel !== $this->phpErrorLevel) { ini_set('error_reporting', $this->phpErrorLevel); $oldHex = strtoupper(dechex($this->phpErrorLevel)); $newHex = strtoupper(dechex($phpErrorLevel)); $message = "PHP error_reporting setting was left dirty: " . "was 0x{$oldHex} before test, 0x{$newHex} after test!"; $this->fail($message); } parent::tearDown(); }
protected function tearDown() { wfProfileIn(__METHOD__); // Cleaning up temporary files foreach ($this->tmpFiles as $fileName) { if (is_file($fileName) || is_link($fileName)) { unlink($fileName); } elseif (is_dir($fileName)) { wfRecursiveRemoveDir($fileName); } } if ($this->needsDB() && $this->db) { // Clean up open transactions while ($this->db->trxLevel() > 0) { $this->db->rollback(); } // don't ignore DB errors $this->db->ignoreErrors(false); } // Restore mw globals foreach ($this->mwGlobals as $key => $value) { $GLOBALS[$key] = $value; } $this->mwGlobals = array(); RequestContext::resetMain(); MediaHandler::resetCache(); $phpErrorLevel = intval(ini_get('error_reporting')); if ($phpErrorLevel !== $this->phpErrorLevel) { ini_set('error_reporting', $this->phpErrorLevel); $oldHex = strtoupper(dechex($this->phpErrorLevel)); $newHex = strtoupper(dechex($phpErrorLevel)); $message = "PHP error_reporting setting was left dirty: " . "was 0x{$oldHex} before test, 0x{$newHex} after test!"; $this->fail($message); } parent::tearDown(); wfProfileOut(__METHOD__); }
public function testBug71329() { SpecialPageFactory::resetList(); RequestContext::resetMain(); $req = new FauxRequest(array('title' => 'Special:Search', 'mobileaction' => 'toggle_view_mobile')); $req->setRequestURL('/w/index.php?title=Special:Search&mobileaction=toggle_view_mobile'); RequestContext::getMain()->setRequest($req); MobileContext::setInstance(null); $this->setMwGlobals('wgTitle', null); SpecialPage::getTitleFor('Search'); $this->assertTrue(true, 'In case of failure this test just crashes'); }
function resetAllEnv() { $_SESSION = array(); $_GET = array(); $_POST = array(); $_SERVER = array(); $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME; $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME; $_SERVER['SCRIPT_NAME'] = __FILE__; RequestContext::resetMain(); // Wipe out the $instance of these classes to make sure they're // re-created with fresh gateway instances for the next test $singleton_classes = array('Gateway_Extras_ConversionLog', 'Gateway_Extras_CustomFilters', 'Gateway_Extras_CustomFilters_Functions', 'Gateway_Extras_CustomFilters_IP_Velocity', 'Gateway_Extras_CustomFilters_MinFraud', 'Gateway_Extras_CustomFilters_Referrer', 'Gateway_Extras_CustomFilters_Source', 'Gateway_Extras_SessionVelocityFilter'); foreach ($singleton_classes as $singleton_class) { $unwrapped = TestingAccessWrapper::newFromClass($singleton_class); $unwrapped->instance = null; } // Reset SmashPig context Context::set(null); }
protected function tearDown() { global $wgRequest, $wgSQLMode; $status = ob_get_status(); if (isset($status['name']) && $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier') { ob_end_flush(); } $this->called['tearDown'] = true; // Cleaning up temporary files foreach ($this->tmpFiles as $fileName) { if (is_file($fileName) || is_link($fileName)) { unlink($fileName); } elseif (is_dir($fileName)) { wfRecursiveRemoveDir($fileName); } } if ($this->needsDB() && $this->db) { // Clean up open transactions while ($this->db->trxLevel() > 0) { $this->db->rollback(__METHOD__, 'flush'); } if ($this->db->getType() === 'mysql') { $this->db->query("SET sql_mode = " . $this->db->addQuotes($wgSQLMode)); } } // Restore mw globals foreach ($this->mwGlobals as $key => $value) { $GLOBALS[$key] = $value; } $this->mwGlobals = []; $this->restoreLoggers(); if (self::$serviceLocator && MediaWikiServices::getInstance() !== self::$serviceLocator) { MediaWikiServices::forceGlobalInstance(self::$serviceLocator); } // TODO: move global state into MediaWikiServices RequestContext::resetMain(); if (session_id() !== '') { session_write_close(); session_id(''); } $wgRequest = new FauxRequest(); MediaWiki\Session\SessionManager::resetCache(); MediaWiki\Auth\AuthManager::resetCache(); $phpErrorLevel = intval(ini_get('error_reporting')); if ($phpErrorLevel !== $this->phpErrorLevel) { ini_set('error_reporting', $this->phpErrorLevel); $oldHex = strtoupper(dechex($this->phpErrorLevel)); $newHex = strtoupper(dechex($phpErrorLevel)); $message = "PHP error_reporting setting was left dirty: " . "was 0x{$oldHex} before test, 0x{$newHex} after test!"; $this->fail($message); } parent::tearDown(); }
protected function setUp() { parent::setUp(); $langObj = Language::factory('en'); $localZone = 'UTC'; $localOffset = date('Z') / 60; $this->setMwGlobals(array('wgMemc' => new EmptyBagOStuff(), 'wgContLang' => $langObj, 'wgLanguageCode' => 'en', 'wgLang' => $langObj, 'wgLocaltimezone' => $localZone, 'wgLocalTZoffset' => $localOffset, 'wgNamespaceProtection' => array(NS_MEDIAWIKI => 'editinterface'))); // Without this testUserBlock will use a non-English context on non-English MediaWiki // installations (because of how Title::checkUserBlock is implemented) and fail. RequestContext::resetMain(); $this->userName = '******'; $this->altUserName = '******'; date_default_timezone_set($localZone); $this->title = Title::makeTitle(NS_MAIN, "Main Page"); if (!isset($this->userUser) || !$this->userUser instanceof User) { $this->userUser = User::newFromName($this->userName); if (!$this->userUser->getID()) { $this->userUser = User::createNew($this->userName, array("email" => "*****@*****.**", "real_name" => "Test User")); $this->userUser->load(); } $this->altUser = User::newFromName($this->altUserName); if (!$this->altUser->getID()) { $this->altUser = User::createNew($this->altUserName, array("email" => "*****@*****.**", "real_name" => "Test User Alt")); $this->altUser->load(); } $this->anonUser = User::newFromId(0); $this->user = $this->userUser; } }