From e1a47de20eceec154893e7ff7c3a8e9f187d7188 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 22 Oct 2009 00:30:21 +0000 Subject: [PATCH] BUGFIX Fixing regression in TranslatableTest due to outdated singleton caching. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89911 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- dev/SapphireTest.php | 18 ++++++++---------- tests/ObjectTest.php | 7 +++++++ tests/model/TranslatableTest.php | 10 +++++----- tests/search/TranslatableSearchFormTest.php | 6 +++--- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 579a1d7f5..0b4ec7fca 100755 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -65,11 +65,6 @@ class SapphireTest extends PHPUnit_Framework_TestCase { DataObject::reset(); SiteTree::reset(); Controller::curr()->setSession(new Session(array())); - - // clear singletons, they're caching old extension info - // which is used in DatabaseAdmin->doBuild() - global $_SINGLETONS; - $_SINGLETONS = array(); $className = get_class($this); $fixtureFile = eval("return {$className}::\$fixture_file;"); @@ -119,6 +114,10 @@ class SapphireTest extends PHPUnit_Framework_TestCase { * for tearing down the state again. */ static function set_up_once() { + // clear singletons, they're caching old extension info + // which is used in DatabaseAdmin->doBuild() + global $_SINGLETONS; + $_SINGLETONS = array(); } /** @@ -228,11 +227,6 @@ class SapphireTest extends PHPUnit_Framework_TestCase { } function tearDown() { - // clear singletons, they're caching old extension info - // which is used in DatabaseAdmin->doBuild() - global $_SINGLETONS; - $_SINGLETONS = array(); - // Restore email configuration Email::set_mailer($this->originalMailer); $this->originalMailer = null; @@ -250,6 +244,10 @@ class SapphireTest extends PHPUnit_Framework_TestCase { } static function tear_down_once() { + // clear singletons, they're caching old extension info + // which is used in DatabaseAdmin->doBuild() + global $_SINGLETONS; + $_SINGLETONS = array(); } /** diff --git a/tests/ObjectTest.php b/tests/ObjectTest.php index 809835f4f..392050f61 100755 --- a/tests/ObjectTest.php +++ b/tests/ObjectTest.php @@ -9,6 +9,13 @@ */ class ObjectTest extends SapphireTest { + function setUp() { + parent::setUp(); + + global $_SINGLETONS; + $_SINGLETONS = array(); + } + function testHasmethodBehaviour() { /* SiteTree should have all of the methods that Versioned has, because Versioned is listed in SiteTree's * extensions */ diff --git a/tests/model/TranslatableTest.php b/tests/model/TranslatableTest.php index 4fd5fb1e0..fdb080932 100755 --- a/tests/model/TranslatableTest.php +++ b/tests/model/TranslatableTest.php @@ -15,11 +15,13 @@ class TranslatableTest extends FunctionalTest { static protected $origTranslatableSettings = array(); static function set_up_once() { + parent::set_up_once(); + // needs to recreate the database schema with language properties self::kill_temp_db(); // store old defaults - self::$origTranslatableSettings['has_extension'] = singleton('SiteTree')->hasExtension('Translatable'); + self::$origTranslatableSettings['has_extension'] = Object::has_extension('SiteTree', 'Translatable'); self::$origTranslatableSettings['default_locale'] = Translatable::default_locale(); // overwrite locale @@ -28,12 +30,10 @@ class TranslatableTest extends FunctionalTest { // refresh the decorated statics - different fields in $db with Translatable enabled if(!self::$origTranslatableSettings['has_extension']) Object::add_extension('SiteTree', 'Translatable'); Object::add_extension('TranslatableTest_DataObject', 'Translatable'); - + // recreate database with new settings $dbname = self::create_temp_db(); DB::set_alternative_database_name($dbname); - - parent::set_up_once(); } static function tear_down_once() { @@ -832,7 +832,7 @@ class TranslatableTest extends FunctionalTest { )); $form->saveInto($frPage); $frPage->write(); - + $this->assertEquals('Translated', $frPage->Title); $this->assertEquals(array($group->ID), $frPage->ViewerGroups()->column('ID')); diff --git a/tests/search/TranslatableSearchFormTest.php b/tests/search/TranslatableSearchFormTest.php index 875a7aaa9..e3b3a8a18 100644 --- a/tests/search/TranslatableSearchFormTest.php +++ b/tests/search/TranslatableSearchFormTest.php @@ -15,11 +15,13 @@ class TranslatableSearchFormTest extends FunctionalTest { static protected $origTranslatableSettings = array(); static function set_up_once() { + parent::set_up_once(); + // needs to recreate the database schema with language properties self::kill_temp_db(); // store old defaults - self::$origTranslatableSettings['has_extension'] = singleton('SiteTree')->hasExtension('Translatable'); + self::$origTranslatableSettings['has_extension'] = Object::has_extension('SiteTree', 'Translatable'); self::$origTranslatableSettings['default_locale'] = Translatable::default_locale(); // overwrite locale @@ -32,8 +34,6 @@ class TranslatableSearchFormTest extends FunctionalTest { // recreate database with new settings $dbname = self::create_temp_db(); DB::set_alternative_database_name($dbname); - - parent::set_up_once(); } function setUp() {