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
This commit is contained in:
C. Scott Ananian 2020-08-17 23:41:34 -04:00
parent 1f5b2dc105
commit ce663741bc
2 changed files with 24 additions and 0 deletions

View file

@ -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

View file

@ -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'] );
}
}