Merge "Avoid running of hooks when running MWTimestampTest"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 23 Oct 2014 19:18:20 +0000 (19:18 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 23 Oct 2014 19:18:20 +0000 (19:18 +0000)
includes/DefaultSettings.php
includes/api/ApiFormatBase.php
tests/phpunit/includes/TitleTest.php
tests/phpunit/includes/UserTest.php
tests/phpunit/includes/api/ApiOptionsTest.php
tests/phpunit/includes/api/query/ApiQueryTest.php
tests/phpunit/includes/cache/LocalisationCacheTest.php
tests/phpunit/includes/content/TextContentTest.php
tests/phpunit/structure/AutoLoaderTest.php

index af36a64..d45e573 100644 (file)
@@ -3079,6 +3079,7 @@ $wgEditPageFrameOptions = 'DENY';
  *   - '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';
 
index f0037bb..62705ef 100644 (file)
@@ -178,6 +178,9 @@ abstract class ApiFormatBase extends ApiBase {
                                );
                        }
 
+                       // 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
index fb58381..a4bc427 100644 (file)
@@ -428,14 +428,14 @@ class TitleTest extends MediaWikiTestCase {
        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,
index a0c20bb..f9ef317 100644 (file)
@@ -281,9 +281,7 @@ class UserTest extends MediaWikiTestCase {
         * @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' );
@@ -296,8 +294,6 @@ class UserTest extends MediaWikiTestCase {
                $ts = time() - ( 3600 * 24 * 10 ); // 10 days ago
                $user->expirePassword( $ts );
                $this->assertEquals( 'hard', $user->getPasswordExpired() );
-
-               $wgPasswordExpireGrace = $wgTemp;
        }
 
        /**
index 5f955bb..bd34018 100644 (file)
@@ -17,8 +17,6 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
        /** @var DerivativeContext */
        private $mContext;
 
-       private $mOldGetPreferencesHooks;
-
        private static $Success = array( 'options' => 'success' );
 
        protected function setUp() {
@@ -50,21 +48,11 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
 
                $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 ) {
index bba22c7..200027d 100644 (file)
@@ -7,32 +7,21 @@
  * @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() {
index fc06a50..35ff919 100644 (file)
@@ -60,21 +60,23 @@ class LocalisationCacheTest extends MediaWikiTestCase {
        }
 
        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' );
index 2f81109..dd61f85 100644 (file)
@@ -7,11 +7,8 @@
  */
 class TextContentTest extends MediaWikiLangTestCase {
        protected $context;
-       protected $savedContentGetParserOutput;
 
        protected function setUp() {
-               global $wgHooks;
-
                parent::setUp();
 
                // Anon user
@@ -32,24 +29,8 @@ class TextContentTest extends MediaWikiLangTestCase {
                        '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 ) {
index 2bdc9c9..2142061 100644 (file)
@@ -2,27 +2,22 @@
 
 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 );
+               ) );
        }
 
        /**