parserTests: re-enable save parse and fix MCR errors
[lhc/web/wiklou.git] / tests / parser / ParserTestRunner.php
index 08ec9f6..68bc61e 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
@@ -143,12 +167,13 @@ class ParserTestRunner {
 
                $this->keepUploads = !empty( $options['keep-uploads'] );
 
-               $this->fileBackendName = isset( $options['file-backend'] ) ?
-                       $options['file-backend'] : false;
+               $this->fileBackendName = $options['file-backend'] ?? false;
 
                $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(
@@ -465,7 +490,7 @@ class ParserTestRunner {
                        if ( is_int( $name ) ) {
                                $value();
                        } else {
-                               $saved[$name] = isset( $GLOBALS[$name] ) ? $GLOBALS[$name] : null;
+                               $saved[$name] = $GLOBALS[$name] ?? null;
                                $GLOBALS[$name] = $value;
                        }
                }
@@ -537,7 +562,7 @@ class ParserTestRunner {
         * @return bool
         */
        public function isSetupDone( $funcName ) {
-               return isset( $this->setupDone[$funcName] ) ? $this->setupDone[$funcName] : false;
+               return $this->setupDone[$funcName] ?? false;
        }
 
        /**
@@ -774,7 +799,7 @@ class ParserTestRunner {
        /**
         * Get a Parser object
         *
-        * @param string $preprocessor
+        * @param string|null $preprocessor
         * @return Parser
         */
        function getParser( $preprocessor = null ) {
@@ -829,8 +854,15 @@ class ParserTestRunner {
                        $titleText = 'Parser test';
                }
 
+               if ( isset( $opts['maxincludesize'] ) ) {
+                       $options->setMaxIncludeSize( $opts['maxincludesize'] );
+               }
+               if ( isset( $opts['maxtemplatedepth'] ) ) {
+                       $options->setMaxTemplateDepth( $opts['maxtemplatedepth'] );
+               }
+
                $local = isset( $opts['local'] );
-               $preprocessor = isset( $opts['preprocessor'] ) ? $opts['preprocessor'] : null;
+               $preprocessor = $opts['preprocessor'] ?? null;
                $parser = $this->getParser( $preprocessor );
                $title = Title::newFromText( $titleText );
 
@@ -1083,6 +1115,11 @@ class ParserTestRunner {
                        'wgFragmentMode' => [ 'legacy' ],
                ];
 
+               $nonIncludable = self::getOptionValue( 'wgNonincludableNamespaces', $opts, false );
+               if ( $nonIncludable !== false ) {
+                       $setup['wgNonincludableNamespaces'] = [ $nonIncludable ];
+               }
+
                if ( $config ) {
                        $configLines = explode( "\n", $config );
 
@@ -1173,7 +1210,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 ) {
@@ -1253,6 +1291,7 @@ class ParserTestRunner {
                $this->dbClone = new CloneDatabase( $this->db, $this->listTables(), $prefix );
                $this->dbClone->useTemporaryTables( $temporary );
                $this->dbClone->cloneTableStructure();
+               CloneDatabase::changePrefix( $prefix );
 
                if ( $dbType == 'oracle' ) {
                        $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
@@ -1270,7 +1309,7 @@ class ParserTestRunner {
 
                // Wipe some DB query result caches on setup and teardown
                $reset = function () {
-                       LinkCache::singleton()->clear();
+                       MediaWikiServices::getInstance()->getLinkCache()->clear();
 
                        // Clear the message cache
                        MessageCache::singleton()->clear();
@@ -1439,7 +1478,6 @@ class ParserTestRunner {
                $this->checkSetupDone( 'setupDatabase' );
 
                $this->dbClone->destroy();
-               $this->databaseSetupDone = false;
 
                if ( $this->useTemporaryTables ) {
                        if ( $this->db->getType() == 'sqlite' ) {
@@ -1639,11 +1677,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,
@@ -1651,7 +1693,9 @@ class ParserTestRunner {
                                EDIT_NEW | EDIT_INTERNAL
                        );
                } finally {
-                       $restore();
+                       if ( $restore ) {
+                               $restore();
+                       }
                }
 
                if ( !$status->isOK() ) {