Merge "ApiLogin: Remove the first example of outdated flow"
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageClassesTestCase.php
index 4274335..2216ba4 100644 (file)
@@ -3,16 +3,7 @@
  * Helping class to run tests using a clean language instance.
  *
  * This is intended for the MediaWiki language class tests under
- * tests/phpunit/languages. You simply need to extends this test
- * and set it up with a language code using setUpBeforeClass:
- *
- * @par Setting up a language:
- * @code
- * class LanguageFooTest extends LanguageClassesTestCase {
- *   public static function setUpBeforeClass() {
- *     self::setLang( 'Foo' );
- *   }
- * @endcode
+ * tests/phpunit/languages.
  *
  * Before each tests, a new language object is build which you
  * can retrieve in your test using the $this->getLang() method:
  * @endcode
  */
 abstract class LanguageClassesTestCase extends MediaWikiTestCase {
-
-       /**
-        * Regex used to find out the language code out of the class name
-        * used by setUpBeforeClass
-        */
-       private static $reExtractLangFromClass = '/Language(.*)Test/';
-
-       /**
-        * Hold the language code we are going to use. This is extracted
-        * directly from the extending class.
-        */
-       private static $LanguageClassCode;
-
        /**
         * Internal language object
         *
@@ -57,24 +35,9 @@ abstract class LanguageClassesTestCase extends MediaWikiTestCase {
         */
        private $languageObject;
 
-       public static function setUpBeforeClass() {
-               $found = preg_match( self::$reExtractLangFromClass,
-                       get_called_class(), $m );
-               if ( $found ) {
-                       # Normalize language code since classes uses underscores
-                       $m[1] = str_replace( '_', '-', $m[1] );
-               } else {
-                       # Fallback to english language
-                       $m[1] = 'en';
-                       wfDebug(
-                               __METHOD__ . " could not extract a language name "
-                                       . "out of " . get_called_class() . " failling back to 'en'\n"
-                       );
-               }
-               // TODO: validate $m[1] which should be a valid language code
-               self::$LanguageClassCode = $m[1];
-       }
-
+       /**
+        * @return Language
+        */
        protected function getLang() {
                return $this->languageObject;
        }
@@ -84,8 +47,20 @@ abstract class LanguageClassesTestCase extends MediaWikiTestCase {
         */
        protected function setUp() {
                parent::setUp();
-               $this->languageObject = Language::factory(
-                       self::$LanguageClassCode );
+               $found = preg_match( '/Language(.+)Test/', static::class, $m );
+               if ( $found ) {
+                       # Normalize language code since classes uses underscores
+                       $m[1] = strtolower( str_replace( '_', '-', $m[1] ) );
+               } else {
+                       # Fallback to english language
+                       $m[1] = 'en';
+                       wfDebug(
+                               __METHOD__ . ' could not extract a language name '
+                                       . 'out of ' . static::class . " failling back to 'en'\n"
+                       );
+               }
+               // @todo validate $m[1] which should be a valid language code
+               $this->languageObject = Language::factory( $m[1] );
        }
 
        /**