Reject requests without mandatory custom fields

We need to make sure subscribers cannot be created without custom fields
Users require GDPR consent and we need to make sure there are no way to
create a subscriber without mandatory custom fields

[MAILPOET-1405]
This commit is contained in:
Pavel Dohnal
2018-08-21 09:30:44 +02:00
parent 5cfe8e3368
commit ac33e11c60
7 changed files with 152 additions and 5 deletions

View File

@ -0,0 +1,48 @@
<?php
namespace MailPoet\Subscribers;
use MailPoet\Models\CustomField;
class RequiredCustomFieldValidatorTest extends \MailPoetTest {
private $custom_field;
function _before() {
\ORM::raw_execute('TRUNCATE ' . CustomField::$_table);
$this->custom_field = CustomField::createOrUpdate([
'name' => 'custom field',
'type' => 'text',
'params' => ['required' => '1']
]);
}
function testItValidatesDataWithoutCustomField() {
$validator = new RequiredCustomFieldValidator();
$this->setExpectedException('Exception');
$validator->validate([]);
}
function testItValidatesDataWithCustomFieldPassedAsId() {
$validator = new RequiredCustomFieldValidator();
$validator->validate([$this->custom_field->id() => 'value']);
}
function testItValidatesDataWithCustomFieldPassedAsCFId() {
$validator = new RequiredCustomFieldValidator();
$validator->validate(['cf_' . $this->custom_field->id() => 'custom field']);
}
function testItValidatesDataWithEmptyCustomField() {
$validator = new RequiredCustomFieldValidator();
$this->setExpectedException('Exception');
$validator->validate([$this->custom_field->id() => '']);
}
function testItValidatesDataWithEmptyCustomFieldAsCFId() {
$validator = new RequiredCustomFieldValidator();
$this->setExpectedException('Exception');
$validator->validate(['cf_' . $this->custom_field->id() => '']);
}
}