diff --git a/src/EditableSpamProtectionField.php b/src/EditableSpamProtectionField.php index eb91273..8f13aec 100644 --- a/src/EditableSpamProtectionField.php +++ b/src/EditableSpamProtectionField.php @@ -227,9 +227,9 @@ public function validateField($data, $form) $formField->setValue($data[$this->Name]); } - $validator = $form->getValidator(); - if (!$formField->validate($validator)) { - $errors = $validator->getErrors(); + $result = $formField->validate(); + if (!$result->isValid()) { + $errors = $result->getMessages(); $foundError = false; // field validate implementation may not add error to validator diff --git a/tests/EditableSpamProtectionFieldTest.php b/tests/EditableSpamProtectionFieldTest.php index 55d3a8e..22eb0fe 100644 --- a/tests/EditableSpamProtectionFieldTest.php +++ b/tests/EditableSpamProtectionFieldTest.php @@ -14,6 +14,7 @@ use SilverStripe\SpamProtection\EditableSpamProtectionField; use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension; use SilverStripe\SpamProtection\Tests\Stub\Protector; +use SilverStripe\Core\Validation\ValidationResult; class EditableSpamProtectionFieldTest extends SapphireTest { @@ -39,11 +40,12 @@ public function testValidateFieldDoesntAddErrorOnSuccess() $formMock = $this->getFormMock(); $formFieldMock = $this->getEditableFormFieldMock(); + $result = new ValidationResult; $formFieldMock ->getFormField() // mock ->expects($this->once()) ->method('validate') - ->willReturn(true); + ->willReturn($result); $formMock ->expects($this->never()) @@ -57,13 +59,13 @@ public function testValidateFieldAddsErrorFromField() $formMock = $this->getFormMock(); $formFieldMock = $this->getEditableFormFieldMock(); + $result = new ValidationResult; + $result->addFieldError('MyField', 'some field message'); $formFieldMock ->getFormField() // mock ->expects($this->once()) ->method('validate') - ->willReturn(false); - - $formMock->getValidator()->validationError('MyField', 'some field message', 'required'); + ->willReturn($result); $formMock ->expects($this->once()) @@ -78,11 +80,13 @@ public function testValidateFieldAddsDefaultError() $formMock = $this->getFormMock(); $formFieldMock = $this->getEditableFormFieldMock(); + $result = new ValidationResult; + $result->addError('fail'); $formFieldMock ->getFormField() // mock ->expects($this->once()) ->method('validate') - ->willReturn(false); + ->willReturn($result); // field doesn't set any validation errors here