From: Aryeh Gregor Date: Sun, 1 Sep 2019 08:39:50 +0000 (+0300) Subject: Reset $wgContLang consistently for tests X-Git-Tag: 1.34.0-rc.0~442 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=09407afd74104bb3a674e4f5c48d10b15914d0db;p=lhc%2Fweb%2Fwiklou.git Reset $wgContLang consistently for tests We already reset $wgParser to a stub in a number of places where it might have changed. Let's give $wgContLang the same treatment so we can avoid special-case code. This deprecates setContentLang(), which is no longer needed. The magic of $wgContLang is now handled by setMwGlobals() and setService(). This is a follow-up to e4f69ee, which fixed one case of this problem. Change-Id: I90925ef8b2a7478cce90d474db1b8b4539e45c15 --- diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index 275f4c2fb5..b9b26ce26a 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -443,6 +443,10 @@ 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 b1eb9effa7..c22bf45b88 100644 --- a/tests/phpunit/MediaWikiIntegrationTestCase.php +++ b/tests/phpunit/MediaWikiIntegrationTestCase.php @@ -717,9 +717,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $instantiator ); - if ( $name === 'ContentLanguage' ) { - $this->setMwGlobals( [ 'wgContLang' => $this->localServices->getContentLanguage() ] ); - } + self::resetLegacyGlobals(); } /** @@ -932,7 +930,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->localServices->resetServiceForTesting( $name, true ); } - self::resetGlobalParser(); + self::resetLegacyGlobals(); Language::clearCaches(); } @@ -986,7 +984,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $newInstance->redefineService( $name, $callback ); } - self::resetGlobalParser(); + self::resetLegacyGlobals(); return $newInstance; } @@ -1053,7 +1051,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { MediaWikiServices::forceGlobalInstance( $newServices ); - self::resetGlobalParser(); + self::resetLegacyGlobals(); return $newServices; } @@ -1083,24 +1081,29 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { MediaWikiServices::forceGlobalInstance( self::$originalServices ); $currentServices->destroy(); - self::resetGlobalParser(); + self::resetLegacyGlobals(); return true; } /** - * 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. + * 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. */ - private static function resetGlobalParser() { + private static function resetLegacyGlobals() { // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgParser - global $wgParser; - if ( $wgParser instanceof StubObject ) { - return; + 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(); + } ); } - $wgParser = new StubObject( 'wgParser', function () { - return MediaWikiServices::getInstance()->getParser(); - } ); } /** @@ -1113,6 +1116,8 @@ 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 */ @@ -1122,10 +1127,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->setService( 'ContentLanguage', $lang ); $this->setMwGlobals( 'wgLanguageCode', $lang->getCode() ); } else { - $this->setMwGlobals( [ - 'wgLanguageCode' => $lang, - 'wgContLang' => Language::factory( $lang ), - ] ); + $this->setMwGlobals( 'wgLanguageCode', $lang ); } }