<?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
*
* Clears $wgUser, and reports errors from addDBData to PHPUnit
*/
- function setUp() {
+ public function setUp() {
global $wgUser;
parent::setUp();
$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.
*
* @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" );
$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,
$this->assertNodeEnd( "text" );
$this->skipWhitespace();
}
-
- $this->assertTextNode( "sha1", $text_sha1 );
-
- $this->assertNodeEnd( "revision" );
- $this->skipWhitespace();
}
-
}