Tests the basic translation workflow.
protected function assertBasicTranslation() {
// Create a new test entity with original values in the default language.
$default_langcode = $this->langcodes[0];
$values[$default_langcode] = $this
->getNewEntityValues($default_langcode);
$this->entityId = $this
->createEntity($values[$default_langcode], $default_langcode);
$entity = entity_load($this->entityType, $this->entityId, TRUE);
$this
->assertTrue($entity, t('Entity found in the database.'));
$translation = $this
->getTranslation($entity, $default_langcode);
foreach ($values[$default_langcode] as $property => $value) {
$stored_value = $this
->getValue($translation, $property, $default_langcode);
$value = is_array($value) ? $value[0]['value'] : $value;
$message = format_string('@property correctly stored in the default language.', array(
'@property' => $property,
));
$this
->assertEqual($stored_value, $value, $message);
}
// Add an entity translation.
$langcode = 'it';
$values[$langcode] = $this
->getNewEntityValues($langcode);
$base_path = $this->controller
->getBasePath($entity);
$path = $langcode . '/' . $base_path . '/translations/add/' . $default_langcode . '/' . $langcode;
$this
->drupalPost($path, $this
->getEditValues($values, $langcode), $this
->getFormSubmitAction($entity));
if ($this->testLanguageSelector) {
$this
->assertNoFieldByXPath('//select[@id="edit-langcode"]', NULL, 'Language selector correclty disabled on translations.');
}
$entity = entity_load($this->entityType, $this->entityId, TRUE);
// Switch the source language.
$langcode = 'fr';
$source_langcode = 'it';
$edit = array(
'source_langcode[source]' => $source_langcode,
);
$path = $langcode . '/' . $base_path . '/translations/add/' . $default_langcode . '/' . $langcode;
$this
->drupalPost($path, $edit, t('Change'));
$this
->assertFieldByXPath("//input[@name=\"{$this->fieldName}[fr][0][value]\"]", $values[$source_langcode][$this->fieldName][0]['value'], 'Source language correctly switched.');
// Add another translation and mark the other ones as outdated.
$values[$langcode] = $this
->getNewEntityValues($langcode);
$edit = $this
->getEditValues($values, $langcode) + array(
'translation_entity[retranslate]' => TRUE,
);
$this
->drupalPost($path, $edit, $this
->getFormSubmitAction($entity));
$entity = entity_load($this->entityType, $this->entityId, TRUE);
// Check that the entered values have been correctly stored.
foreach ($values as $langcode => $property_values) {
$translation = $this
->getTranslation($entity, $langcode);
foreach ($property_values as $property => $value) {
$stored_value = $this
->getValue($translation, $property, $langcode);
$value = is_array($value) ? $value[0]['value'] : $value;
$message = format_string('%property correctly stored with language %language.', array(
'%property' => $property,
'%language' => $langcode,
));
$this
->assertEqual($stored_value, $value, $message);
}
}
}