From ce663741bc06ff481df28c9c1618bbe885f5028b Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Mon, 17 Aug 2020 23:41:34 -0400 Subject: [PATCH] Allow independent parser test files to (re)define articles w/ the same names It leads to surprising results when the definitions in one parser test file leak into all the others. This can cause spurious test failures when you happen to have two extensions which define conflicting article fixtures, and prevents you from using parser tests to test patches like I50ff8a7b6be95901ebb14ffbe64940a0f499cfac, where you deliberately want to set up and test two different definitions for the same template name. Change-Id: I958c6305a95ca32418d83b7f33f7c180a3b370cd --- tests/parser/ParserTestRunner.php | 20 ++++++++++++++++++++ tests/phpunit/suites/ParserTestFileSuite.php | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 9cb6a23b15f..d3a86e98aea 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -786,6 +786,9 @@ class ParserTestRunner { } } + // Clean up + $this->cleanupArticles( $testFileInfo['articles'] ); + return $ok; } @@ -1542,6 +1545,23 @@ class ParserTestRunner { $this->executeSetupSnippets( $teardown ); } + /** + * Remove articles from the test DB. This prevents independent parser + * test files from having conflicts when they choose the same names + * for article or template test fixtures. + * + * @param array $articles Article info array from TestFileReader + */ + public function cleanupArticles( $articles ) { + $user = RequestContext::getMain()->getUser(); + foreach ( $articles as $info ) { + $name = self::chomp( $info['name'] ); + $title = Title::newFromText( $name ); + $page = WikiPage::factory( $title ); + $page->doDeleteArticleReal( 'cleaning up', $user ); + } + } + /** * Insert a temporary test article * @param string $name The title, including any prefix diff --git a/tests/phpunit/suites/ParserTestFileSuite.php b/tests/phpunit/suites/ParserTestFileSuite.php index de4cd11827b..adbae09118f 100644 --- a/tests/phpunit/suites/ParserTestFileSuite.php +++ b/tests/phpunit/suites/ParserTestFileSuite.php @@ -41,4 +41,8 @@ class ParserTestFileSuite extends TestSuite { protected function setUp() : void { $this->ptRunner->addArticles( $this->ptFileInfo[ 'articles'] ); } + + protected function tearDown() : void { + $this->ptRunner->cleanupArticles( $this->ptFileInfo[ 'articles'] ); + } }