protected function RangeFieldValidationTest::rangeTestConstraints in Range 8
Tests range field constraints.
Parameters
string $field_type: Range field type. Could be one of the following values: range_integer, range_float or range_decimal.
1 call to RangeFieldValidationTest::rangeTestConstraints()
- RangeFieldValidationTest::testRangeValidation in tests/
src/ Functional/ RangeFieldValidationTest.php - Tests range field validation.
File
- tests/
src/ Functional/ RangeFieldValidationTest.php, line 34
Class
- RangeFieldValidationTest
- Tests range field validation.
Namespace
Drupal\Tests\range\FunctionalCode
protected function rangeTestConstraints($field_type) {
$field_name = $this
->getTestFieldName($field_type);
$path = "node/add/{$this->bundle}";
$validation_error_1 = 'Both range values (FROM and TO) are required.';
$validation_error_2 = 'The FROM value is higher than the TO value.';
$items = [
[
'edit' => [
"{$field_name}[0][from]" => 10,
"{$field_name}[0][to]" => '',
],
'error' => $validation_error_1,
],
[
'edit' => [
"{$field_name}[0][from]" => '',
"{$field_name}[0][to]" => 10,
],
'error' => $validation_error_1,
],
[
'edit' => [
"{$field_name}[0][from]" => 10,
"{$field_name}[0][to]" => 5,
],
'error' => $validation_error_2,
],
];
foreach ($items as $item) {
$this
->drupalGet($path);
$this
->submitForm($item['edit'], 'Save');
$this
->assertSession()
->pageTextContains($item['error']);
}
$valid_edit = [
"{$field_name}[0][from]" => 5,
"{$field_name}[0][to]" => 10,
];
$this
->drupalGet($path);
$this
->submitForm($valid_edit, 'Save');
$this
->assertSession()
->pageTextNotContains($validation_error_1);
$this
->assertSession()
->pageTextNotContains($validation_error_2);
}