Merge "Add part to update ctd_user_defined in populateChangeTagDef"
[lhc/web/wiklou.git] / tests / phpunit / suites / ParserTestTopLevelSuite.php
index 5d5d693..cc0f263 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 use Wikimedia\ScopedCallback;
 
 /**
@@ -17,6 +18,8 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
        /** @var ScopedCallback */
        private $ptTeardownScope;
 
+       private $oldTablePrefix = '';
+
        /**
         * @defgroup filtering_constants Filtering constants
         *
@@ -29,7 +32,7 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
        /** Include non core files as set in $wgParserTestFiles */
        const NO_CORE = 2;
        /** Include anything set via $wgParserTestFiles */
-       const WITH_ALL = 3; # CORE_ONLY | NO_CORE
+       const WITH_ALL = self::CORE_ONLY | self::NO_CORE;
 
        /** @} */
 
@@ -69,7 +72,7 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
                if ( is_string( $flags ) ) {
                        $flags = self::CORE_ONLY;
                }
-               global $wgParserTestFiles, $IP;
+               global $IP;
 
                $mwTestDir = $IP . '/tests/';
 
@@ -81,15 +84,16 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
                $filesToTest = [];
 
                # Filter out .txt files
-               foreach ( $wgParserTestFiles as $parserTestFile ) {
+               $files = ParserTestRunner::getParserTestFiles();
+               foreach ( $files as $extName => $parserTestFile ) {
                        $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) );
 
                        if ( $isCore && $wantsCore ) {
                                self::debug( "included core parser tests: $parserTestFile" );
-                               $filesToTest[] = $parserTestFile;
+                               $filesToTest[$extName] = $parserTestFile;
                        } elseif ( !$isCore && $wantsRest ) {
                                self::debug( "included non core parser tests: $parserTestFile" );
-                               $filesToTest[] = $parserTestFile;
+                               $filesToTest[$extName] = $parserTestFile;
                        } else {
                                self::debug( "skipped parser tests: $parserTestFile" );
                        }
@@ -99,12 +103,13 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
 
                $testList = [];
                $counter = 0;
-               foreach ( $filesToTest as $fileName ) {
-                       // Call the highest level directory the extension name.
-                       // It may or may not actually be, but it should be close
-                       // enough to cause there to be separate names for different
-                       // things, which is good enough for our purposes.
-                       $extensionName = basename( dirname( $fileName ) );
+               foreach ( $filesToTest as $extensionName => $fileName ) {
+                       if ( is_int( $extensionName ) ) {
+                               // If there's no extension name because this is coming
+                               // from the legacy global, then assume the next level directory
+                               // is the extension name (e.g. extensions/FooBar/parserTests.txt).
+                               $extensionName = basename( dirname( $fileName ) );
+                       }
                        $testsName = $extensionName . '__' . basename( $fileName, '.txt' );
                        $parserTestClassName = ucfirst( $testsName );
 
@@ -131,12 +136,24 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
 
        public function setUp() {
                wfDebug( __METHOD__ );
+
                $db = wfGetDB( DB_MASTER );
                $type = $db->getType();
                $prefix = $type === 'oracle' ?
                        MediaWikiTestCase::ORA_DB_PREFIX : MediaWikiTestCase::DB_PREFIX;
+               $this->oldTablePrefix = $db->tablePrefix();
                MediaWikiTestCase::setupTestDB( $db, $prefix );
-               $teardown = $this->ptRunner->setDatabase( $db );
+               CloneDatabase::changePrefix( $prefix );
+
+               $this->ptRunner->setDatabase( $db );
+
+               MediaWikiTestCase::resetNonServiceCaches();
+
+               MediaWikiTestCase::installMockMwServices();
+               $teardown = new ScopedCallback( function () {
+                       MediaWikiTestCase::restoreMwServices();
+               } );
+
                $teardown = $this->ptRunner->setupUploads( $teardown );
                $this->ptTeardownScope = $teardown;
        }
@@ -146,6 +163,7 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
                if ( $this->ptTeardownScope ) {
                        ScopedCallback::consume( $this->ptTeardownScope );
                }
+               CloneDatabase::changePrefix( $this->oldTablePrefix );
        }
 
        /**
@@ -153,6 +171,6 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
         * @param string $msg Message to log
         */
        protected static function debug( $msg ) {
-               return wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg );
+               wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg );
        }
 }