1 number_settings.test public NumberFieldSettingsTestCase::testNumberIntegerFieldSettings()

Test number_integer field settings.

File

core/modules/field/modules/number/tests/number_settings.test, line 125
Tests for number.module settings.

Class

NumberFieldSettingsTestCase
Tests for number field type settings.

Code

public function testNumberIntegerFieldSettings() {
  // Create a field with settings to validate.
  $field_name = 'field_' . backdrop_strtolower($this->randomName());

  $this->field = array(
    'field_name' => $field_name,
    'type' => 'number_integer',
  );
  field_create_field($this->field);

  $this->instance = array(
    'field_name' => $field_name,
    'entity_type' => 'node',
    'bundle' => 'post',
    'widget' => array(
      'type' => 'number',
    ),
    'display' => array(
      'default' => array(
        'type' => 'number_integer',
      ),
    ),
  );
  field_create_instance($this->instance);

  // Admin user sets various min/max values to an integer field.
  // Maximum value is smaller than Minimum.
  $edit = array(
    'instance[settings][min]' => 300,
    'instance[settings][max]' => 10,
  );
  $this->backdropGet("admin/structure/types/manage/post/fields/$field_name");
  $this->backdropPost(NULL, $edit, t('Save settings'));
  $this->assertRaw(format_string('%max must be greater than, or equal to, %min.', array(
    '%max' => 'Maximum',
    '%min' => 'Minimum',
  )), 'Integer field min setting greater max setting rejected');

  // Maximum and Minimum exceed the values a signed int(11) database field can
  // store.
  $min_db_integer = -2147483647;
  $max_db_integer = 2147483647;
  $min = -3000000000;
  $max = 4000000000;

  $edit = array(
    'instance[settings][min]' => -3000000000,
    'instance[settings][max]' => 4000000000,
  );
  $this->backdropGet("admin/structure/types/manage/post/fields/$field_name");
  $this->backdropPost(NULL, $edit, t('Save settings'));
  $this->assertRaw(format_string('%min is smaller than the smallest value the database can save. Choose a value equal to or higher than %db_min.', array(
    '%min' => $min,
    '%db_min' => $min_db_integer,
  )), 'Integer field min setting outside db range rejected');
  $this->assertRaw(format_string('%max is greater than the largest value the database can save. Choose a value equal to or lower than %db_max.', array(
    '%max' => $max,
    '%db_max' => $max_db_integer,
  )), 'Integer field max setting outside db range rejected');

  // Proper values should pass.
  $edit = array(
    'instance[settings][min]' => -2000000000,
    'instance[settings][max]' => 2000000000,
  );
  $this->backdropGet("admin/structure/types/manage/post/fields/$field_name");
  $this->backdropPost(NULL, $edit, t('Save settings'));
  $this->assertRaw(format_string('Saved %field_name configuration.', array(
    '%field_name' => $field_name,
  )), 'Proper integer field min/max settings saved');
}