aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/MediaWikiLangTestCase.php
blob: cc8948f18159eb08bd5417360f0b148fe8a244ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

use MediaWiki\MainConfigNames;

/**
 * Base class that store and restore the Language objects
 */
abstract class MediaWikiLangTestCase extends MediaWikiIntegrationTestCase {
	/**
	 * The annotation causes this to be called immediately before setUp()
	 * @before
	 */
	final protected function mediaWikiLangSetUp(): void {
		$services = $this->getServiceContainer();
		$languageCode = $this->getConfVar( MainConfigNames::LanguageCode );
		$contLanguageCode = $services->getContentLanguageCode()->toString();
		if ( $languageCode !== $contLanguageCode ) {
			throw new RuntimeException( "Error in " . __METHOD__ . ': ' .
				"\$wgLanguageCode ('$languageCode') is different from content language code " .
				"('$contLanguageCode')" );
		}

		$this->setUserLang( 'en' );
		// For mainpage to be 'Main Page'
		$this->setContentLang( 'en' );

		$services->getMessageCache()->disable();
	}
}