Merge pull request #851 from LukeAmos/issue/850

FIX Fixes #850 added validation to numerical form fields
This commit is contained in:
Robbie Averill 2019-01-16 22:12:32 +01:00 committed by GitHub
commit b2101c15fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -82,4 +82,15 @@ class EditableNumericField extends EditableFormField
$field->setAttribute('data-rule-max', $this->MaxValue);
}
}
public function validate()
{
$result = parent::validate();
if ($this->MinValue > $this->MaxValue) {
$result->addError(
_t(__CLASS__ . '.ORDER_WARNING', 'Minimum length should be less than the maximum length.')
);
}
return $result;
}
}

View File

@ -14,4 +14,27 @@ class EditableNumericFieldTest extends SapphireTest
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
public function testValidateAddsErrorWhenMinValueIsGreaterThanMaxValue()
{
/** @var EditableNumericField $field */
$field = EditableNumericField::create();
$field->MinValue = 10;
$field->MaxValue = 5;
$result = $field->validate();
$this->assertFalse($result->isValid(), 'Validation should fail when min is greater than max');
$this->assertContains('Minimum length should be less than the maximum length', $result->serialize());
}
public function testValidate()
{
/** @var EditableNumericField $field */
$field = EditableNumericField::create();
$field->MinValue = 5;
$field->MaxValue = 10;
$result = $field->validate();
$this->assertTrue($result->isValid());
}
}