Add a new test for creating a custom field
[MAILPOET-3628]
This commit is contained in:
@@ -67,7 +67,7 @@ class CustomFields {
|
||||
try {
|
||||
$customField = $this->customFieldsRepository->createOrUpdate($this->customFieldsDataSanitizer->sanitize($data));
|
||||
} catch (\Exception $e) {
|
||||
throw new APIException('Failed to save a new subscriber field ' . join(', ', $e->getMessage()), APIException::FAILED_TO_SAVE_SUBSCRIBER_FIELD);
|
||||
throw new APIException('Failed to save a new subscriber field ' . $e->getMessage(), APIException::FAILED_TO_SAVE_SUBSCRIBER_FIELD);
|
||||
}
|
||||
$customField = $this->customFieldsRepository->findOneById($customField->getId());
|
||||
if (!$customField instanceof CustomFieldEntity) {
|
||||
|
@@ -6,7 +6,6 @@ use Codeception\Stub;
|
||||
use Codeception\Stub\Expected;
|
||||
use Codeception\Util\Fixtures;
|
||||
use MailPoet\API\MP\v1\CustomFields;
|
||||
use MailPoet\CustomFields\ApiDataSanitizer;
|
||||
use MailPoet\CustomFields\CustomFieldsRepository;
|
||||
use MailPoet\Entities\CustomFieldEntity;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace MailPoet\Test\API\MP;
|
||||
|
||||
use MailPoet\API\MP\v1\API;
|
||||
use MailPoet\API\MP\v1\APIException;
|
||||
use MailPoet\CustomFields\CustomFieldsRepository;
|
||||
use MailPoet\Entities\CustomFieldEntity;
|
||||
|
||||
@@ -80,4 +81,30 @@ class CustomFieldsTest extends \MailPoetTest {
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItCreateNewCustomField() {
|
||||
$response = $this->api->addSubscriberField([
|
||||
'name' => 'text custom field',
|
||||
'type' => 'text',
|
||||
'params' => [
|
||||
'required' => '1',
|
||||
'label' => 'text custom field',
|
||||
'date_type' => 'year_month_day',
|
||||
],
|
||||
]);
|
||||
expect($response)->array();
|
||||
expect($response)->hasKey('name');
|
||||
}
|
||||
|
||||
public function testItFailsToCreateNewCustomField() {
|
||||
$this->expectException(APIException::class);
|
||||
$this->api->addSubscriberField([
|
||||
'type' => 'text',
|
||||
'params' => [
|
||||
'required' => '1',
|
||||
'label' => 'text custom field',
|
||||
'date_type' => 'year_month_day',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user