Merge "Made WikiPage recall the source of the data used to load its state."
[lhc/web/wiklou.git] / tests / phpunit / maintenance / DumpTestCase.php
index a6fe549..fd39c45 100644 (file)
@@ -69,25 +69,12 @@ abstract class DumpTestCase extends MediaWikiTestCase {
                        file_put_contents( $fname, $contents ), "# bytes written" );
        }
 
-       /**
-        * obtains a new temporary file name
-        *
-        * The obtained filename is enlisted to be removed upon tearDown
-        *
-        * @returns string: absolute name of the temporary file
-        */
-       protected function getNewTempFile() {
-               $fname = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
-               $this->tmpfiles[] = $fname;
-               return $fname;
-       }
-
        /**
         * Default set up function.
         *
         * Clears $wgUser, and reports errors from addDBData to PHPUnit
         */
-       function setUp() {
+       protected function setUp() {
                global $wgUser;
 
                parent::setUp();
@@ -97,26 +84,31 @@ abstract class DumpTestCase extends MediaWikiTestCase {
                if ( $this->exceptionFromAddDBData !== null ) {
                        throw $this->exceptionFromAddDBData;
                }
-               $this->tmpfiles = array();
 
                $wgUser = new User();
        }
 
        /**
-        * Default tear down function
-        *
-        * Removes all files that have been allocated via self::getNewTempFile, even if
-        * they turn out to be (empty or non-empty) directories now.
+        * Checks for test output consisting only of lines containing ETA announcements
         */
-       function tearDown() {
-               foreach ( $this->tmpfiles as $fname ) {
-                       if ( is_file( $fname ) || ( is_link( $fname ) ) ) {
-                               unlink( $fname );
-                       } elseif ( is_dir( $fname ) ) {
-                               wfRecursiveRemoveDir( $fname );
-                       }
+       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 );
                }
-               parent::tearDown();
        }