diff --git a/field_collection.info b/field_collection.info index 59b1dd1..d3d408b 100644 --- a/field_collection.info +++ b/field_collection.info @@ -2,6 +2,7 @@ name = Field collection description = Provides a field collection field, to which any number of fields can be attached. core = 7.x dependencies[] = entity +test_dependencies[] = entity_translation files[] = field_collection.test files[] = field_collection.entity.inc files[] = field_collection.info.inc diff --git a/field_collection.test b/field_collection.test index feda2b1..88ff2a5 100644 --- a/field_collection.test +++ b/field_collection.test @@ -626,6 +626,7 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { 'administer blocks', 'access administration pages', 'administer site configuration', + 'administer entity translation', ), $permissions)); } return $this->admin_user; @@ -729,6 +730,11 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { ); $this->instance = field_create_instance($this->instance); + // Enable entity translation of field collections + $this->drupalGet('admin/config/regional/entity_translation'); + $this->drupalPost('admin/config/regional/entity_translation', array('entity_translation_entity_types[field_collection_item]' => TRUE), t('Save configuration')); + $this->assertRaw(t('The configuration options have been saved.'), t('Entity translation of field collections enabled.')); + // Add an untraslatable field to the collection $this->field_untrans_name = 'field_text_untrans'; $this->field_untrans_base = "[{$this->field_untrans_name}][$language_none][0][value]"; @@ -753,6 +759,7 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { // Add a translatable field to the collection $this->field_trans_name = 'field_text_trans'; $this->field_trans_base = "[{$this->field_trans_name}][$language_none][0][value]"; + $this->field_trans_dest = "[{$this->field_trans_name}][de][0][value]"; $field = array( 'field_name' => $this->field_trans_name, 'type' => 'text', @@ -791,7 +798,7 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { $this->drupalGet('node/add/page'); $edit = array(); - $edit["title"] = $title; + $edit['title'] = $title; for ($i = 0; $i < $num_values; $i++) { if ($i != 0) { $this->drupalPost(NULL, array(), t('Add another item')); @@ -834,9 +841,10 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { // Check if all the fields were well populated and fill it later with the new value foreach ($fc_values as $delta => $fc_value) { // Load the field collection item - $fc_item = reset(entity_load('field_collection_item', array($fc_value['value']))); + $fc_item_array = entity_load('field_collection_item', array($fc_value['value'])); + $fc_item = reset($fc_item_array); $fc_untrans_key = "{$this->field_name}[$langcode][$delta]{$this->field_untrans_base}"; - $fc_trans_key = "{$this->field_name}[$langcode][$delta]{$this->field_trans_base}"; + $fc_trans_key = "{$this->field_name}[$langcode][$delta]{$this->field_trans_dest}"; $this->assertFieldByXPath( "//input[@name='$fc_untrans_key']", $fc_item->{$this->field_untrans_name}[LANGUAGE_NONE][0]['value'], @@ -844,7 +852,7 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { ); $this->assertFieldByXPath( "//input[@name='$fc_trans_key']", - $fc_item->{$this->field_trans_name}[LANGUAGE_NONE][0]['value'], + $fc_item->{$this->field_trans_name}['en'][0]['value'], 'Original value of translatable field correctly populated' ); @@ -1041,12 +1049,13 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { foreach ($fc_values as $delta => $fc_value) { // Load the field collection item - $fc_item = reset(entity_load('field_collection_item', array($fc_value['value']))); + $fc_item_array = entity_load('field_collection_item', array($fc_value['value'])); + $fc_item = reset($fc_item_array); $fc_untrans_key = "{$this->field_name}[$langcode][$delta]{$this->field_untrans_base}"; $fc_trans_key = "{$this->field_name}[$langcode][$delta]{$this->field_trans_base}"; $this->assertEqual($untrans_field . '_' . $delta, $fc_item->{$this->field_untrans_name}[LANGUAGE_NONE][0]['value']); - $this->assertEqual($trans_field . '_' . $delta, $fc_item->{$this->field_trans_name}[LANGUAGE_NONE][0]['value']); + $this->assertEqual($trans_field . '_' . $delta, $fc_item->{$this->field_trans_name}[$langcode][0]['value']); } } @@ -1064,11 +1073,12 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase { if (isset($node->{$this->field_name}[$langcode][$delta]['value'])) { $fc_item_id = $node->{$this->field_name}[$langcode][$delta]['value']; // Load the field collection - $fc_item = reset(entity_load('field_collection_item', array($fc_item_id))); + $fc_item_array = entity_load('field_collection_item', array($fc_item_id)); + $fc_item = reset($fc_item_array); $return = array( 'field_untrans' => $fc_item->{$this->field_untrans_name}[LANGUAGE_NONE][0]['value'], - 'field_trans' => $fc_item->{$this->field_trans_name}[LANGUAGE_NONE][0]['value'], + 'field_trans' => $fc_item->{$this->field_trans_name}[$langcode][0]['value'], ); }