Merge "Get better error message for duplicate names in MagicWordArray"
[lhc/web/wiklou.git] / tests / phpunit / maintenance / DumpTestCase.php
index 415e11b..99bd427 100644 (file)
@@ -19,24 +19,46 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
        protected $exceptionFromAddDBData = null;
 
        /**
-        * Holds the xmlreader used for analyzing an xml dump
+        * Holds the XMLReader used for analyzing an XML dump
         *
         * @var XMLReader|null
         */
        protected $xml = null;
 
+       /** @var bool|null Whether the 'gzip' utility is available */
+       protected static $hasGzip = null;
+
+       /**
+        * Skip the test if 'gzip' is not in $PATH.
+        *
+        * @return bool
+        */
+       protected function checkHasGzip() {
+               if ( self::$hasGzip === null ) {
+                       self::$hasGzip = ( Installer::locateExecutableInDefaultPaths( 'gzip' ) !== false );
+               }
+
+               if ( !self::$hasGzip ) {
+                       $this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
+               }
+
+               return self::$hasGzip;
+       }
+
        /**
         * Adds a revision to a page, while returning the resuting revision's id
         *
         * @param Page $page Page to add the revision to
         * @param string $text Revisions text
-        * @param string $summary Revisions summare
-        * @return array
+        * @param string $summary Revisions summary
+        * @param string $model The model ID (defaults to wikitext)
+        *
         * @throws MWException
+        * @return array
         */
-       protected function addRevision( Page $page, $text, $summary ) {
+       protected function addRevision( Page $page, $text, $summary, $model = CONTENT_MODEL_WIKITEXT ) {
                $status = $page->doEditContent(
-                       ContentHandler::makeContent( $text, $page->getTitle() ),
+                       ContentHandler::makeContent( $text, $page->getTitle(), $model ),
                        $summary
                );
 
@@ -47,11 +69,12 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
                        $text_id = $revision->getTextId();
 
                        if ( ( $revision_id > 0 ) && ( $text_id > 0 ) ) {
-                               return array( $revision_id, $text_id );
+                               return [ $revision_id, $text_id ];
                        }
                }
 
-               throw new MWException( "Could not determine revision id (" . $status->getWikiText() . ")" );
+               throw new MWException( "Could not determine revision id ("
+                       . $status->getWikiText( false, false, 'en' ) . ")" );
        }
 
        /**
@@ -100,7 +123,7 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
                // expectOutput[...] functions. However, the PHPUnit shipped prediactes
                // do not allow to check /each/ line of the output using /readable/ REs.
                // So we ...
-               //
+
                // 1. ... add a dummy output checking to make PHPUnit not complain
                //    about unchecked test output
                $this->expectOutputRegex( '//' );
@@ -275,7 +298,6 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
         * @param string $name Title of the current page
         */
        protected function assertPageStart( $id, $ns, $name ) {
-
                $this->assertNodeStart( "page" );
                $this->skipWhitespace();
 
@@ -370,7 +392,6 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
                        if ( ( $this->xml->nodeType == XMLReader::END_ELEMENT )
                                && ( $this->xml->name == "text" )
                        ) {
-
                                $this->xml->read();
                        }
                        $this->skipWhitespace();