diff --git a/core/model/Versioned.php b/core/model/Versioned.php index 2b0ea87fe..328bbd21e 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -154,6 +154,14 @@ class Versioned extends DataObjectDecorator { * @todo Reduce the coupling between this and SapphireTest, somehow. */ public static function on_db_reset() { + // Drop all temporary tables + $db = DB::getConn(); + foreach(self::$archive_tables as $tableName) { + if(method_exists($db, 'dropTable')) $db->dropTable($tableName); + else $db->query("DROP TABLE \"$tableName\""); + } + + // Remove references to them self::$archive_tables = array(); } diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 10bf825a6..2c49b5bcf 100755 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -111,10 +111,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase { } singleton('DataObject')->flushCache(); - - $dbadmin = new DatabaseAdmin(); - $dbadmin->clearAllData(); + self::empty_temp_db(); + $fixtureFiles = (is_array($fixtureFile)) ? $fixtureFile : array($fixtureFile); $i = 0; @@ -329,6 +328,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase { // Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls self::$is_running_test = $this->originalIsRunningTest; $this->originalIsRunningTest = null; + + // Reset mocked datetime + SSDatetime::clear_mock_now(); } /** * Clear the log of emails sent @@ -551,6 +553,20 @@ class SapphireTest extends PHPUnit_Framework_TestCase { } } + /** + * Remove all content from the temporary database. + */ + static function empty_temp_db() { + if(self::using_temp_db()) { + $dbadmin = new DatabaseAdmin(); + $dbadmin->clearAllData(); + + // Todo: it would be good to remove this inappropriate coupling, somehow. + // The versioned class keeps a static cache of information about temporary tables. + Versioned::on_db_reset(); + } + } + /** * @todo Make this db agnostic */