From 9742d569b08e579e77476a9dbcd5b01dfbeab2ee Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 20 Jul 2018 12:03:48 +1000 Subject: [PATCH 1/1] parserTests: re-enable save parse and fix MCR errors * Re-enable parse on save as requested in T159014, instead hide the feature behind an option. * Add the MCR tables to the list of tables that need to be cloned. Fixes unconditional exception. * Fix some undefined member variables, remove assignment to unused variable $this->databaseSetupDone. Bug: T159014 Change-Id: I6be577ebcbadeb4e08079a82543d521fc2bb5948 --- tests/parser/ParserTestRunner.php | 44 ++++++++++++++++++++++++++----- tests/parser/parserTests.php | 3 +++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index ceee432fb8..68bc61e476 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -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( @@ -1184,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 ) { @@ -1451,7 +1478,6 @@ class ParserTestRunner { $this->checkSetupDone( 'setupDatabase' ); $this->dbClone->destroy(); - $this->databaseSetupDone = false; if ( $this->useTemporaryTables ) { if ( $this->db->getType() == 'sqlite' ) { @@ -1651,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, @@ -1663,7 +1693,9 @@ class ParserTestRunner { EDIT_NEW | EDIT_INTERNAL ); } finally { - $restore(); + if ( $restore ) { + $restore(); + } } if ( !$status->isOK() ) { diff --git a/tests/parser/parserTests.php b/tests/parser/parserTests.php index 6a423d5cb3..c01b416311 100644 --- a/tests/parser/parserTests.php +++ b/tests/parser/parserTests.php @@ -62,6 +62,8 @@ class ParserTestsMaintenance extends Maintenance { 'be used.', false, true ); $this->addOption( 'run-disabled', 'run disabled tests' ); $this->addOption( 'run-parsoid', 'run parsoid tests (normally disabled)' ); + $this->addOption( 'disable-save-parse', 'Don\'t run the parser when ' . + 'inserting articles into the database' ); $this->addOption( 'dwdiff', 'Use dwdiff to display diff output' ); $this->addOption( 'mark-ws', 'Mark whitespace in diffs by replacing it with symbols' ); $this->addOption( 'norm', 'Apply a comma-separated list of normalization functions to ' . @@ -180,6 +182,7 @@ class ParserTestsMaintenance extends Maintenance { 'keep-uploads' => $this->hasOption( 'keep-uploads' ), 'run-disabled' => $this->hasOption( 'run-disabled' ), 'run-parsoid' => $this->hasOption( 'run-parsoid' ), + 'disable-save-parse' => $this->hasOption( 'disable-save-parse' ), 'use-tidy-config' => $this->hasOption( 'use-tidy-config' ), 'file-backend' => $this->getOption( 'file-backend' ), 'upload-dir' => $this->getOption( 'upload-dir' ), -- 2.20.1