BUGFIX: Added static resetting methods for more reliable test execution.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84147 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-08-11 04:45:54 +00:00
parent 6f0a1e9d36
commit 5f6bee22ba
4 changed files with 35 additions and 3 deletions

View File

@ -2649,6 +2649,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
self::$cache_get_one = array(); self::$cache_get_one = array();
} }
/**
* Reset internal caches, for example after test runs
*/
static function reset() {
self::$cache_get_one = array();
self::$cache_buildSQL_query = array();
}
/** /**
* Does the hard work for get_one() * Does the hard work for get_one()
* *

View File

@ -194,6 +194,16 @@ class Translatable extends DataObjectDecorator {
*/ */
protected static $allowed_locales = null; protected static $allowed_locales = null;
/**
* Reset static configuration variables to their default values
*/
static function reset() {
self::$default_locale = 'en_US';
self::$current_locale = null;
self::$enable_lang_filter = true;
self::$allowed_locales = null;
}
/** /**
* Choose the language the site is currently on. * Choose the language the site is currently on.
* *

View File

@ -69,6 +69,17 @@ class Versioned extends DataObjectDecorator {
'PublisherID' => true, 'PublisherID' => true,
); );
/**
* Reset static configuration variables to their default values
*/
static function reset() {
self::$reading_stage = null;
self::$reading_archived_date = null;
Session::clear('currentStage');
Session::clear('archiveDate');
}
/** /**
* Construct a new Versioned object. * Construct a new Versioned object.
* @var array $stages The different stages the versioned object can be. * @var array $stages The different stages the versioned object can be.

View File

@ -51,6 +51,12 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
Member::set_password_validator(null); Member::set_password_validator(null);
Cookie::set_report_errors(false); Cookie::set_report_errors(false);
// Reset Translatable and Versioned
Translatable::reset();
Versioned::reset();
DataObject::reset();
Controller::curr()->setSession(new Session(array()));
$className = get_class($this); $className = get_class($this);
$fixtureFile = eval("return {$className}::\$fixture_file;"); $fixtureFile = eval("return {$className}::\$fixture_file;");
@ -62,9 +68,6 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
//echo "done.\n"; //echo "done.\n";
} }
// This code is a bit misplaced; we want some way of the whole session being reinitialised...
Versioned::reading_stage(null);
singleton('DataObject')->flushCache(); singleton('DataObject')->flushCache();
$dbadmin = new DatabaseAdmin(); $dbadmin = new DatabaseAdmin();