abstract class MediaWikiLangTestCase extends MediaWikiTestCase {
protected function setUp() {
global $wgLanguageCode, $wgContLang;
- parent::setUp();
if ( $wgLanguageCode != $wgContLang->getCode() ) {
throw new MWException( "Error in MediaWikiLangTestCase::setUp(): " .
"\$wgContLang->getCode() (" . $wgContLang->getCode() . ")" );
}
- // HACK: Call getLanguage() so the real $wgContLang is cached as the user language
- // rather than our fake one. This is to avoid breaking other, unrelated tests.
- RequestContext::getMain()->getLanguage();
-
- $langCode = 'en'; # For mainpage to be 'Main Page'
- $langObj = Language::factory( $langCode );
+ parent::setUp();
- $this->setMwGlobals( [
- 'wgLanguageCode' => $langCode,
- 'wgLang' => $langObj,
- 'wgContLang' => $langObj,
- ] );
+ $this->setUserLang( 'en' );
+ // For mainpage to be 'Main Page'
+ $this->setContentLang( 'en' );
MessageCache::singleton()->disable();
}
$this->setMwGlobals( $name, $merged );
}
+ /**
+ * @since 1.27
+ * @param string|Language $lang
+ */
+ public function setUserLang( $lang ) {
+ RequestContext::getMain()->setLanguage( $lang );
+ $this->setMwGlobals( 'wgLang', RequestContext::getMain()->getLanguage() );
+ }
+
+ /**
+ * @since 1.27
+ * @param string|Language $lang
+ */
+ public function setContentLang( $lang ) {
+ if ( $lang instanceof Language ) {
+ $langCode = $lang->getCode();
+ $langObj = $lang;
+ } else {
+ $langCode = $lang;
+ $langObj = Language::factory( $langCode );
+ }
+ $this->setMwGlobals( [
+ 'wgLanguageCode' => $langCode,
+ 'wgContLang' => $langObj,
+ ] );
+ }
+
/**
* Sets the logger for a specified channel, for the duration of the test.
* @since 1.27
/* variable used to save up the blockID we insert in this test suite */
private $blockId;
- protected function setUp() {
- parent::setUp();
- $this->setMwGlobals( [
- 'wgLanguageCode' => 'en',
- 'wgContLang' => Language::factory( 'en' )
- ] );
- }
-
function addDBData() {
$user = User::newFromName( 'UTBlockee' );
protected function setUp() {
parent::setUp();
$this->setMwGlobals( [
- 'wgContLang' => Language::factory( 'en' ),
- 'wgLanguageCode' => 'en',
'wgCapitalLinks' => true,
] );
}
$contLang = Language::factory( 'en' );
$this->setMwGlobals( [
'wgShowDBErrorBacktrace' => true,
- 'wgLanguageCode' => 'en',
- 'wgContLang' => $contLang,
- 'wgLang' => Language::factory( 'en' ),
'wgCleanSignatures' => true,
] );
+ $this->setUserLang( 'en' );
+ $this->setContentLang( $contLang );
+ // FIXME: This test should pass without setting global content language
$this->options = ParserOptions::newFromUserAndLang( new User, $contLang );
$this->options->setTemplateCallback( [ __CLASS__, 'statelessFetchTemplate' ] );
$this->parser = new Parser;
protected function setUp() {
parent::setUp();
- $langCode = 'en';
- $langObj = Language::factory( $langCode );
+ $this->setMwGlobals( [
+ 'wgWellFormedXml' => false,
+ ] );
+
+ $langObj = Language::factory( 'en' );
// Hardcode namespaces during test runs,
// so that html output based on existing namespaces
100 => 'Custom',
101 => 'Custom_talk',
] );
-
- $this->setMwGlobals( [
- 'wgLanguageCode' => $langCode,
- 'wgContLang' => $langObj,
- 'wgLang' => $langObj,
- 'wgWellFormedXml' => false,
- ] );
+ $this->setUserLang( $langObj );
+ $this->setContentLang( $langObj );
}
/**
// Avoid 'GetHumanTimestamp' hook and others
$this->setMwGlobals( 'wgHooks', [] );
-
- RequestContext::getMain()->setLanguage( Language::factory( 'en' ) );
}
/**
parent::setUp();
$this->setMwGlobals( [
- 'wgLang' => Language::factory( 'en' ),
'wgForceUIMsgAsContentMsg' => [],
] );
+ $this->setUserLang( 'en' );
}
/**
* @covers Message::inContentLanguage
*/
public function testInContentLanguage() {
- $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) );
+ $this->setUserLang( 'fr' );
// NOTE: make sure internal caching of the message text is reset appropriately
$msg = wfMessage( 'mainpage' );
*/
public function testInContentLanguageOverride() {
$this->setMwGlobals( [
- 'wgLang' => Language::factory( 'fr' ),
'wgForceUIMsgAsContentMsg' => [ 'mainpage' ],
] );
+ $this->setUserLang( 'fr' );
// NOTE: make sure internal caching of the message text is reset appropriately.
// NOTE: wgForceUIMsgAsContentMsg forces the messages *current* language to be used.
protected function setUp() {
parent::setUp();
- $langObj = Language::factory( 'en' );
$localZone = 'UTC';
$localOffset = date( 'Z' ) / 60;
$this->setMwGlobals( [
- 'wgContLang' => $langObj,
- 'wgLanguageCode' => 'en',
- 'wgLang' => $langObj,
'wgLocaltimezone' => $localZone,
'wgLocalTZoffset' => $localOffset,
'wgNamespaceProtection' => [
parent::setUp();
$this->setMwGlobals( [
- 'wgLanguageCode' => 'en',
- 'wgContLang' => Language::factory( 'en' ),
- // User language
- 'wgLang' => Language::factory( 'en' ),
'wgAllowUserJs' => false,
'wgDefaultLanguageVariant' => false,
'wgMetaNamespace' => 'Project',
] );
+ $this->setUserLang( 'en' );
+ $this->setContentLang( 'en' );
}
/**
) {
// Setup environnement for this test
$this->setMwGlobals( [
- 'wgLanguageCode' => $contLang,
- 'wgContLang' => Language::factory( $contLang ),
- 'wgLang' => Language::factory( $lang ),
'wgDefaultLanguageVariant' => $variant,
'wgAllowUserJs' => true,
] );
+ $this->setUserLang( $lang );
+ $this->setContentLang( $contLang );
$title = Title::newFromText( $titleText );
$this->assertInstanceOf( 'Title', $title,
protected function configureLanguages() {
// for the test, we need the content language to be anything but English,
// let's choose e.g. German (de)
- $langCode = 'de';
- $langObj = Language::factory( $langCode );
-
- $this->setMwGlobals( [
- 'wgLanguageCode' => $langCode,
- 'wgLang' => $langObj,
- 'wgContLang' => $langObj,
- ] );
+ $this->setUserLang( 'de' );
+ $this->setContentLang( 'de' );
}
function addDBData() {
$this->setMwGlobals( [
'wgArticlePath' => '/wiki/$1',
- 'wgLang' => Language::factory( 'qqx' )
] );
+ $this->setUserLang( 'qqx' );
}
/**
private function getContext() {
$user = $this->getTestUser();
$context = $this->testRecentChangesHelper->getTestContext( $user );
- $context->setLanguage( Language::factory( 'qqx' ) );
+ $context->setLanguage( 'qqx' );
return $context;
}
public function getTestContext( User $user ) {
$context = new RequestContext();
- $context->setLanguage( Language::factory( 'en' ) );
+ $context->setLanguage( 'en' );
$context->setUser( $user );
* @dataProvider provideTextUseOutputPage
* @covers MWException::useOutputPage
*/
- public function testUseOutputPage( $expected, $wgLang, $wgFullyInitialised, $wgOut ) {
+ public function testUseOutputPage( $expected, $langObj, $wgFullyInitialised, $wgOut ) {
$this->setMwGlobals( [
- 'wgLang' => $wgLang,
+ 'wgLang' => $langObj,
'wgFullyInitialised' => $wgFullyInitialised,
'wgOut' => $wgOut,
] );
public function provideTextUseOutputPage() {
return [
- // expected, wgLang, wgFullyInitialised, wgOut
+ // expected, langObj, wgFullyInitialised, wgOut
[ false, null, null, null ],
[ false, $this->getMockLanguage(), null, null ],
[ false, $this->getMockLanguage(), true, null ],
* @dataProvider provideUseMessageCache
* @covers MWException::useMessageCache
*/
- public function testUseMessageCache( $expected, $wgLang ) {
+ public function testUseMessageCache( $expected, $langObj ) {
$this->setMwGlobals( [
- 'wgLang' => $wgLang,
+ 'wgLang' => $langObj,
] );
$e = new MWException();
$this->assertEquals( $expected, $e->useMessageCache() );
$page = WikiPage::factory( $title );
$user = new User();
$user->mRights = [ 'createpage', 'edit', 'purge' ];
- $this->setMwGlobals( 'wgLanguageCode', 'es' );
- $this->setMwGlobals( 'wgContLang', Language::factory( 'es' ) );
- $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) );
+ $this->setContentLang( 'es' );
+ $this->setUserLang( 'fr' );
$page->doEditContent(
new WikitextContent( '{{:{{int:history}}}}' ),
);
$templates1 = $title->getTemplateLinksFrom();
- $this->setMwGlobals( 'wgLang', Language::factory( 'de' ) );
+ $this->setUserLang( 'de' );
$page = WikiPage::factory( $title ); // In order to force the re-rendering of the same wikitext
// We need an edit, a purge is not enough to regenerate the tables
parent::setUp();
$this->setMwGlobals( [
- 'wgLanguageCode' => 'en',
- 'wgContLang' => Language::factory( 'en' ),
- // User language
- 'wgLang' => Language::factory( 'en' ),
'wgAllowUserJs' => false,
'wgDefaultLanguageVariant' => false,
'wgMetaNamespace' => 'Project',
]
]
] );
+ $this->setUserLang( 'en' );
+ $this->setContentLang( 'en' );
}
/**