diff --git a/includes/salsa_entity.mock.inc b/includes/salsa_entity.mock.inc index 2e5dfa7..2cbe364 100644 --- a/includes/salsa_entity.mock.inc +++ b/includes/salsa_entity.mock.inc @@ -87,6 +87,81 @@ class SalsaAPIMock extends SalsaAPI implements SalsaAPIInterface { EOF; } + elseif (($query[0] == 'object=supporter') && isset($query[1]) && + (($query[1] == 'condition=supporter_KEY=2'))) { + $response = << + + + + 2 + 11111 + + Mon May 21 2012 11:56:46 GMT-0400 (EDT) + Mon May 20 2012 16:48:23 GMT-0400 (EDT) + Mr + First Name + + Last Name + + example@example.com + d41d8cd98f00b204e9800998ecf8427e + 1 + + + 0 + 0 + + false + false + + + + + + + + Example Street + + + Example City + + 1000 + 0000 + + + CH + 0.000000 + 0.000000 + + + + + + + + + + + + Web + (No Referring info) + (No Original Source Available) + + + + eng + + + + 2 + supporter + + 1 + + +EOF; + } elseif ($script == '/api/getObjects.sjs' && $query[0] == 'object=signup_page') { $response = << diff --git a/salsa_entity.module b/salsa_entity.module index 4b52212..f6b1826 100644 --- a/salsa_entity.module +++ b/salsa_entity.module @@ -237,8 +237,8 @@ function salsa_entity_salsa_object_type_info() { * Necessary to set the language property on supporter objects upon saving and * updating. */ -function salsa_entity_entity_presave($entity, $type) { - if ($type == 'salsa_supporter' && variable_get('salsa_entity_set_supporter_language', TRUE)) { +function salsa_entity_salsa_supporter_presave($entity) { + if (variable_get('salsa_entity_set_supporter_language', TRUE)) { // Set the code only for supporters that don't have any language code yet. if (empty($entity->Language_Code)) { $lang_code = SalsaEntityLanguageMapper::toIso639_2(); diff --git a/tests/salsa_entity.test b/tests/salsa_entity.test index 89d38e1..721a0f1 100644 --- a/tests/salsa_entity.test +++ b/tests/salsa_entity.test @@ -75,7 +75,7 @@ class SalsaEntityTranslationTestCase extends SalsaEntityBaseTestCase { } public function setUp() { - parent::setUp(array('salsa_event')); + parent::setUp(array('salsa_event', 'locale', 'salsa_entity')); } /** @@ -105,4 +105,50 @@ class SalsaEntityTranslationTestCase extends SalsaEntityBaseTestCase { $this->assertEqual($event2->getTranslation('Event_Name', 'de'), $event2->Event_Name); } + /** + * Check whether language is saved proper on supporter objects. + */ + function testSupporterLanguageStorage() { + global $language; + $language = (object) array( + 'language' => 'de', + 'name' => 'German', + 'native' => 'Deutsch', + 'direction' => 0, + 'enabled' => 1, + 'plurals' => 0, + 'formula' => '', + 'domain' => '', + 'prefix' => '', + 'weight' => 0, + 'javascript' => '', + ); + $supporter_id = 1; + + // Disable language storage on supporter objects and make sure the language + // code isn't saved. + variable_set('salsa_entity_set_supporter_language', FALSE); + $supporter = entity_load_single('salsa_supporter', $supporter_id); + $supporter->save(); + $mock = variable_get('salsa_entity_mock_saved'); + $this->assertTrue(empty($mock['supporter'][$supporter_id]['Language_Code'])); + + // Now enable language storage on supporter objects and test if the language + // code gets saved. + variable_set('salsa_entity_set_supporter_language', TRUE); + $supporter = entity_load_single('salsa_supporter', $supporter_id); + $supporter->save(); + $mock = variable_get('salsa_entity_mock_saved'); + $this->assertEqual($mock['supporter'][$supporter_id]['Language_Code'], SalsaEntityLanguageMapper::toIso639_2($language->language)); + + // Load a supporter that already has a language code set to "eng" and test + // that the language code doesn't get overridden with "ger", the current + // language. + $supporter_id = 2; + $supporter = entity_load_single('salsa_supporter', $supporter_id); + $supporter->save(); + $mock = variable_get('salsa_entity_mock_saved'); + $this->assertEqual($supporter->Language_Code, $mock['supporter'][$supporter_id]['Language_Code']); + } + }