From 40c98e0ad1035d7006c5740e13ced123f0fa4c7c Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 7 Jan 2012 12:19:10 +0000 Subject: [PATCH] * Don't select (even twice for PHPUnit tests) "FOR UPDATE", but use the master database directly instead * 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 | 21 ++++++++++++------- .../phpunit/includes/parser/NewParserTest.php | 11 ++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index 5584596648..ac557a35fd 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -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; diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index c4ccececde..5065ba0f27 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -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' ); } } -- 2.20.1