Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / tests / parser / ParserTestRunner.php
index ceee432..cc3ef1c 100644 (file)
@@ -116,6 +116,30 @@ class ParserTestRunner {
         */
        private $normalizationFunctions = [];
 
+       /**
+        * Run disabled parser tests
+        * @var bool
+        */
+       private $runDisabled;
+
+       /**
+        * Run tests intended only for parsoid
+        * @var bool
+        */
+       private $runParsoid;
+
+       /**
+        * Disable parse on article insertion
+        * @var bool
+        */
+       private $disableSaveParse;
+
+       /**
+        * Reuse upload directory
+        * @var bool
+        */
+       private $keepUploads;
+
        /**
         * @param TestRecorder $recorder
         * @param array $options
@@ -148,6 +172,8 @@ class ParserTestRunner {
                $this->runDisabled = !empty( $options['run-disabled'] );
                $this->runParsoid = !empty( $options['run-parsoid'] );
 
+               $this->disableSaveParse = !empty( $options['disable-save-parse'] );
+
                $this->tidySupport = new TidySupport( !empty( $options['use-tidy-config'] ) );
                if ( !$this->tidySupport->isEnabled() ) {
                        $this->recorder->warning(
@@ -384,7 +410,7 @@ class ParserTestRunner {
                // any live Language object, both on setup and teardown
                $reset = function () {
                        MWNamespace::clearCaches();
-                       $GLOBALS['wgContLang']->resetNamespaces();
+                       MediaWikiServices::getInstance()->getContentLanguage()->resetNamespaces();
                };
                $setup[] = $reset;
                $teardown[] = $reset;
@@ -804,7 +830,7 @@ class ParserTestRunner {
         * @return ParserTestResult|false false if skipped
         */
        public function runTest( $test ) {
-               wfDebug( __METHOD__.": running {$test['desc']}" );
+               wfDebug( __METHOD__ . ": running {$test['desc']}" );
                $opts = $this->parseOptions( $test['options'] );
                $teardownGuard = $this->perTestSetup( $test );
 
@@ -1125,8 +1151,20 @@ class ParserTestRunner {
                $lang = Language::factory( $langCode );
                $lang->resetNamespaces();
                $setup['wgContLang'] = $lang;
+               $setup[] = function () use ( $lang ) {
+                       MediaWikiServices::getInstance()->disableService( 'ContentLanguage' );
+                       MediaWikiServices::getInstance()->redefineService(
+                               'ContentLanguage',
+                               function () use ( $lang ) {
+                                       return $lang;
+                               }
+                       );
+               };
+               $teardown[] = function () {
+                       MediaWikiServices::getInstance()->resetServiceForTesting( 'ContentLanguage' );
+               };
                $reset = function () {
-                       MagicWord::clearCache();
+                       MediaWikiServices::getInstance()->resetServiceForTesting( 'MagicWordFactory' );
                        $this->resetTitleServices();
                };
                $setup[] = $reset;
@@ -1184,7 +1222,8 @@ class ParserTestRunner {
                        'site_stats', 'ipblocks', 'image', 'oldimage',
                        'recentchanges', 'watchlist', 'interwiki', 'logging', 'log_search',
                        'querycache', 'objectcache', 'job', 'l10n_cache', 'redirect', 'querycachetwo',
-                       'archive', 'user_groups', 'page_props', 'category'
+                       'archive', 'user_groups', 'page_props', 'category',
+                       'slots', 'content', 'slot_roles', 'content_models',
                ];
 
                if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) {
@@ -1223,7 +1262,7 @@ class ParserTestRunner {
         * For best performance, call this once only for all tests. However, it can
         * be called at the start of each test if more isolation is desired.
         *
-        * @todo: This is basically an unrefactored copy of
+        * @todo This is basically an unrefactored copy of
         * MediaWikiTestCase::setupAllTestDBs. They should be factored out somehow.
         *
         * Do not call this function from a MediaWikiTestCase subclass, since
@@ -1451,7 +1490,6 @@ class ParserTestRunner {
                $this->checkSetupDone( 'setupDatabase' );
 
                $this->dbClone->destroy();
-               $this->databaseSetupDone = false;
 
                if ( $this->useTemporaryTables ) {
                        if ( $this->db->getType() == 'sqlite' ) {
@@ -1584,15 +1622,25 @@ class ParserTestRunner {
         * @param array $articles Article info array from TestFileReader
         */
        public function addArticles( $articles ) {
-               global $wgContLang;
                $setup = [];
                $teardown = [];
 
                // Be sure ParserTestRunner::addArticle has correct language set,
                // so that system messages get into the right language cache
-               if ( $wgContLang->getCode() !== 'en' ) {
+               if ( MediaWikiServices::getInstance()->getContentLanguage()->getCode() !== 'en' ) {
                        $setup['wgLanguageCode'] = 'en';
-                       $setup['wgContLang'] = Language::factory( 'en' );
+                       $lang = Language::factory( 'en' );
+                       $setup['wgContLang'] = $lang;
+                       $setup[] = function () use ( $lang ) {
+                               $services = MediaWikiServices::getInstance();
+                               $services->disableService( 'ContentLanguage' );
+                               $services->redefineService( 'ContentLanguage', function () use ( $lang ) {
+                                       return $lang;
+                               } );
+                       };
+                       $teardown[] = function () {
+                               MediaWikiServices::getInstance()->resetServiceForTesting( 'ContentLanguage' );
+                       };
                }
 
                // Add special namespaces, in case that hasn't been done by staticSetup() yet
@@ -1651,11 +1699,15 @@ class ParserTestRunner {
                        );
                }
 
-               // Use mock parser, to make debugging of actual parser tests simpler.
+               // Optionally use mock parser, to make debugging of actual parser tests simpler.
                // But initialise the MessageCache clone first, don't let MessageCache
                // get a reference to the mock object.
-               MessageCache::singleton()->getParser();
-               $restore = $this->executeSetupSnippets( [ 'wgParser' => new ParserTestMockParser ] );
+               if ( $this->disableSaveParse ) {
+                       MessageCache::singleton()->getParser();
+                       $restore = $this->executeSetupSnippets( [ 'wgParser' => new ParserTestMockParser ] );
+               } else {
+                       $restore = false;
+               }
                try {
                        $status = $page->doEditContent(
                                $newContent,
@@ -1663,7 +1715,9 @@ class ParserTestRunner {
                                EDIT_NEW | EDIT_INTERNAL
                        );
                } finally {
-                       $restore();
+                       if ( $restore ) {
+                               $restore();
+                       }
                }
 
                if ( !$status->isOK() ) {