https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108316

Revision: 108316
Author:   ialex
Date:     2012-01-07 12:19:10 +0000 (Sat, 07 Jan 2012)
Log Message:
-----------
* 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()

Modified Paths:
--------------
    trunk/phase3/tests/parser/parserTest.inc
    trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php

Modified: trunk/phase3/tests/parser/parserTest.inc
===================================================================
--- trunk/phase3/tests/parser/parserTest.inc    2012-01-07 10:37:13 UTC (rev 
108315)
+++ trunk/phase3/tests/parser/parserTest.inc    2012-01-07 12:19:10 UTC (rev 
108316)
@@ -1162,29 +1162,34 @@
         * @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;

Modified: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php        
2012-01-07 10:37:13 UTC (rev 108315)
+++ trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php        
2012-01-07 12:19:10 UTC (rev 108316)
@@ -698,7 +698,7 @@
        //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 @@
                        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' );
                }
        }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to