Follow up r75810. The code for the parser tests modified the main database even when...
authorPlatonides <platonides@users.mediawiki.org>
Fri, 5 Nov 2010 20:03:18 +0000 (20:03 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Fri, 5 Nov 2010 20:03:18 +0000 (20:03 +0000)
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

maintenance/tests/parser/parserTest.inc
maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php
maintenance/tests/phpunit/includes/parser/ParserHelpers.php
maintenance/tests/testHelpers.inc

index da07b9c..381c265 100644 (file)
@@ -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);
index f6fabe1..a8d105a 100644 (file)
@@ -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;
+       }
 }
 
index 3fbd78b..43da342 100644 (file)
@@ -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 );
 
index 5d6bdec..71479e5 100644 (file)
@@ -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;