Permalink
Browse files

FIXED: Issue where $enable_siteconfig_generation flag was not being s…

…et correctly, causing failed test cases_

FIXED: Duplicate entries in test database
  • Loading branch information...
1 parent 405fa7e commit a3b3ec8c4eb69928729d43fb5183d0228c2a056b @tractorcow tractorcow committed with chillu Aug 16, 2012
Showing with 21 additions and 60 deletions.
  1. +21 −17 code/model/Translatable.php
  2. +0 −43 tests/unit/TranslatableSiteConfigTest.yml
@@ -1131,13 +1131,6 @@ function getTranslation($locale, $stage = null) {
$translations = $this->getTranslations($locale, $stage);
return ($translations) ? $translations->First() : null;
}
-
- /**
- * Enables automatic population of SiteConfig fields using createTranslation if
- * created outside of the Translatable module
- * @var boolean
- */
- public static $enable_siteconfig_generation = true;
/**
* When the SiteConfig object is automatically instantiated, we should ensure that
@@ -1150,12 +1143,14 @@ function getTranslation($locale, $stage = null) {
* @see SiteConfig
*/
protected function populateSiteConfig() {
- // This is required to prevent infinite loop during createTranslation
- // If createTranslation is called directly on SiteConfig then this function could
- // be called twice, but it will not cause harm for this to happen.
- if(!self::$enable_siteconfig_generation)
+
+ // Work-around for population of defaults during test setup (when tables are not created).
+ // When the database is being setup during testing, singleton('SiteConfig') is called.
+ // Singleton objects should not call populateDefault() but a bug seems to be allowing it
+ // to happen anyway. Looking up existing SiteConfig objects without a database crashes horribly
+ // @todo Remove this hack once this bug is fixed
+ if(SapphireTest::using_temp_db() && !DB::getConn()->hasTable($this->owner->class))
return;
- self::$enable_siteconfig_generation = false;
// Find the best base translation for site config
Translatable::disable_locale_filter();
@@ -1181,19 +1176,28 @@ protected function populateSiteConfig() {
// Copy fields from translated object (including ID) to the generated object
// This is similar to the creation of objects via createTranslation, but we need to
- // preserve the ID in order to prevent
+ // preserve the ID in order to prevent unnecessary object creation
$this->owner->update($stagingConfig->toMap());
-
- // Re-enable config generation
- self::$enable_siteconfig_generation = true;
}
+
+ /**
+ * Enables automatic population of SiteConfig fields using createTranslation if
+ * created outside of the Translatable module
+ * @var boolean
+ */
+ public static $enable_siteconfig_generation = true;
/**
* Hooks into the DataObject::populateDefaults() method
*/
public function populateDefaults() {
- if (empty($this->owner->ID) && $this->owner instanceof SiteConfig)
+ if (empty($this->owner->ID) && ($this->owner instanceof SiteConfig) && self::$enable_siteconfig_generation)
+ {
+ // Use enable_siteconfig_generation to prevent infinite loop during
+ self::$enable_siteconfig_generation = false;
$this->populateSiteConfig();
+ self::$enable_siteconfig_generation = true;
+ }
}
/**
@@ -40,47 +40,4 @@ SiteConfig:
Title: Meine Test Seite
Locale: de_DE
CanEditType: OnlyTheseUsers
- EditorGroups: =>Group.translators_de
-Permission:
- cmsmain1:
- Code: CMS_ACCESS_CMSMain
- cmsmain2:
- Code: CMS_ACCESS_CMSMain
- translate_all1:
- Code: TRANSLATE_ALL
- translate_all2:
- Code: TRANSLATE_ALL
-Group:
- translators_de:
- Code: translators_de
- Permissions: =>Permission.cmsmain1,=>Permission.translate_all1
- translators_en:
- Code: translators_en
- Permissions: =>Permission.cmsmain2,=>Permission.translate_all2
-Member:
- translator_de:
- Email: translator_de@test.com
- Password: test
- Groups: =>Group.translators_de
- translator_en:
- Email: translator_en@test.com
- Password: test
- Groups: =>Group.translators_en
- websiteuser:
- Email: websiteuser@test.com
- Password: test
-Page:
- root_en:
- URLSegment: root-en
- Locale: en_US
-SiteConfig:
- en_US:
- Title: My test site
- Locale: en_US
- CanEditType: OnlyTheseUsers
- EditorGroups: =>Group.translators_en
- de_DE:
- Title: Meine Test Seite
- Locale: de_DE
- CanEditType: OnlyTheseUsers
EditorGroups: =>Group.translators_de

0 comments on commit a3b3ec8

Please sign in to comment.