You are here

public function EntityTranslationToggleFieldsTranslatabilityTestCase::testTogglingFieldsWithDataNonRevisionable in Entity Translation 7

Tests toggling translatability on fields with data (non-revisionable).

File

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

Class

EntityTranslationToggleFieldsTranslatabilityTestCase
Tests for enabling fields to use Entity Translation or disabling them.

Code

public function testTogglingFieldsWithDataNonRevisionable() {

  // Create an untranslated Basic page.
  $node_title = $this
    ->randomName();
  $node_body = $this
    ->randomName();
  $node = $this
    ->createUntranslatedPage($node_title, $node_body);
  $this
    ->assert(isset($node->body[LANGUAGE_NONE]), t('Found body field data in LANGUAGE_NONE as expected.'));
  $this
    ->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $node_body);

  // Create an untranslated Tags term.
  $term_name = $this
    ->randomName();
  $term_description = $this
    ->randomName();
  $term_simple_text = $this
    ->randomName();
  $term = $this
    ->createUntranslatedTag($term_name, $term_description, $term_simple_text);
  $this
    ->assert(isset($term->field_simple_text[LANGUAGE_NONE]), t('Found field data in LANGUAGE_NONE as expected.'));
  $this
    ->assertEqual($term->field_simple_text[LANGUAGE_NONE][0]['value'], $term_simple_text);

  // Enable translation for field body and check field migration.
  $this
    ->login($this
    ->getAdminUser());
  $this
    ->drupalGet('admin/structure/types/manage/page/fields/body');
  $this
    ->clickLink('Enable translation');
  $this
    ->drupalPost(NULL, array(), t('Confirm'));
  $node = current(entity_load('node', FALSE, array(
    'title' => $node_title,
  ), TRUE));
  $this
    ->assert(isset($node->body['en']), t('Found field data in English as expected.'));
  $this
    ->assertEqual($node->body['en'][0]['value'], $node_body);
  $this
    ->assert(!isset($node->body[LANGUAGE_NONE]), t('No field data in LANGUAGE_NONE found.'));

  // Disable translation for body field and check field reverse migration.
  $this
    ->drupalGet('admin/structure/types/manage/page/fields/body');
  $this
    ->clickLink('Disable translation');
  $this
    ->drupalPost(NULL, array(), t('Confirm'));
  $node = current(entity_load('node', FALSE, array(
    'title' => $node_title,
  ), TRUE));
  $this
    ->assert(isset($node->body[LANGUAGE_NONE]), t('Found field data in LANGUAGE_NONE as expected.'));
  $this
    ->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $node_body);
  $this
    ->assert(!isset($node->body['en']), t('No field data in English found.'));

  // Enable translation for field_simple_text and check field migration.
  $this
    ->drupalGet('admin/structure/taxonomy/tags/fields/field_simple_text');
  $this
    ->clickLink('Enable translation');
  $this
    ->drupalPost(NULL, array(), t('Confirm'));

  // Clear the field cache in order to load current field data.
  field_info_cache_clear();

  // Load the term and check that the fields data are under 'en'.
  $term = current(entity_load('taxonomy_term', FALSE, array(
    'name' => $term_name,
  ), TRUE));
  $this
    ->assert(isset($term->field_simple_text['en']), t('Found field data in English as expected.'));
  $this
    ->assertEqual($term->field_simple_text['en'][0]['value'], $term_simple_text);
  $this
    ->assert(!isset($term->field_simple_text[LANGUAGE_NONE]), t('No field data in LANGUAGE_NONE found.'));

  // Disable translation for field_simple_text.
  $this
    ->drupalGet('admin/structure/taxonomy/tags/fields/field_simple_text');
  $this
    ->clickLink('Disable translation');
  $this
    ->drupalPost(NULL, array(), t('Confirm'));

  // Load the term and check that the fields data are under LANGUAGE_NONE.
  $term = current(entity_load('taxonomy_term', FALSE, array(
    'name' => $term_name,
  ), TRUE));
  $this
    ->assert(isset($term->field_simple_text[LANGUAGE_NONE]), t('Found field data in LANGUAGE_NONE as expected.'));
  $this
    ->assertEqual($term->field_simple_text[LANGUAGE_NONE][0]['value'], $term_simple_text);
  $this
    ->assert(!isset($term->field_simple_text['en']), t('No field data in English found.'));
}