You are here

public function I18nFieldPlaceholderTestCase::testFieldPlaceholderTranslation in Field placeholder 7.2

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

Test the translation of text fields.

File

i18n_field_placeholder/i18n_field_placeholder.test, line 88

Class

I18nFieldPlaceholderTestCase

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');

  // Test Label as placeholder feature.
  $edit = array(
    'instance[use_title_as_placeholder]' => 1,
  );
  $this
    ->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/fields/field_' . $field_name, $edit, t('Save settings'));

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

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