Validate only fields in form

[MAILPOET-1828]
This commit is contained in:
Pavel Dohnal
2019-04-03 13:12:47 +02:00
committed by M. Shull
parent 66663331c5
commit 6493f7ceb4
4 changed files with 66 additions and 9 deletions

View File

@ -3,6 +3,7 @@
namespace MailPoet\Subscribers;
use MailPoet\Models\CustomField;
use MailPoet\Models\Form;
class RequiredCustomFieldValidatorTest extends \MailPoetTest {
@ -46,4 +47,26 @@ class RequiredCustomFieldValidatorTest extends \MailPoetTest {
$validator->validate(['cf_' . $this->custom_field->id() => '']);
}
function testItValidatesOnlyFieldPresentInForm() {
CustomField::createOrUpdate([
'name' => 'custom field 2',
'type' => 'text',
'params' => ['required' => '1']
]);
$form = Form::createOrUpdate([
'name' => 'form',
'body' => [[
'type' => 'text',
'name' => 'mandatory',
'id' => $this->custom_field->id(),
'unique' => '1',
'static' => '0',
'params' => ['required' => '1'],
'position' => '0',
]],
]);
$validator = new RequiredCustomFieldValidator();
$validator->validate(['cf_' . $this->custom_field->id() => 'value'], $form);
}
}