You are here

protected function RangeFieldUIWebTestCase::_testRangeFieldFormatterSettingsUI in Range 7

Helper method. Sets range field formatter settings via field UI.

Parameters

string $field_type: Range field type. Could be one of the following values: range_integer, range_float or range_decimal.

1 call to RangeFieldUIWebTestCase::_testRangeFieldFormatterSettingsUI()
RangeFieldUIWebTestCase::_testRangeFieldUI in tests/range.field_ui.test
Helper method. Tests given range field type via field UI.

File

tests/range.field_ui.test, line 193
Contains range field UI tests.

Class

RangeFieldUIWebTestCase
Tests adding range fields and their settings via field UI.

Code

protected function _testRangeFieldFormatterSettingsUI($field_type = 'range_integer') {
  $field_name = $this
    ->getTestFieldName($field_type);
  switch ($field_type) {
    case 'range_integer':
      $formatters = array(
        'range_integer',
        'range_integer_sprintf',
      );
      break;
    case 'range_float':
    case 'range_decimal':
      $formatters = array(
        'range_decimal',
        'range_decimal_sprintf',
      );
      break;
    default:
      $formatters = array();
  }
  $formatters[] = 'range_unformatted';
  $this
    ->drupalGet("admin/structure/types/manage/{$this->contentType}/display");
  foreach ($formatters as $formatter) {
    $edit = array(
      "fields[{$field_name}][type]" => $formatter,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $this
      ->drupalPostAJAX(NULL, array(), "{$field_name}_formatter_settings_edit");
    switch ($formatter) {
      case 'range_integer':
        $edit = array(
          "fields[{$field_name}][settings_edit_form][settings][thousand_separator]" => static::FORMATTER_SETTING_THOUSAND_SEPARATOR,
        );
        break;
      case 'range_decimal':
        $edit = array(
          "fields[{$field_name}][settings_edit_form][settings][thousand_separator]" => static::FORMATTER_SETTING_THOUSAND_SEPARATOR,
          "fields[{$field_name}][settings_edit_form][settings][decimal_separator]" => static::FORMATTER_SETTING_DECIMAL_SEPARATOR,
          "fields[{$field_name}][settings_edit_form][settings][scale]" => static::FORMATTER_SETTING_SCALE,
        );
        break;
      case 'range_integer_sprintf':
      case 'range_decimal_sprintf':
        $edit = array(
          "fields[{$field_name}][settings_edit_form][settings][format_string]" => static::FORMATTER_SETTING_FORMAT_STRING,
        );
        break;
    }
    $edit += array(
      "fields[{$field_name}][settings_edit_form][settings][range_separator]" => static::FORMATTER_SETTING_RANGE_SEPARATOR,
      "fields[{$field_name}][settings_edit_form][settings][range_combine]" => static::FORMATTER_SETTING_RANGE_COMBINE,
      "fields[{$field_name}][settings_edit_form][settings][from_prefix_suffix]" => static::FORMATTER_SETTING_FROM_PREFIX_SUFFIX,
      "fields[{$field_name}][settings_edit_form][settings][to_prefix_suffix]" => static::FORMATTER_SETTING_TO_PREFIX_SUFFIX,
      "fields[{$field_name}][settings_edit_form][settings][field_prefix_suffix]" => static::FORMATTER_SETTING_FIELD_PREFIX_SUFFIX,
      "fields[{$field_name}][settings_edit_form][settings][combined_prefix_suffix]" => static::FORMATTER_SETTING_COMBINED_PREFIX_SUFFIX,
    );
    $this
      ->drupalPostAJAX(NULL, $edit, array(
      $this
        ->getTestFieldName($field_type) . '_formatter_settings_update' => t('Update'),
    ));

    // Save field settings via field UI.
    $this
      ->drupalPost(NULL, array(), t('Save'));

    // Clear field info cache.
    field_info_cache_clear();

    // Ensure that all field formatter settings were saved correctly.
    $field = field_info_field($field_name);
    $instance = field_info_instance('node', $field_name, $this->contentType);
    $settings = $instance['display']['default']['settings'];
    switch ($formatter) {
      case 'range_integer':
        $this
          ->assertEqual($settings['thousand_separator'], static::FORMATTER_SETTING_THOUSAND_SEPARATOR, format_string('Correct thousand separator setting %value found for the %formatter_type formater (%field_type field type)', array(
          '%value' => $settings['thousand_separator'],
          '%formatter_type' => $formatter,
          '%field_type' => $field['type'],
        )));
        break;
      case 'range_decimal':
        $this
          ->assertEqual($settings['thousand_separator'], static::FORMATTER_SETTING_THOUSAND_SEPARATOR, format_string('Correct thousand separator setting %value found for the %formatter_type formater (%field_type field type)', array(
          '%value' => $settings['thousand_separator'],
          '%formatter_type' => $formatter,
          '%field_type' => $field['type'],
        )));
        $this
          ->assertEqual($settings['decimal_separator'], static::FORMATTER_SETTING_DECIMAL_SEPARATOR, format_string('Correct decimal separator setting %value found for the %formatter_type formater (%field_type field type)', array(
          '%value' => $settings['decimal_separator'],
          '%formatter_type' => $formatter,
          '%field_type' => $field['type'],
        )));
        $this
          ->assertEqual($settings['scale'], static::FORMATTER_SETTING_SCALE, format_string('Correct scale setting %value found for the %formatter_type formater (%field_type field type)', array(
          '%value' => $settings['scale'],
          '%formatter_type' => $formatter,
          '%field_type' => $field['type'],
        )));
        break;
      case 'range_integer_sprintf':
      case 'range_decimal_sprintf':
        $this
          ->assertEqual($settings['format_string'], static::FORMATTER_SETTING_FORMAT_STRING, format_string('Correct format string %value found for the %formatter_type formater (%field_type field type)', array(
          '%value' => $settings['format_string'],
          '%formatter_type' => $formatter,
          '%field_type' => $field['type'],
        )));
        break;
    }
    $this
      ->assertEqual($settings['range_separator'], static::FORMATTER_SETTING_RANGE_SEPARATOR, format_string('Correct range separator setting %value found for the %formatter_type formater (%field_type field type)', array(
      '%value' => $settings['range_separator'],
      '%formatter_type' => $formatter,
      '%field_type' => $field['type'],
    )));
    $this
      ->assertEqual($settings['range_combine'], static::FORMATTER_SETTING_RANGE_COMBINE, format_string('Correct combine equivalent values setting %value found for the %formatter_type formater (%field_type field type)', array(
      '%value' => $settings['range_combine'],
      '%formatter_type' => $formatter,
      '%field_type' => $field['type'],
    )));
    $this
      ->assertEqual($settings['from_prefix_suffix'], static::FORMATTER_SETTING_FROM_PREFIX_SUFFIX, format_string('Correct display FROM prefix/suffix setting %value found for the %formatter_type formater (%field_type field type)', array(
      '%value' => $settings['from_prefix_suffix'],
      '%formatter_type' => $formatter,
      '%field_type' => $field['type'],
    )));
    $this
      ->assertEqual($settings['to_prefix_suffix'], static::FORMATTER_SETTING_TO_PREFIX_SUFFIX, format_string('Correct display TO prefix/suffix setting %value found for the %formatter_type formater (%field_type field type)', array(
      '%value' => $settings['to_prefix_suffix'],
      '%formatter_type' => $formatter,
      '%field_type' => $field['type'],
    )));
    $this
      ->assertEqual($settings['field_prefix_suffix'], static::FORMATTER_SETTING_FIELD_PREFIX_SUFFIX, format_string('Correct display FIELD prefix/suffix setting %value found for the %formatter_type formater (%field_type field type)', array(
      '%value' => $settings['field_prefix_suffix'],
      '%formatter_type' => $formatter,
      '%field_type' => $field['type'],
    )));
    $this
      ->assertEqual($settings['combined_prefix_suffix'], static::FORMATTER_SETTING_COMBINED_PREFIX_SUFFIX, format_string('Correct display COMBINED prefix/suffix setting %value found for the %formatter_type formater (%field_type field type)', array(
      '%value' => $settings['combined_prefix_suffix'],
      '%formatter_type' => $formatter,
      '%field_type' => $field['type'],
    )));
  }
}