From 60e4f3fd90abf1aced88846138ba9ede66571bda Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 1 Mar 2016 21:46:35 +0000 Subject: [PATCH] tests: Ensure main RequestContext reflects custom $wgLang Call RequestContext::resetMain() so that any subsequent call to getMain() and getLanguage() is aware of the latest state as set up by the setUp() and setupGlobals() methods. The MediaWikiTestCase class for PHPUnit did this already, but the parserTest suite and UploadFromUrlTestSuite didn't yet. Change-Id: I6481176228944004091078704d0346c8f3fc0cf1 --- tests/parser/parserTest.inc | 9 ++++++--- tests/phpunit/suites/UploadFromUrlTestSuite.php | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index c42ff30634..9f453075cb 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -227,12 +227,13 @@ class ParserTest { $messageMemc = wfGetMessageCacheStorage(); $parserMemc = wfGetParserCacheStorage(); - $wgUser = new User; + RequestContext::resetMain(); $context = new RequestContext; + $wgUser = new User; $wgLang = $context->getLanguage(); $wgOut = $context->getOutput(); - $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] ); $wgRequest = $context->getRequest(); + $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] ); if ( $wgStyleDirectory === false ) { $wgStyleDirectory = "$IP/skins"; @@ -931,10 +932,12 @@ class ParserTest { $GLOBALS[$var] = $val; } + // Must be set before $context as user language defaults to $wgContLang $GLOBALS['wgContLang'] = Language::factory( $lang ); $GLOBALS['wgMemc'] = new EmptyBagOStuff; - $context = new RequestContext(); + RequestContext::resetMain(); + $context = RequestContext::getMain(); $GLOBALS['wgLang'] = $context->getLanguage(); $GLOBALS['wgOut'] = $context->getOutput(); $GLOBALS['wgUser'] = $context->getUser(); diff --git a/tests/phpunit/suites/UploadFromUrlTestSuite.php b/tests/phpunit/suites/UploadFromUrlTestSuite.php index 9ff79a5e58..e3c5118e7a 100644 --- a/tests/phpunit/suites/UploadFromUrlTestSuite.php +++ b/tests/phpunit/suites/UploadFromUrlTestSuite.php @@ -63,8 +63,9 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite { $messageMemc = wfGetMessageCacheStorage(); $parserMemc = wfGetParserCacheStorage(); + RequestContext::resetMain(); + $context = RequestContext::getMain(); $wgUser = new User; - $context = new RequestContext; $wgLang = $context->getLanguage(); $wgOut = $context->getOutput(); $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] ); -- 2.20.1