You are here

public function RangeInternationalizationWebTestCase::testRangeFieldFormErrorsRespectInterfaceLanguage in Range 7

Verify that range field form widget errors respect interface language.

File

tests/range.i18n.test, line 259
Contains range i18n tests.

Class

RangeInternationalizationWebTestCase
Tests translatability of range fields.

Code

public function testRangeFieldFormErrorsRespectInterfaceLanguage() {
  $account = $this
    ->drupalCreateUser(array(
    "create {$this->contentType} content",
  ));
  $this
    ->drupalLogin($account);

  // Translate field instance settings.
  $this
    ->translateRangeFieldInstanceSettings();
  $languages = language_list();
  $field_name = $this
    ->getTestFieldName();
  $form_element_key = $field_name . '[' . LANGUAGE_NONE . '][0]';

  // Test default language (field instance settings should be in the original
  // language - English).
  //
  // Test widget validation error messages.
  $edit = array(
    "{$form_element_key}[from]" => 'A',
    "{$form_element_key}[to]" => 'Z',
  );
  $this
    ->drupalPost("node/add/{$this->contentType}", $edit, t('Save'), array(
    'language' => $languages[static::PRIMARY_LANGUAGE],
  ));
  $error_message = t('Only numbers are allowed in %field.', array(
    '%field' => static::INSTANCE_SETTINGS_FROM_LABEL,
  ));
  $this
    ->assertRaw($error_message, format_string('Correct original widget validation error message found on the page: !error_message', array(
    '!error_message' => $error_message,
  )));
  $error_message = t('Only numbers are allowed in %field.', array(
    '%field' => static::INSTANCE_SETTINGS_TO_LABEL,
  ));
  $this
    ->assertRaw($error_message, format_string('Correct original widget validation error message found on the page: !error_message', array(
    '!error_message' => $error_message,
  )));

  // Test field validation error messages.
  $edit = array(
    "{$form_element_key}[from]" => '10',
    "{$form_element_key}[to]" => '',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $error_message = t('%name: you must specify two values.', array(
    '%name' => static::INSTANCE_LABEL,
  ));
  $this
    ->assertRaw($error_message, format_string('Correct original field validation error message found on the page: !error_message', array(
    '!error_message' => $error_message,
  )));

  // Test secondary language (field instance settings should be translated to
  // the secondary language).
  //
  // Test widget validation error messages.
  $edit = array(
    "{$form_element_key}[from]" => 'A',
    "{$form_element_key}[to]" => 'A',
  );
  $this
    ->drupalPost("node/add/{$this->contentType}", $edit, t('Save'), array(
    'language' => $languages[static::SECONDARY_LANGUAGE],
  ));
  $error_message = t('Only numbers are allowed in %field.', array(
    '%field' => static::INSTANCE_SETTINGS_FROM_LABEL_TRANSLATED,
  ));
  $this
    ->assertRaw($error_message, format_string('Correct translated widget validation error message found on the page: !error_message', array(
    '!error_message' => $error_message,
  )));
  $error_message = t('Only numbers are allowed in %field.', array(
    '%field' => static::INSTANCE_SETTINGS_TO_LABEL_TRANSLATED,
  ));
  $this
    ->assertRaw($error_message, format_string('Correct translated widget validation error message found on the page: !error_message', array(
    '!error_message' => $error_message,
  )));

  // Test field validation error messages.
  $edit = array(
    "{$form_element_key}[from]" => '10',
    "{$form_element_key}[to]" => '',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $error_message = t('%name: you must specify two values.', array(
    '%name' => static::INSTANCE_LABEL_TRANSLATED,
  ));
  $this
    ->assertRaw($error_message, format_string('Correct translated field validation error message found on the page: !error_message', array(
    '!error_message' => $error_message,
  )));
}