protected function RangeFieldWidgetValidationTestCase::_testRangeFloatFormValidation in Range 7
Helper method. Tests widget validation for given field type.
Parameters
string $field_type: Field type to test against. Could be one of the following values: range_float or range_decimal.
2 calls to RangeFieldWidgetValidationTestCase::_testRangeFloatFormValidation()
- RangeFieldWidgetValidationTestCase::testRangeDecimalFormValidation in tests/
range.field_widget_validation.test - Tests field widget validation for range decimal fields.
- RangeFieldWidgetValidationTestCase::testRangeFloatFormValidation in tests/
range.field_widget_validation.test - Tests field widget validation for range float fields.
File
- tests/
range.field_widget_validation.test, line 152 - Contains range form validation tests.
Class
- RangeFieldWidgetValidationTestCase
- Tests form validation for range fields.
Code
protected function _testRangeFloatFormValidation($field_type) {
$this
->createTestRangeField($field_type);
$this
->drupalGet("node/add/{$this->contentType}");
$field_name = $this
->getTestFieldName($field_type);
$form_element_key = $field_name . '[' . LANGUAGE_NONE . '][0]';
// Test field widget validation error messages.
// Only numbers and one decimal separator allowed.
$incorrect_entries = array(
array(
'from' => 'A',
'to' => 'Z',
),
array(
'from' => '1..0',
'to' => '2.0.0',
),
array(
'from' => '-1.0.',
'to' => '2-.',
),
array(
'from' => '0A',
'to' => '9Z',
),
array(
'from' => '-1.0-',
'to' => '2.0-2',
),
array(
'from' => '-',
'to' => '--',
),
array(
'from' => '1,,0',
'to' => '2,0,0',
),
array(
'from' => '-1,0,',
'to' => '2,,',
),
array(
'from' => '-1,0,,0',
'to' => ',,2',
),
);
foreach ($incorrect_entries as $entries) {
$edit = array(
"{$form_element_key}[from]" => $entries['from'],
"{$form_element_key}[to]" => $entries['to'],
);
$this
->drupalPost(NULL, $edit, t('Save'));
$error_message = t('Only numbers and one decimal separator (@separator) allowed in %field.', array(
'@separator' => static::FIELD_SETTINGS_DECIMAL_SEPARATOR,
'%field' => static::INSTANCE_SETTINGS_FROM_LABEL,
));
$this
->assertRaw($error_message, format_string('Correct widget validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
$error_message = t('Only numbers and one decimal separator (@separator) allowed in %field.', array(
'@separator' => static::FIELD_SETTINGS_DECIMAL_SEPARATOR,
'%field' => static::INSTANCE_SETTINGS_TO_LABEL,
));
$this
->assertRaw($error_message, format_string('Correct widget validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
}
$correct_entries = array(
array(
'from' => '-200,00',
'to' => '-100,89',
),
array(
'from' => '-3,9',
'to' => '99,0',
),
array(
'from' => '0',
'to' => '9',
),
array(
'from' => '1',
'to' => '5',
),
array(
'from' => '10000,99293993',
'to' => '20000,3487693476',
),
);
foreach ($correct_entries as $entries) {
$edit = array(
"{$form_element_key}[from]" => $entries['from'],
"{$form_element_key}[to]" => $entries['to'],
);
$this
->drupalPost(NULL, $edit, t('Save'));
$error_message = t('Only numbers and one decimal separator (@separator) allowed in %field.', array(
'@separator' => static::FIELD_SETTINGS_DECIMAL_SEPARATOR,
'%field' => static::INSTANCE_SETTINGS_FROM_LABEL,
));
$this
->assertNoRaw($error_message, format_string('Correct widget validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
$error_message = t('Only numbers and one decimal separator (@separator) allowed in %field.', array(
'@separator' => static::FIELD_SETTINGS_DECIMAL_SEPARATOR,
'%field' => static::INSTANCE_SETTINGS_TO_LABEL,
));
$this
->assertNoRaw($error_message, format_string('Correct widget validation error message found on the page: !error_message', array(
'!error_message' => $error_message,
)));
}
}