// any live Language object, both on setup and teardown
$reset = function () {
MWNamespace::clearCaches();
- $GLOBALS['wgContLang']->resetNamespaces();
+ MediaWikiServices::getInstance()->getContentLanguage()->resetNamespaces();
};
$setup[] = $reset;
$teardown[] = $reset;
* @return ParserTestResult|false false if skipped
*/
public function runTest( $test ) {
- wfDebug( __METHOD__.": running {$test['desc']}" );
+ wfDebug( __METHOD__ . ": running {$test['desc']}" );
$opts = $this->parseOptions( $test['options'] );
$teardownGuard = $this->perTestSetup( $test );
$lang = Language::factory( $langCode );
$lang->resetNamespaces();
$setup['wgContLang'] = $lang;
+ $setup[] = function () use ( $lang ) {
+ MediaWikiServices::getInstance()->disableService( 'ContentLanguage' );
+ MediaWikiServices::getInstance()->redefineService(
+ 'ContentLanguage',
+ function () use ( $lang ) {
+ return $lang;
+ }
+ );
+ };
+ $teardown[] = function () {
+ MediaWikiServices::getInstance()->resetServiceForTesting( 'ContentLanguage' );
+ };
$reset = function () {
- MagicWord::clearCache();
+ MediaWikiServices::getInstance()->resetServiceForTesting( 'MagicWordFactory' );
$this->resetTitleServices();
};
$setup[] = $reset;
* For best performance, call this once only for all tests. However, it can
* be called at the start of each test if more isolation is desired.
*
- * @todo: This is basically an unrefactored copy of
+ * @todo This is basically an unrefactored copy of
* MediaWikiTestCase::setupAllTestDBs. They should be factored out somehow.
*
* Do not call this function from a MediaWikiTestCase subclass, since
* @param array $articles Article info array from TestFileReader
*/
public function addArticles( $articles ) {
- global $wgContLang;
$setup = [];
$teardown = [];
// Be sure ParserTestRunner::addArticle has correct language set,
// so that system messages get into the right language cache
- if ( $wgContLang->getCode() !== 'en' ) {
+ if ( MediaWikiServices::getInstance()->getContentLanguage()->getCode() !== 'en' ) {
$setup['wgLanguageCode'] = 'en';
- $setup['wgContLang'] = Language::factory( 'en' );
+ $lang = Language::factory( 'en' );
+ $setup['wgContLang'] = $lang;
+ $setup[] = function () use ( $lang ) {
+ $services = MediaWikiServices::getInstance();
+ $services->disableService( 'ContentLanguage' );
+ $services->redefineService( 'ContentLanguage', function () use ( $lang ) {
+ return $lang;
+ } );
+ };
+ $teardown[] = function () {
+ MediaWikiServices::getInstance()->resetServiceForTesting( 'ContentLanguage' );
+ };
}
// Add special namespaces, in case that hasn't been done by staticSetup() yet