* Don't select (even twice for PHPUnit tests) "FOR UPDATE", but use the master databa...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 7 Jan 2012 12:19:10 +0000 (12:19 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 7 Jan 2012 12:19:10 +0000 (12:19 +0000)
* Also pass the line number
* Removed useless usage of $title when throwing the exception about invalid since that variable is always null
* Added $ignoreDuplicate parameter to ParserTest::addArticle()

tests/parser/parserTest.inc
tests/phpunit/includes/parser/NewParserTest.php

index 5584596..ac557a3 100644 (file)
@@ -1162,29 +1162,34 @@ class ParserTest {
         * @param $name String: the title, including any prefix
         * @param $text String: the article text
         * @param $line Integer: the input line number, for reporting errors
+        * @param $ignoreDuplicate Boolean: whether to silently ignore duplicate pages
         */
-       static public function addArticle( $name, $text, $line = 'unknown' ) {
+       static public function addArticle( $name, $text, $line = 'unknown', $ignoreDuplicate = '' ) {
                global $wgCapitalLinks;
 
-               $text = self::chomp($text);
-
                $oldCapitalLinks = $wgCapitalLinks;
                $wgCapitalLinks = true; // We only need this from SetupGlobals() See r70917#c8637
 
+               $text = self::chomp( $text );
                $name = self::chomp( $name );
+
                $title = Title::newFromText( $name );
 
                if ( is_null( $title ) ) {
-                       throw new MWException( "invalid title ('$name' => '$title') at line $line\n" );
+                       throw new MWException( "invalid title '$name' at line $line\n" );
                }
 
-               $aid = $title->getArticleID( Title::GAID_FOR_UPDATE );
+               $page = WikiPage::factory( $title );
+               $page->loadPageData( 'fromdbmaster' );
 
-               if ( $aid != 0 ) {
-                       throw new MWException( "duplicate article '$name' at line $line\n" );
+               if ( $page->exists() ) {
+                       if ( $ignoreDuplicate == 'ignoreduplicate' ) {
+                               return;
+                       } else {
+                               throw new MWException( "duplicate article '$name' at line $line\n" );
+                       }
                }
 
-               $page = WikiPage::factory( $title );
                $page->doEdit( $text, '', EDIT_NEW );
 
                $wgCapitalLinks = $oldCapitalLinks;
index c4ccece..5065ba0 100644 (file)
@@ -698,7 +698,7 @@ class NewParserTest extends MediaWikiTestCase {
        //Various action functions
 
        public function addArticle( $name, $text, $line ) {
-               self::$articles[$name] = $text;
+               self::$articles[$name] = array( $text, $line );
        }
 
        public function publishTestArticles() {
@@ -706,12 +706,9 @@ class NewParserTest extends MediaWikiTestCase {
                        return;
                }
 
-               foreach ( self::$articles as $name => $text ) {
-                       $title = Title::newFromText( $name );
-
-                       if ( $title->getArticleID( Title::GAID_FOR_UPDATE ) == 0 ) {
-                               ParserTest::addArticle( $name, $text );
-                       }
+               foreach ( self::$articles as $name => $info ) {
+                       list( $text, $line ) = $info;
+                       ParserTest::addArticle( $name, $text, $line, 'ignoreduplicate' );
                }
        }