From 5f6bee22ba820602f85a3aad928cc49bbe92cc61 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 11 Aug 2009 04:45:54 +0000 Subject: [PATCH] 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 --- core/model/DataObject.php | 8 ++++++++ core/model/Translatable.php | 10 ++++++++++ core/model/Versioned.php | 11 +++++++++++ dev/SapphireTest.php | 9 ++++++--- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index a0dafd1d3..06adcb9de 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -2648,6 +2648,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity } 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() diff --git a/core/model/Translatable.php b/core/model/Translatable.php index 4b22ac5c1..8d7164af8 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -194,6 +194,16 @@ class Translatable extends DataObjectDecorator { */ 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. * diff --git a/core/model/Versioned.php b/core/model/Versioned.php index b33cddaea..008ded85e 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -68,6 +68,17 @@ class Versioned extends DataObjectDecorator { 'AuthorID' => 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. diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 0636a7cdf..c5cbd65b9 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -50,6 +50,12 @@ class SapphireTest extends PHPUnit_Framework_TestCase { $this->originalRequirements = Requirements::backend(); Member::set_password_validator(null); 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); $fixtureFile = eval("return {$className}::\$fixture_file;"); @@ -62,9 +68,6 @@ class SapphireTest extends PHPUnit_Framework_TestCase { //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(); $dbadmin = new DatabaseAdmin();