You are here

protected function RangeBaseWebTestCase::createTestRangeField in Range 7

Creates a range field of a given type.

Parameters

string $field_type: Range field type. Possible values:

  • range_decimal
  • range_float
  • range_integer
5 calls to RangeBaseWebTestCase::createTestRangeField()
RangeFieldWidgetTestCase::_testRangeFieldWidget in tests/range.field_widget.test
Helper method. Tests range field widget for a given range field type.
RangeFieldWidgetValidationTestCase::testRangeFieldFormValidation in tests/range.field_widget_validation.test
Tests range field validation.
RangeFieldWidgetValidationTestCase::testRangeIntegerFormValidation in tests/range.field_widget_validation.test
Tests field widget validation for range integer fields.
RangeFieldWidgetValidationTestCase::_testRangeFloatFormValidation in tests/range.field_widget_validation.test
Helper method. Tests widget validation for given field type.
RangeInternationalizationWebTestCase::setUp in tests/range.i18n.test
Sets up a Drupal site for running functional and integration tests.

File

tests/range.base.test, line 129
Contains range base test classes.

Class

RangeBaseWebTestCase
Base class for the range module's tests.

Code

protected function createTestRangeField($field_type = 'range_integer') {
  $field_name = $this
    ->getTestFieldName($field_type);
  $field = array(
    'field_name' => $field_name,
    'type' => $field_type,
    'cardinality' => 1,
    'settings' => array(),
  );
  if ($field_type === 'range_float' || $field_type === 'range_decimal') {
    $field['settings']['decimal_separator'] = static::FIELD_SETTINGS_DECIMAL_SEPARATOR;
    $field['settings']['precision'] = static::FIELD_SETTINGS_PRECISION;
    $field['settings']['scale'] = static::FIELD_SETTINGS_SCALE;
  }
  $this->field = field_create_field($field);
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'node',
    'bundle' => $this->contentType,
    'label' => static::INSTANCE_LABEL,
    'widget' => array(
      'type' => 'range',
    ),
    'settings' => array(
      'min' => static::INSTANCE_SETTINGS_MIN,
      'max' => static::INSTANCE_SETTINGS_MAX,
      'from' => array(
        'label' => static::INSTANCE_SETTINGS_FROM_LABEL,
        'prefix' => static::INSTANCE_SETTINGS_FROM_PREFIX,
        'suffix' => static::INSTANCE_SETTINGS_FROM_SUFFIX,
      ),
      'to' => array(
        'label' => static::INSTANCE_SETTINGS_TO_LABEL,
        'prefix' => static::INSTANCE_SETTINGS_TO_PREFIX,
        'suffix' => static::INSTANCE_SETTINGS_TO_SUFFIX,
      ),
      'field' => array(
        'prefix' => static::INSTANCE_SETTINGS_FIELD_PREFIX,
        'suffix' => static::INSTANCE_SETTINGS_FIELD_SUFFIX,
      ),
      'combined' => array(
        'prefix' => static::INSTANCE_SETTINGS_COMBINED_PREFIX,
        'suffix' => static::INSTANCE_SETTINGS_COMBINED_SUFFIX,
      ),
    ),
  );
  $this->instance = field_create_instance($instance);
}