* - 'DENY': Do not allow framing. This is recommended for most wikis.
* - 'SAMEORIGIN': Allow framing by pages on the same domain.
* - false: Allow all framing.
+ * Note: $wgBreakFrames will override this for human formatted API output.
*/
$wgApiFrameOptions = 'DENY';
);
}
+ // API handles its own clickjacking protection.
+ // Note, that $wgBreakFrames will still override $wgApiFrameOptions for format mode.
+ $out->allowClickJacking();
$out->output();
} else {
// For non-HTML output, clear all errors that might have been
public function testGetPageViewLanguage( $expected, $titleText, $contLang,
$lang, $variant, $msg = ''
) {
- global $wgLanguageCode, $wgContLang, $wgLang, $wgDefaultLanguageVariant, $wgAllowUserJs;
-
// Setup environnement for this test
- $wgLanguageCode = $contLang;
- $wgContLang = Language::factory( $contLang );
- $wgLang = Language::factory( $lang );
- $wgDefaultLanguageVariant = $variant;
- $wgAllowUserJs = true;
+ $this->setMwGlobals( array(
+ 'wgLanguageCode' => $contLang,
+ 'wgContLang' => Language::factory( $contLang ),
+ 'wgLang' => Language::factory( $lang ),
+ 'wgDefaultLanguageVariant' => $variant,
+ 'wgAllowUserJs' => true,
+ ) );
$title = Title::newFromText( $titleText );
$this->assertInstanceOf( 'Title', $title,
* @covers User::getPasswordExpired()
*/
public function testPasswordExpire() {
- global $wgPasswordExpireGrace;
- $wgTemp = $wgPasswordExpireGrace;
- $wgPasswordExpireGrace = 3600 * 24 * 7; // 7 days
+ $this->setMwGlobals( 'wgPasswordExpireGrace', 3600 * 24 * 7 ); // 7 days
$user = User::newFromName( 'UnitTestUser' );
$user->loadDefaults( 'UnitTestUser' );
$ts = time() - ( 3600 * 24 * 10 ); // 10 days ago
$user->expirePassword( $ts );
$this->assertEquals( 'hard', $user->getPasswordExpired() );
-
- $wgPasswordExpireGrace = $wgTemp;
}
/**
/** @var DerivativeContext */
private $mContext;
- private $mOldGetPreferencesHooks;
-
private static $Success = array( 'options' => 'success' );
protected function setUp() {
$this->mTested = new ApiOptions( $main, 'options' );
- global $wgHooks;
- if ( !isset( $wgHooks['GetPreferences'] ) ) {
- $wgHooks['GetPreferences'] = array();
- }
- $this->mOldGetPreferencesHooks = $wgHooks['GetPreferences'];
- $wgHooks['GetPreferences'][] = array( $this, 'hookGetPreferences' );
- }
-
- protected function tearDown() {
- global $wgHooks;
-
- $wgHooks['GetPreferences'] = $this->mOldGetPreferencesHooks;
- $this->mOldGetPreferencesHooks = false;
-
- parent::tearDown();
+ $this->mergeMwGlobalArrayValue( 'wgHooks', array(
+ 'GetPreferences' => array(
+ array( $this, 'hookGetPreferences' )
+ )
+ ) );
}
public function hookGetPreferences( $user, &$preferences ) {
* @covers ApiQuery
*/
class ApiQueryTest extends ApiTestCase {
- /**
- * @var array Storage for $wgHooks
- */
- protected $hooks;
-
protected function setUp() {
- global $wgHooks;
-
parent::setUp();
$this->doLogin();
- // Setup en: as interwiki prefix
- $this->hooks = $wgHooks;
- $wgHooks['InterwikiLoadPrefix'][] = function ( $prefix, &$data ) {
- if ( $prefix == 'apiquerytestiw' ) {
- $data = array( 'iw_url' => 'wikipedia' );
- }
- return false;
- };
- }
-
- protected function tearDown() {
- global $wgHooks;
- $wgHooks = $this->hooks;
-
- parent::tearDown();
+ // Setup apiquerytestiw: as interwiki prefix
+ $this->setMwGlobals( 'wgHooks', array(
+ 'InterwikiLoadPrefix' => array(
+ function ( $prefix, &$data ) {
+ if ( $prefix == 'apiquerytestiw' ) {
+ $data = array( 'iw_url' => 'wikipedia' );
+ }
+ return false;
+ }
+ )
+ ) );
}
public function testTitlesGetNormalized() {
}
public function testRecacheFallbacksWithHooks() {
- global $wgHooks;
-
// Use hook to provide updates for messages. This is what the
// LocalisationUpdate extension does. See bug 68781.
- $wgHooks['LocalisationCacheRecacheFallback'][] = function (
- LocalisationCache $lc,
- $code,
- array &$cache
- ) {
- if ( $code === 'ru' ) {
- $cache['messages']['present-uk'] = 'ru-override';
- $cache['messages']['present-ru'] = 'ru-override';
- $cache['messages']['present-en'] = 'ru-override';
- }
- };
+ $this->mergeMwGlobalArrayValue( 'wgHooks', array(
+ 'LocalisationCacheRecacheFallback' => array(
+ function (
+ LocalisationCache $lc,
+ $code,
+ array &$cache
+ ) {
+ if ( $code === 'ru' ) {
+ $cache['messages']['present-uk'] = 'ru-override';
+ $cache['messages']['present-ru'] = 'ru-override';
+ $cache['messages']['present-en'] = 'ru-override';
+ }
+ }
+ )
+ ) );
$lc = new LocalisationCache( array( 'store' => 'detect' ) );
$lc->recache( 'uk' );
*/
class TextContentTest extends MediaWikiLangTestCase {
protected $context;
- protected $savedContentGetParserOutput;
protected function setUp() {
- global $wgHooks;
-
parent::setUp();
// Anon user
'wgUseTidy' => false,
'wgAlwaysUseTidy' => false,
'wgCapitalLinks' => true,
+ 'wgHooks' => array(), // bypass hook ContentGetParserOutput that force custom rendering
) );
-
- // bypass hooks that force custom rendering
- if ( isset( $wgHooks['ContentGetParserOutput'] ) ) {
- $this->savedContentGetParserOutput = $wgHooks['ContentGetParserOutput'];
- unset( $wgHooks['ContentGetParserOutput'] );
- }
- }
-
- public function teardown() {
- global $wgHooks;
-
- // restore hooks that force custom rendering
- if ( $this->savedContentGetParserOutput !== null ) {
- $wgHooks['ContentGetParserOutput'] = $this->savedContentGetParserOutput;
- }
-
- parent::teardown();
}
public function newContent( $text ) {
class AutoLoaderTest extends MediaWikiTestCase {
protected function setUp() {
- global $wgAutoloadLocalClasses, $wgAutoloadClasses;
-
parent::setUp();
// Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
- $this->testLocalClasses = array(
- 'TestAutoloadedLocalClass' => __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
- 'TestAutoloadedCamlClass' => __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
+ $this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', array(
+ 'TestAutoloadedLocalClass' =>
+ __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
+ 'TestAutoloadedCamlClass' =>
+ __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
'TestAutoloadedSerializedClass' =>
__DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php',
- );
- $this->setMwGlobals(
- 'wgAutoloadLocalClasses',
- $this->testLocalClasses + $wgAutoloadLocalClasses
- );
+ ) );
AutoLoader::resetAutoloadLocalClassesLower();
- $this->testExtensionClasses = array(
+ $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', array(
'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php',
- );
- $this->setMwGlobals( 'wgAutoloadClasses', $this->testExtensionClasses + $wgAutoloadClasses );
+ ) );
}
/**