You are here

protected function RangeFieldUIWebTestCase::_testRangeFieldSettingsUI in Range 7

Helper method. Sets range field 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::_testRangeFieldSettingsUI()
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 81
Contains range field UI tests.

Class

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

Code

protected function _testRangeFieldSettingsUI($field_type = 'range_integer') {
  $field_name = $this
    ->getTestFieldName($field_type);
  switch ($field_type) {
    case 'range_integer':
      $edit = array();
      break;
    case 'range_float':
      $edit = array(
        'field[settings][decimal_separator]' => static::FIELD_SETTINGS_DECIMAL_SEPARATOR,
      );
      break;
    case 'range_decimal':
      $edit = array(
        'field[settings][decimal_separator]' => static::FIELD_SETTINGS_DECIMAL_SEPARATOR,
        'field[settings][precision]' => static::FIELD_SETTINGS_PRECISION,
        'field[settings][scale]' => static::FIELD_SETTINGS_SCALE,
      );
      break;
    default:
      $edit = array();
  }

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

  // Clear field info cache.
  field_info_cache_clear();

  // Ensure that all field settings were saved correctly.
  $field = field_info_field($field_name);
  $settings = $field['settings'];
  switch ($field_type) {
    case 'range_float':
      $this
        ->assertEqual($settings['decimal_separator'], static::FIELD_SETTINGS_DECIMAL_SEPARATOR, format_string('Correct decimal separator setting %value found for the %field_type field type', array(
        '%value' => $settings['decimal_separator'],
        '%field_type' => $field['type'],
      )));
      break;
    case 'range_decimal':
      $this
        ->assertEqual($settings['decimal_separator'], static::FIELD_SETTINGS_DECIMAL_SEPARATOR, format_string('Correct decimal separator setting %value found for the %field_type field type', array(
        '%value' => $settings['decimal_separator'],
        '%field_type' => $field['type'],
      )));
      $this
        ->assertEqual($settings['precision'], static::FIELD_SETTINGS_PRECISION, format_string('Correct precision setting %value found for the %field_type field type', array(
        '%value' => $settings['precision'],
        '%field_type' => $field['type'],
      )));
      $this
        ->assertEqual($settings['scale'], static::FIELD_SETTINGS_SCALE, format_string('Correct scale setting %value found for the %field_type field type', array(
        '%value' => $settings['scale'],
        '%field_type' => $field['type'],
      )));
      break;
  }
}