You are here

public function RangeInternationalizationWebTestCase::testRangeFieldFormatterRespectsInterfaceLanguage in Range 7

Verifies that range module field formatters respect interface language.

File

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

Class

RangeInternationalizationWebTestCase
Tests translatability of range fields.

Code

public function testRangeFieldFormatterRespectsInterfaceLanguage() {
  $account = $this
    ->drupalCreateUser(array(
    'administer content types',
    'administer nodes',
  ));
  $this
    ->drupalLogin($account);

  // Translate field instance settings.
  $this
    ->translateRangeFieldInstanceSettings();

  // Create a test node.
  $from_value = $to_value = 10;
  $node = $this
    ->createTestNode(array(
    'from' => $from_value,
    'to' => $to_value,
  ));
  $languages = language_list();

  // First, test with combined value off.
  //
  // Test default language (field instance settings should be in the original
  // language - English).
  $this
    ->drupalGet("node/{$node->nid}", array(
    'language' => $languages[static::PRIMARY_LANGUAGE],
  ));
  $original_formatted_field_value_array = array(
    static::INSTANCE_SETTINGS_FIELD_PREFIX,
    static::INSTANCE_SETTINGS_FROM_PREFIX,
    $from_value,
    static::INSTANCE_SETTINGS_FROM_SUFFIX,
    '-',
    static::INSTANCE_SETTINGS_TO_PREFIX,
    $to_value,
    static::INSTANCE_SETTINGS_TO_SUFFIX,
    static::INSTANCE_SETTINGS_FIELD_SUFFIX,
  );
  $original_formatted_field_value = implode('', $original_formatted_field_value_array);
  $this
    ->assertText($original_formatted_field_value, format_string('Correct original formatted range field value %value found on the page', array(
    '%value' => $original_formatted_field_value,
  )));

  // Test secondary language (field instance settings should be translated to
  // the secondary language).
  $this
    ->drupalGet("node/{$node->nid}", array(
    'language' => $languages[static::SECONDARY_LANGUAGE],
  ));
  $translated_formatted_field_value_array = array(
    static::INSTANCE_SETTINGS_FIELD_PREFIX_TRANSLATED,
    static::INSTANCE_SETTINGS_FROM_PREFIX_TRANSLATED,
    $from_value,
    static::INSTANCE_SETTINGS_FROM_SUFFIX_TRANSLATED,
    '-',
    static::INSTANCE_SETTINGS_TO_PREFIX_TRANSLATED,
    $to_value,
    static::INSTANCE_SETTINGS_TO_SUFFIX_TRANSLATED,
    static::INSTANCE_SETTINGS_FIELD_SUFFIX_TRANSLATED,
  );
  $translated_formatted_field_value = implode('', $translated_formatted_field_value_array);
  $this
    ->assertText($translated_formatted_field_value, format_string('Correct translated formatted range field value %value found on the page', array(
    '%value' => $translated_formatted_field_value,
  )));

  // Then test again with combined value on.
  $instance = field_info_instance('node', $this
    ->getTestFieldName(), $this->contentType);
  $instance['display']['default']['settings']['range_combine'] = TRUE;
  $instance['display']['default']['settings']['combined_prefix_suffix'] = TRUE;
  field_update_instance($instance);

  // Test default language (field instance settings should be in the original
  // language - English).
  $this
    ->drupalGet("node/{$node->nid}", array(
    'language' => $languages[static::PRIMARY_LANGUAGE],
  ));
  $original_formatted_field_value_array = array(
    static::INSTANCE_SETTINGS_FIELD_PREFIX,
    static::INSTANCE_SETTINGS_COMBINED_PREFIX,
    $from_value,
    static::INSTANCE_SETTINGS_COMBINED_SUFFIX,
    static::INSTANCE_SETTINGS_FIELD_SUFFIX,
  );
  $original_formatted_field_value = implode('', $original_formatted_field_value_array);
  $this
    ->assertText($original_formatted_field_value, format_string('Correct original formatted range field value %value found on the page', array(
    '%value' => $original_formatted_field_value,
  )));

  // Test secondary language (field instance settings should be translated to
  // the secondary language).
  $this
    ->drupalGet("node/{$node->nid}", array(
    'language' => $languages[static::SECONDARY_LANGUAGE],
  ));
  $translated_formatted_field_value_array = array(
    static::INSTANCE_SETTINGS_FIELD_PREFIX_TRANSLATED,
    static::INSTANCE_SETTINGS_COMBINED_PREFIX_TRANSLATED,
    $from_value,
    static::INSTANCE_SETTINGS_COMBINED_SUFFIX_TRANSLATED,
    static::INSTANCE_SETTINGS_FIELD_SUFFIX_TRANSLATED,
  );
  $translated_formatted_field_value = implode('', $translated_formatted_field_value_array);
  $this
    ->assertText($translated_formatted_field_value, format_string('Correct translated formatted range field value %value found on the page', array(
    '%value' => $translated_formatted_field_value,
  )));
}