Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / languages / LanguageClassesTestCase.php
blobf93ff7d388dab107867575554d300dabf56a8499
1 <?php
2 /**
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:
12 * @code
13 * function testHasLanguageObject() {
14 * $langObject = $this->getLang();
15 * $this->assertInstanceOf( 'LanguageFoo',
16 * $langObject
17 * );
18 * }
19 * @endcode
21 abstract class LanguageClassesTestCase extends MediaWikiTestCase {
22 /**
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
30 * @code
31 * function testWeAreTheChampions() {
32 * $this->getLang(); # language object
33 * }
34 * @endcode
36 private $languageObject;
38 /**
39 * @return Language
41 protected function getLang() {
42 return $this->languageObject;
45 /**
46 * Create a new language object before each test.
48 protected function setUp() {
49 parent::setUp();
50 $found = preg_match( '/Language(.+)Test/', get_called_class(), $m );
51 if ( $found ) {
52 # Normalize language code since classes uses underscores
53 $m[1] = strtolower( str_replace( '_', '-', $m[1] ) );
54 } else {
55 # Fallback to english language
56 $m[1] = 'en';
57 wfDebug(
58 __METHOD__ . " could not extract a language name "
59 . "out of " . get_called_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] );
66 /**
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 );
72 parent::tearDown();