You are here

function EntityTranslationTaxonomyAutocompleteTestCase::testInPlaceTranslation in Entity Translation 7

Tests that in-place translation works as expected.

File

tests/entity_translation.test, line 1298
Tests for Entity translation module.

Class

EntityTranslationTaxonomyAutocompleteTestCase
Tests for the taxonomy autocomplete translation modes.

Code

function testInPlaceTranslation() {
  $this
    ->enableInPlaceTranslation();
  $this
    ->login($this
    ->getTranslatorUser(array(
    'administer taxonomy',
  )));
  $values = array(
    'Red' => 'Rosso',
    'Green' => 'Verde',
    'Blue' => 'Blu',
  );

  // Create an English node with a few new tags.
  $edit = array(
    'title' => 'Test 1',
    'field_test_tags[' . LANGUAGE_NONE . ']' => implode(', ', array_keys($values)),
    'language' => 'en',
  );
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $node = $this
    ->drupalGetNodeByTitle($edit['title']);

  // Create an Italian translation and translate the English tags.
  $this
    ->drupalGet('node/' . $node->nid . '/translate');
  $this
    ->clickLink('add', 1);
  $edit = array();
  foreach (array_values($values) as $delta => $value) {
    $edit['field_test_tags[' . LANGUAGE_NONE . '][' . $delta . ']'] = $value;
  }
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Verify that the Italian values are correctly stored/displayed.
  foreach ($values as $original => $translation) {
    $this
      ->assertRaw($translation);
  }

  // Verify that the original English values were correctly retained.
  $this
    ->drupalGet('node/' . $node->nid);
  foreach ($values as $original => $translation) {
    $this
      ->assertRaw($original);
  }
}