[bug 37746] string ids for content model and format.
[lhc/web/wiklou.git] / tests / phpunit / maintenance / DumpTestCase.php
index 2f8c232..f573c74 100644 (file)
@@ -1,11 +1,9 @@
 <?php
-global $IP;
-require_once( "$IP/maintenance/backup.inc" );
 
 /**
  * Base TestCase for dumps
  */
-abstract class DumpTestCase extends MediaWikiTestCase {
+abstract class DumpTestCase extends MediaWikiLangTestCase {
 
        /**
         * exception to be rethrown once in sound PHPUnit surrounding
@@ -74,7 +72,7 @@ abstract class DumpTestCase extends MediaWikiTestCase {
         *
         * Clears $wgUser, and reports errors from addDBData to PHPUnit
         */
-       function setUp() {
+       public function setUp() {
                global $wgUser;
 
                parent::setUp();
@@ -88,6 +86,30 @@ abstract class DumpTestCase extends MediaWikiTestCase {
                $wgUser = new User();
        }
 
+       /**
+        * Checks for test output consisting only of lines containing ETA announcements
+        */
+       function expectETAOutput() {
+               // Newer PHPUnits require assertion about the output using PHPUnit's own
+               // 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( '//' );
+
+               // 2. Do the real output checking on our own.
+               $lines = explode( "\n", $this->getActualOutput() );
+               $this->assertGreaterThan( 1, count( $lines ), "Minimal lines of produced output" );
+               $this->assertEquals( '', array_pop( $lines ), "Output ends in LF" );
+               $timestamp_re = "[0-9]{4}-[01][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-6][0-9]";
+               foreach ( $lines as $line ) {
+                       $this->assertRegExp( "/$timestamp_re: .* \(ID [0-9]+\) [0-9]* pages .*, [0-9]* revs .*, ETA/", $line );
+               }
+       }
+
+
        /**
         * Step the current XML reader until node end of given name is found.
         *
@@ -273,13 +295,20 @@ abstract class DumpTestCase extends MediaWikiTestCase {
         * @param $text_sha1 string: the base36 SHA-1 of the revision's text
         * @param $text string|false: (optional) The revision's string, or false to check for a
         *            revision stub
+        * @param $model String: the expected content model id (default: CONTENT_MODEL_WIKITEXT)
+        * @param $format String: the expected format model id (default: CONTENT_FORMAT_WIKITEXT)
+        * @param $parentid int|false: (optional) id of the parent revision
         */
-       protected function assertRevision( $id, $summary, $text_id, $text_bytes, $text_sha1, $text = false ) {
+       protected function assertRevision( $id, $summary, $text_id, $text_bytes, $text_sha1, $text = false, $parentid = false,
+                                               $model = CONTENT_MODEL_WIKITEXT, $format = CONTENT_FORMAT_WIKITEXT ) {
 
                $this->assertNodeStart( "revision" );
                $this->skipWhitespace();
 
                $this->assertTextNode( "id", $id );
+               if( $parentid ) {
+                       $this->assertTextNode( "parentid", $parentid );
+               }
                $this->assertTextNode( "timestamp", false );
 
                $this->assertNodeStart( "contributor" );
@@ -289,14 +318,39 @@ abstract class DumpTestCase extends MediaWikiTestCase {
                $this->skipWhitespace();
 
                $this->assertTextNode( "comment", $summary );
+               $this->skipWhitespace();
+
+               if ( $this->xml->name == "text" ) {
+                       // note: <text> tag may occur here or at the very end.
+                       $text_found = true;
+                       $this->assertText( $id, $text_id, $text_bytes, $text );
+               } else {
+                       $text_found = false;
+               }
+
+               $this->assertTextNode( "sha1", $text_sha1 );
+
+               $this->assertTextNode( "model", $model );
+               $this->skipWhitespace();
 
+               $this->assertTextNode( "format", $format );
+               $this->skipWhitespace();
+
+               if ( !$text_found ) {
+                       $this->assertText( $id, $text_id, $text_bytes, $text );
+               }
+
+               $this->assertNodeEnd( "revision" );
+               $this->skipWhitespace();
+       }
+
+       protected function assertText( $id, $text_id, $text_bytes, $text ) {
                $this->assertNodeStart( "text", false );
                if ( $text_bytes !== false ) {
                        $this->assertEquals( $this->xml->getAttribute( "bytes" ), $text_bytes,
                                "Attribute 'bytes' of revision " . $id );
                }
 
-
                if ( $text === false ) {
                        // Testing for a stub
                        $this->assertEquals( $this->xml->getAttribute( "id" ), $text_id,
@@ -317,11 +371,5 @@ abstract class DumpTestCase extends MediaWikiTestCase {
                        $this->assertNodeEnd( "text" );
                        $this->skipWhitespace();
                }
-
-               $this->assertTextNode( "sha1", $text_sha1 );
-
-               $this->assertNodeEnd( "revision" );
-               $this->skipWhitespace();
        }
-
 }