1.20.x field.test FieldTranslationsTestCase::testFieldFormTranslationRevisions()

Tests field translations when creating a new revision.

File

modules/field/tests/field.test, line 3104
Tests for field.module.

Class

FieldTranslationsTestCase
Unit test class for the multilanguage fields logic.

Code

function testFieldFormTranslationRevisions() {
  $web_user = $this->backdropCreateUser(array('access field_test content', 'administer field_test content'));
  $this->backdropLogin($web_user);

  // Prepare the field translations.
  field_test_entity_info_translatable($this->entity_type, TRUE);
  $eid = 1;
  $entity = field_test_create_entity($eid, $eid, $this->instance['bundle']);
  $available_languages = array_flip(field_available_languages($this->entity_type, $this->field));
  unset($available_languages[LANGUAGE_NONE]);
  $field_name = $this->field['field_name'];

  // Store the field translations.
  $entity->is_new = TRUE;
  foreach ($available_languages as $langcode => $value) {
    $entity->{$field_name}[$langcode][0]['value'] = $value + 1;
  }
  field_test_entity_save($entity);

  // Create a new revision.
  $langcode = field_valid_language(NULL);
  $edit = array("{$field_name}[$langcode][0][value]" => $entity->{$field_name}[$langcode][0]['value'], 'revision' => TRUE);
  $this->backdropPost('test-entity/manage/' . $eid . '/edit', $edit, t('Save'));

  // Check translation revisions.
  $this->checkTranslationRevisions($eid, $eid, $available_languages);
  $this->checkTranslationRevisions($eid, $eid + 1, $available_languages);
}