From ab0dfd181a4b64e9b55d9a04e334237518e4f147 Mon Sep 17 00:00:00 2001 From: Ladsgroup Date: Mon, 2 Sep 2019 11:03:18 +0000 Subject: [PATCH] Revert "Reset $wgContLang consistently for tests" This reverts commit 09407afd74104bb3a674e4f5c48d10b15914d0db. Reason for revert: It broke Wikibase on master. Bug: T231799 Change-Id: Ie347abb24183ce3000af4d653ce2343ec7a63290 --- RELEASE-NOTES-1.34 | 4 -- .../phpunit/MediaWikiIntegrationTestCase.php | 42 +++++++++---------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index b9b26ce26a..275f4c2fb5 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -443,10 +443,6 @@ because of Phabricator reports. Use OutputPage::getRevisionId() and OutputPage::isRevisionCurrent() instead. * LoadBalancer::haveIndex() and LoadBalancer::isNonZeroLoad() have been deprecated. -* MediaWikiIntegrationTest::setContentLang() has been deprecated. Use - setMwGlobals( 'wgLanguageCode', 'xxx' ) to set a different site language - code, or setService( 'ContentLanguage', $myObj ) to set a specific Language - object. Service resets and $wgContLang will be handled automatically. * FileBackend::getWikiId() has been deprecated. Use FileBackend::getDomainId() instead. * User::getRights() and User::$mRights have been deprecated. Use diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php index c22bf45b88..b1eb9effa7 100644 --- a/tests/phpunit/MediaWikiIntegrationTestCase.php +++ b/tests/phpunit/MediaWikiIntegrationTestCase.php @@ -717,7 +717,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $instantiator ); - self::resetLegacyGlobals(); + if ( $name === 'ContentLanguage' ) { + $this->setMwGlobals( [ 'wgContLang' => $this->localServices->getContentLanguage() ] ); + } } /** @@ -930,7 +932,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->localServices->resetServiceForTesting( $name, true ); } - self::resetLegacyGlobals(); + self::resetGlobalParser(); Language::clearCaches(); } @@ -984,7 +986,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $newInstance->redefineService( $name, $callback ); } - self::resetLegacyGlobals(); + self::resetGlobalParser(); return $newInstance; } @@ -1051,7 +1053,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { MediaWikiServices::forceGlobalInstance( $newServices ); - self::resetLegacyGlobals(); + self::resetGlobalParser(); return $newServices; } @@ -1081,29 +1083,24 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { MediaWikiServices::forceGlobalInstance( self::$originalServices ); $currentServices->destroy(); - self::resetLegacyGlobals(); + self::resetGlobalParser(); return true; } /** - * If legacy globals such as $wgParser or $wgContLang have been unstubbed, replace them with - * fresh ones so they pick up any config changes. They're deprecated, but we still support them - * for now. + * If $wgParser has been unstubbed, replace it with a fresh one so it picks up any config + * changes. $wgParser is deprecated, but we still support it for now. */ - private static function resetLegacyGlobals() { + private static function resetGlobalParser() { // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgParser - global $wgParser, $wgContLang; - if ( !( $wgParser instanceof StubObject ) ) { - $wgParser = new StubObject( 'wgParser', function () { - return MediaWikiServices::getInstance()->getParser(); - } ); - } - if ( !( $wgContLang instanceof StubObject ) ) { - $wgContlang = new StubObject( 'wgContLang', function () { - return MediaWikiServices::getInstance()->getContLang(); - } ); + global $wgParser; + if ( $wgParser instanceof StubObject ) { + return; } + $wgParser = new StubObject( 'wgParser', function () { + return MediaWikiServices::getInstance()->getParser(); + } ); } /** @@ -1116,8 +1113,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { } /** - * @deprecated since 1.34, use setMwGlobals( 'wgLanguageCode' ) to set the code or - * setService( 'ContentLanguage' ) to set an object * @since 1.27 * @param string|Language $lang */ @@ -1127,7 +1122,10 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->setService( 'ContentLanguage', $lang ); $this->setMwGlobals( 'wgLanguageCode', $lang->getCode() ); } else { - $this->setMwGlobals( 'wgLanguageCode', $lang ); + $this->setMwGlobals( [ + 'wgLanguageCode' => $lang, + 'wgContLang' => Language::factory( $lang ), + ] ); } } -- 2.20.1