From: Platonides Date: Fri, 5 Nov 2010 20:03:18 +0000 (+0000) Subject: Follow up r75810. The code for the parser tests modified the main database even when... X-Git-Tag: 1.31.0-rc.0~34063 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=f04d76c36f149d01b39e2883cb0e4ffcefad69c6;p=lhc%2Fweb%2Fwiklou.git Follow up r75810. The code for the parser tests modified the main database even when they were not run. They are now lazy loaded on the first parserTest. This should also make running the other parserTests faster. It shouldn't take that memory or even parse ParserTests.txt if they are not going to be run, though. PHPUnit ParserTests are still broken at this point due to r74646 --- diff --git a/maintenance/tests/parser/parserTest.inc b/maintenance/tests/parser/parserTest.inc index da07b9c2a8..381c265e86 100644 --- a/maintenance/tests/parser/parserTest.inc +++ b/maintenance/tests/parser/parserTest.inc @@ -1154,7 +1154,7 @@ class ParserTest { * @param $text String: the article text * @param $line Integer: the input line number, for reporting errors */ - static public function addArticle( $name, $text, $line ) { + static public function addArticle( $name, $text, $line = 'unknown' ) { global $wgCapitalLinks; $text = self::chomp($text); diff --git a/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php b/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php index f6fabe17c4..a8d105ab06 100644 --- a/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php +++ b/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php @@ -4,8 +4,9 @@ require_once( dirname( __FILE__ ) . '/ParserHelpers.php' ); require_once( dirname(dirname(dirname( __FILE__ ))) . '/bootstrap.php' ); class MediaWikiParserTest extends MediaWikiTestSetup { - public $count; - public $backend; + public $count; // Number of tests in the suite. + public $backend; // ParserTestSuiteBackend instance + public $articles = array(); // Array of test articles defined by the tests public function __construct() { $suite = new PHPUnit_Framework_TestSuite('Parser Tests'); @@ -24,7 +25,7 @@ class MediaWikiParserTest extends MediaWikiTestSetup { $tester->count = 0; foreach ( $iter as $test ) { - $tester->suite->addTest( new ParserUnitTest( $tester, $test ), array( 'Parser', 'Broken' ) ); + $tester->suite->addTest( new ParserUnitTest( $tester, $test ), array( 'Parser', 'Destructive', 'Database', 'Broken' ) ); $tester->count++; } @@ -46,5 +47,24 @@ class MediaWikiParserTest extends MediaWikiTestSetup { public function getIterator() { return $this->iterator; } + + public function publishTestArticles() { + if ( empty( $this->articles ) ) { + return; + } + + foreach ( $this->articles as $name => $text ) { + $title = Title::newFromText( $name ); + + if ( $title->getArticleID( Title::GAID_FOR_UPDATE ) == 0 ) { + ParserTest::addArticle( $name, $text ); + } + } + $this->articles = array(); + } + + public function addArticle( $name, $text, $line ) { + $this->articles[$name] = $text; + } } diff --git a/maintenance/tests/phpunit/includes/parser/ParserHelpers.php b/maintenance/tests/phpunit/includes/parser/ParserHelpers.php index 3fbd78b684..43da34218b 100644 --- a/maintenance/tests/phpunit/includes/parser/ParserHelpers.php +++ b/maintenance/tests/phpunit/includes/parser/ParserHelpers.php @@ -33,6 +33,7 @@ class ParserUnitTest extends PHPUnit_Framework_TestCase { $result = new PHPUnit_Framework_TestResult; } + $this->suite->publishTestArticles(); // Add articles needed by the tests. $backend = new ParserTestSuiteBackend; $result->startTest( $this ); diff --git a/maintenance/tests/testHelpers.inc b/maintenance/tests/testHelpers.inc index 5d6bdec234..71479e570f 100644 --- a/maintenance/tests/testHelpers.inc +++ b/maintenance/tests/testHelpers.inc @@ -536,10 +536,11 @@ class TestFileIterator implements Iterator { wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" ); } - $title = Title::newFromText( ParserTest::chomp( $data['article'] ) ); - $aid = $title->getArticleID( Title::GAID_FOR_UPDATE ); - if ( $aid == 0 ) + if ( $this->parser ) { + $this->parser->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum ); + } else { ParserTest::addArticle( $data['article'], $data['text'], $this->lineNum ); + } $data = array(); $section = null;