/** * @return Config */ private function newTestConfig() { $globalConfig = new GlobalVarConfig(); $testConfig = new HashConfig(); $testConfig->set('ServiceWiringFiles', $globalConfig->get('ServiceWiringFiles')); $testConfig->set('ConfigRegistry', $globalConfig->get('ConfigRegistry')); return $testConfig; }
/** * @covers HashConfig::set */ public function testSet() { $conf = new HashConfig(['one' => '1']); $conf->set('two', '2'); $this->assertEquals('2', $conf->get('two')); // Check that set overwrites $conf->set('one', '3'); $this->assertEquals('3', $conf->get('one')); }
public function testCrossDomainMangling() { $config = new HashConfig(array('MangleFlashPolicy' => false)); $context = new RequestContext(); $context->setConfig(new MultiConfig(array($config, $context->getConfig()))); $main = new ApiMain($context); $main->getResult()->addValue(null, null, '< Cross-Domain-Policy >'); if (!function_exists('wfOutputHandler')) { function wfOutputHandler($s) { return $s; } } $printer = $main->createPrinterByName('php'); ob_start('wfOutputHandler'); $printer->initPrinter(); $printer->execute(); $printer->closePrinter(); $ret = ob_get_clean(); $this->assertSame('a:1:{i:0;s:23:"< Cross-Domain-Policy >";}', $ret); $config->set('MangleFlashPolicy', true); $printer = $main->createPrinterByName('php'); ob_start('wfOutputHandler'); try { $printer->initPrinter(); $printer->execute(); $printer->closePrinter(); ob_end_clean(); $this->fail('Expected exception not thrown'); } catch (UsageException $ex) { ob_end_clean(); $this->assertSame('This response cannot be represented using format=php. See https://phabricator.wikimedia.org/T68776', $ex->getMessage(), 'Expected exception'); } }
public function testGetNewPasswordExpiry() { $config = new \HashConfig(); $provider = $this->getMockForAbstractClass(AbstractPasswordPrimaryAuthenticationProvider::class); $provider->setConfig(new \MultiConfig([$config, \ConfigFactory::getDefaultInstance()->makeConfig('main')])); $provider->setLogger(new \Psr\Log\NullLogger()); $providerPriv = \TestingAccessWrapper::newFromObject($provider); $this->mergeMwGlobalArrayValue('wgHooks', ['ResetPasswordExpiration' => []]); $config->set('PasswordExpirationDays', 0); $this->assertNull($providerPriv->getNewPasswordExpiry('UTSysop')); $config->set('PasswordExpirationDays', 5); $this->assertEquals(time() + 5 * 86400, wfTimestamp(TS_UNIX, $providerPriv->getNewPasswordExpiry('UTSysop')), '', 2); $this->mergeMwGlobalArrayValue('wgHooks', ['ResetPasswordExpiration' => [function ($user, &$expires) { $this->assertSame('UTSysop', $user->getName()); $expires = '30001231235959'; }]]); $this->assertEquals('30001231235959', $providerPriv->getNewPasswordExpiry('UTSysop')); }
private function getProvider($name, $prefix = null) { $config = new \HashConfig(); $config->set('CookiePrefix', 'wgCookiePrefix'); $params = array('sessionCookieName' => $name, 'sessionCookieOptions' => array()); if ($prefix !== null) { $params['sessionCookieOptions']['prefix'] = $prefix; } $provider = $this->getMockBuilder('MediaWiki\\Session\\ImmutableSessionProviderWithCookie')->setConstructorArgs(array($params))->getMockForAbstractClass(); $provider->setLogger(new \TestLogger()); $provider->setConfig($config); $provider->setManager(new SessionManager()); return $provider; }
/** * Constructs a Config object that contains configuration settings that should be * overwritten for the installation process. * * @since 1.27 * * @param Config $baseConfig * * @return Config The config to use during installation. */ public static function getInstallerConfig(Config $baseConfig) { $configOverrides = new HashConfig(); // disable (problematic) object cache types explicitly, preserving all other (working) ones // bug T113843 $emptyCache = ['class' => 'EmptyBagOStuff']; $objectCaches = [CACHE_NONE => $emptyCache, CACHE_DB => $emptyCache, CACHE_ANYTHING => $emptyCache, CACHE_MEMCACHED => $emptyCache] + $baseConfig->get('ObjectCaches'); $configOverrides->set('ObjectCaches', $objectCaches); // Load the installer's i18n. $messageDirs = $baseConfig->get('MessagesDirs'); $messageDirs['MediawikiInstaller'] = __DIR__ . '/i18n'; $configOverrides->set('MessagesDirs', $messageDirs); $installerConfig = new MultiConfig([$configOverrides, $baseConfig]); // make sure we use the installer config as the main config $configRegistry = $baseConfig->get('ConfigRegistry'); $configRegistry['main'] = function () use($installerConfig) { return $installerConfig; }; $configOverrides->set('ConfigRegistry', $configRegistry); return $installerConfig; }
/** * Create a config suitable for testing, based on a base config, default overrides, * and custom overrides. * * @param Config|null $baseConfig * @param Config|null $customOverrides * * @return Config */ private static function makeTestConfig(Config $baseConfig = null, Config $customOverrides = null) { $defaultOverrides = new HashConfig(); if (!$baseConfig) { $baseConfig = MediaWikiServices::getInstance()->getBootstrapConfig(); } /* Some functions require some kind of caching, and will end up using the db, * which we can't allow, as that would open a new connection for mysql. * Replace with a HashBag. They would not be going to persist anyway. */ $hashCache = ['class' => 'HashBagOStuff', 'reportDupes' => false]; $objectCaches = [CACHE_DB => $hashCache, CACHE_ACCEL => $hashCache, CACHE_MEMCACHED => $hashCache, 'apc' => $hashCache, 'xcache' => $hashCache, 'wincache' => $hashCache] + $baseConfig->get('ObjectCaches'); $defaultOverrides->set('ObjectCaches', $objectCaches); $defaultOverrides->set('MainCacheType', CACHE_NONE); $defaultOverrides->set('JobTypeConf', ['default' => ['class' => 'JobQueueMemory']]); // Use a fast hash algorithm to hash passwords. $defaultOverrides->set('PasswordDefault', 'A'); $testConfig = $customOverrides ? new MultiConfig([$customOverrides, $defaultOverrides, $baseConfig]) : new MultiConfig([$defaultOverrides, $baseConfig]); return $testConfig; }