You are here

public function EntityTranslationUpgradeTestCase::testUpgradeContentToEntityTranslation in Entity Translation 7

Tests copying of source node's body value in the add translation form page.

File

entity_translation_upgrade/entity_translation_upgrade.test, line 114
Tests for Entity Translation module.

Class

EntityTranslationUpgradeTestCase
Tests for the upgrade translation process.

Code

public function testUpgradeContentToEntityTranslation() {

  // Create Basic page in English.
  $node_title = $this
    ->randomName();
  $node_body = $this
    ->randomName();
  $node = $this
    ->createContentTranslationPage($node_title, $node_body, 'en');

  // Submit translation in Spanish.
  $this
    ->drupalGet('node/' . $node->nid . '/translate');
  $node_translation_title = $this
    ->randomName();
  $node_translation_body = $this
    ->randomName();
  $node_translation = $this
    ->createContentTranslationTranslation($node, $node_translation_title, $node_translation_body, 'es');

  // Make Body field translatable before we run the upgrade.
  $this
    ->login($this
    ->getAdminUser());
  $this
    ->makeBodyFieldTranslatable();

  // Run the upgrade for all Page nodes.
  $edit = array(
    'types[page]' => 'page',
  );
  $this
    ->drupalPost('admin/config/regional/entity_translation', $edit, t('Upgrade'));

  // Switch to our translator user.
  $this
    ->login($this
    ->getTranslatorUser());

  // Check that the unpublished target node triggers a redirect.
  $this
    ->drupalGet('node/' . $node_translation->nid);
  $headers = $this
    ->drupalGetHeaders(TRUE);
  list(, $status) = explode(' ', $headers[0][':status'], 3);
  $this
    ->assertEqual($status, 301, 'Expected response code was sent.');
  $languages = language_list();
  $this
    ->assertEqual($this
    ->getUrl(), url('node/' . $node->nid, array(
    'absolute' => TRUE,
    'language' => $languages['es'],
  )), 'entity_translation_upgrade_redirect() redirected to expected URL.');

  // Check that the body is displayed when the active language is English.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw($node_body, t('Body field displayed correctly in the source language.'));

  // Check that the translated body is displayed when the active language is Spanish.
  $this
    ->drupalGet('es/node/' . $node->nid);
  $this
    ->assertRaw($node_translation_body, t('Body field displayed correctly in the target language.'));

  // Check that the edit forms are initialized correctly in the target language.
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertFieldByXPath("//textarea[@name='body[en][0][value]']", $node_body, "Body field correctly instantiated with the value of the source language.");
  $this
    ->drupalGet('es/node/' . $node->nid . '/edit');
  $this
    ->assertFieldByXPath("//textarea[@name='body[es][0][value]']", $node_translation_body, "Body field correctly instantiated with the value of the target language.");
}