public function RangeFieldWidgetValidationTestCase::testRangeFieldFormValidation in Range 7
Tests range field validation.
File
- tests/
range.field_widget_validation.test, line 41 - Contains range form validation tests.
Class
- RangeFieldWidgetValidationTestCase
- Tests form validation for range fields.
Code
public function testRangeFieldFormValidation() {
$this
->createTestRangeField('range_integer');
$this
->drupalGet("node/add/{$this->contentType}");
$field_name = $this
->getTestFieldName('range_integer');
$form_element_key = $field_name . '[' . LANGUAGE_NONE . '][0]';
// Test field validation error messages.
//
// Both FROM and TO values must be specified.
$edit = array(
"{$form_element_key}[from]" => static::INSTANCE_SETTINGS_MIN,
"{$form_element_key}[to]" => '',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$error_message = t('%name: you must specify two values.', array(
'%name' => static::INSTANCE_LABEL,
));
$this
->assertRaw($error_message, format_string('Correct field validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
$edit = array(
"{$form_element_key}[from]" => '',
"{$form_element_key}[to]" => static::INSTANCE_SETTINGS_MAX,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$error_message = t('%name: you must specify two values.', array(
'%name' => static::INSTANCE_LABEL,
));
$this
->assertRaw($error_message, format_string('Correct field validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
// The FROM value is less than the allowed minimum value.
$edit = array(
"{$form_element_key}[from]" => static::INSTANCE_SETTINGS_MIN - 1,
"{$form_element_key}[to]" => static::INSTANCE_SETTINGS_MAX,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$error_message = t('%name: the FROM value may be no less than %min.', array(
'%name' => static::INSTANCE_LABEL,
'%min' => static::INSTANCE_SETTINGS_MIN,
));
$this
->assertRaw($error_message, format_string('Correct field validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
// The TO value is greater than the allowed maximum value.
$edit = array(
"{$form_element_key}[from]" => static::INSTANCE_SETTINGS_MIN,
"{$form_element_key}[to]" => static::INSTANCE_SETTINGS_MAX + 1,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$error_message = t('%name: the TO value may be no greater than %max.', array(
'%name' => static::INSTANCE_LABEL,
'%max' => static::INSTANCE_SETTINGS_MAX,
));
$this
->assertRaw($error_message, format_string('Correct field validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
// FROM value is greater than TO value.
$edit = array(
"{$form_element_key}[from]" => static::INSTANCE_SETTINGS_MAX,
"{$form_element_key}[to]" => static::INSTANCE_SETTINGS_MIN,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$error_message = t('%name: FROM value is greater than TO value.', array(
'%name' => static::INSTANCE_LABEL,
));
$this
->assertRaw($error_message, format_string('Correct field validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
}