You are here

public function I18nFieldPlaceholderTestCase::testFieldPlaceholderTranslation in Field placeholder 7

Same name and namespace in other branches
  1. 7.2 i18n_field_placeholder/i18n_field_placeholder.test \I18nFieldPlaceholderTestCase::testFieldPlaceholderTranslation()

Test the translation of text fields.

File

i18n_field_placeholder/i18n_field_placeholder.test, line 84
File that holds multilingual tests for Field placeholder module.

Class

I18nFieldPlaceholderTestCase
@file File that holds multilingual tests for Field placeholder module.

Code

public function testFieldPlaceholderTranslation() {
  $field_name = drupal_strtolower($this
    ->randomName());
  $label = $this
    ->randomName();
  $placeholder = $this
    ->randomName();
  $bundle_path1 = 'admin/structure/types/manage/' . $this->hyphen_type;

  // Create a basic text field.
  $edit = array(
    'fields[_add_new_field][type]' => 'text',
    'fields[_add_new_field][widget_type]' => 'text_textfield',
    'fields[_add_new_field][label]' => $label,
    'fields[_add_new_field][field_name]' => $field_name,
  );
  $instance_settings = array(
    'instance[placeholder]' => $placeholder,
  );
  $this
    ->fieldUIAddNewField($bundle_path1, $edit, array(), $instance_settings);

  // 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);
  $placeholder_translation = $this
    ->createStringTranslation('field', $placeholder);
  $this
    ->drupalLogin($this->admin_user);

  // Test untranslated values in default language.
  $this
    ->drupalGet('node/add/' . $this->hyphen_type);
  $this
    ->assertText($label, 'Field label is not translated');
  $this
    ->assertRaw('placeholder="' . $placeholder, 'Field description is not translated');

  // Test translated values in secondary language.
  $this
    ->drupalGet($this->secondary_language . '/node/add/' . $this->hyphen_type);
  $this
    ->assertText($label_translation[$this->secondary_language], 'Field label is translated');
  $this
    ->assertRaw('placeholder="' . $placeholder_translation[$this->secondary_language], 'Field description is translated');
}