function i18nFieldTestCase::testListFieldTranslation in Internationalization 7
Test the translation of list fields, including allowed values.
File
- i18n_field/
i18n_field.test, line 27 - Test case for multilingual fields.
Class
- i18nFieldTestCase
- @file Test case for multilingual fields.
Code
function testListFieldTranslation() {
$field_name = drupal_strtolower($this
->randomName());
$label = $this
->randomName();
$description = $this
->randomName();
$value = $this
->randomName();
$field = array(
'field_name' => $field_name,
'type' => 'list_integer',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(
1 => $value,
),
),
);
$field = field_create_field($field);
$instance = array(
'field_name' => $field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'label' => $label,
'description' => $description,
'widget' => array(
'type' => 'options_buttons',
),
);
$instance = field_create_instance($instance);
// Refresh i18n_strings.
$edit = array(
'groups[field]' => TRUE,
);
$this
->drupalPost('admin/config/regional/translate/i18n_string', $edit, t('Refresh strings'));
// Save translations for each attribute.
$label_translation = $this
->createStringTranslation('field', $label);
$description_translation = $this
->createStringTranslation('field', $description);
$value_translation = $this
->createStringTranslation('field', $value);
$this
->drupalLogin($this->admin_user);
// Test untranslated values in default language.
$this
->drupalGet('test-entity/add/test-bundle');
$this
->assertText($label, 'Field label is not translated');
$this
->assertText($description, 'Field description is not translated');
$this
->assertText($value, 'Field allowed values are not translated');
// Test translated values in secondary language.
$this
->drupalGet($this->secondary_language . '/test-entity/add/test-bundle');
$this
->assertText($label_translation[$this->secondary_language], 'Field label is translated');
$this
->assertText($description_translation[$this->secondary_language], 'Field description is translated');
$this
->assertText($value_translation[$this->secondary_language], 'Field allowed values are translated');
}