protected function FieldCollectionEntityTranslationTestCase::createTranslationForm in Field collection 7
Create a translation using the Entity Translation Form.
Parameters
mixed $node: Node of the basic page to create translation for.
string $langcode: The language code of the translation.
string $source_langcode: The original language code.
1 call to FieldCollectionEntityTranslationTestCase::createTranslationForm()
- FieldCollectionEntityTranslationTestCase::testEntityTranslation in ./
field_collection.test - Ensures the right behaviour in all Entity Translation use cases.
File
- ./
field_collection.test, line 931 - Tests for field_collections.
Class
- FieldCollectionEntityTranslationTestCase
- Test using field collection with content that gets translated with Entity Translation.
Code
protected function createTranslationForm($node, $langcode, $source_langcode = 'en') {
$language_none = LANGUAGE_NONE;
$edit = array();
$this
->drupalGet('node/' . $node->nid . '/edit/add/' . $source_langcode . '/' . $langcode);
// Get the field collection in the original language.
$fc_values = $node->{$this->field_name}[$source_langcode];
// Check if all the fields were populated and fill it with the new value.
foreach ($fc_values as $delta => $fc_value) {
// Load the field collection item.
$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_dest}";
$this
->assertFieldByXPath("//input[@name='{$fc_untrans_key}']", $fc_item->{$this->field_untrans_name}[LANGUAGE_NONE][0]['value'], 'Original value of untranslatable field correctly populated');
$this
->assertFieldByXPath("//input[@name='{$fc_trans_key}']", $fc_item->{$this->field_trans_name}['en'][0]['value'], 'Original value of translatable field correctly populated');
$edit[$fc_untrans_key] = self::UNTRANS_FIELD_DE . '_' . $delta;
$edit[$fc_trans_key] = self::TRANS_FIELD_DE . '_' . $delta;
}
// Save the translation.
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/translate');
$this
->assertLinkByHref('node/' . $node->nid . '/edit/' . $langcode, 0, t('Translation edit link found. Translation created.'));
// Reload the node.
$node = node_load($node->nid, NULL, TRUE);
// Check the values of the translated field.
$this
->checkFieldCollectionContent($node, $langcode);
// Check the values of the field in the original language.
$this
->checkFieldCollectionContent($node, $source_langcode);
return $node;
}