3 * Helping class to run tests using a clean language instance.
5 * This is intended for the MediaWiki language class tests under
6 * tests/phpunit/languages.
8 * Before each tests, a new language object is build which you
9 * can retrieve in your test using the $this->getLang() method:
11 * @par Using the crafted language object:
13 * function testHasLanguageObject() {
14 * $langObject = $this->getLang();
15 * $this->assertInstanceOf( 'LanguageFoo',
21 abstract class LanguageClassesTestCase
extends MediaWikiTestCase
{
23 * Internal language object
25 * A new object is created before each tests thanks to PHPUnit
26 * setUp() method, it is deleted after each test too. To get
27 * this object you simply use the getLang method.
29 * You must have setup a language code first. See $LanguageClassCode
31 * function testWeAreTheChampions() {
32 * $this->getLang(); # language object
36 private $languageObject;
41 protected function getLang() {
42 return $this->languageObject
;
46 * Create a new language object before each test.
48 protected function setUp() {
50 $found = preg_match( '/Language(.+)Test/', static::class, $m );
52 # Normalize language code since classes uses underscores
53 $m[1] = strtolower( str_replace( '_', '-', $m[1] ) );
55 # Fallback to english language
58 __METHOD__
. ' could not extract a language name '
59 . 'out of ' . static::class . " failling back to 'en'\n"
62 // @todo validate $m[1] which should be a valid language code
63 $this->languageObject
= Language
::factory( $m[1] );
67 * Delete the internal language object so each test start
68 * out with a fresh language instance.
70 protected function tearDown() {
71 unset( $this->languageObject
);