Move the tests to a separate file
[MAILPOET-3628]
This commit is contained in:
@@ -45,68 +45,6 @@ class APITest extends \MailPoetTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItReturnsDefaultSubscriberFields() {
|
|
||||||
$response = $this->getApi()->getSubscriberFields();
|
|
||||||
|
|
||||||
expect($response)->contains([
|
|
||||||
'id' => 'email',
|
|
||||||
'name' => __('Email', 'mailpoet'),
|
|
||||||
'type' => 'text',
|
|
||||||
'params' => [
|
|
||||||
'required' => '1',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
expect($response)->contains([
|
|
||||||
'id' => 'first_name',
|
|
||||||
'name' => __('First name', 'mailpoet'),
|
|
||||||
'type' => 'text',
|
|
||||||
'params' => [
|
|
||||||
'required' => '',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
expect($response)->contains([
|
|
||||||
'id' => 'last_name',
|
|
||||||
'name' => __('Last name', 'mailpoet'),
|
|
||||||
'type' => 'text',
|
|
||||||
'params' => [
|
|
||||||
'required' => '',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testItReturnsCustomFields() {
|
|
||||||
$customField1 = $this->customFieldRepository->createOrUpdate([
|
|
||||||
'name' => 'text custom field',
|
|
||||||
'type' => CustomFieldEntity::TYPE_TEXT,
|
|
||||||
'params' => ['required' => '1', 'date_type' => 'year_month_day'],
|
|
||||||
]);
|
|
||||||
$customField2 = $this->customFieldRepository->createOrUpdate([
|
|
||||||
'name' => 'checkbox custom field',
|
|
||||||
'type' => CustomFieldEntity::TYPE_CHECKBOX,
|
|
||||||
'params' => ['required' => ''],
|
|
||||||
]);
|
|
||||||
$response = $this->getApi()->getSubscriberFields();
|
|
||||||
expect($response)->contains([
|
|
||||||
'id' => 'cf_' . $customField1->getId(),
|
|
||||||
'name' => 'text custom field',
|
|
||||||
'type' => 'text',
|
|
||||||
'params' => [
|
|
||||||
'required' => '1',
|
|
||||||
'label' => 'text custom field',
|
|
||||||
'date_type' => 'year_month_day',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
expect($response)->contains([
|
|
||||||
'id' => 'cf_' . $customField2->getId(),
|
|
||||||
'name' => 'checkbox custom field',
|
|
||||||
'type' => 'checkbox',
|
|
||||||
'params' => [
|
|
||||||
'required' => '',
|
|
||||||
'label' => 'checkbox custom field',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testItDoesNotSubscribeMissingSubscriberToLists() {
|
public function testItDoesNotSubscribeMissingSubscriberToLists() {
|
||||||
try {
|
try {
|
||||||
$this->getApi()->subscribeToLists(false, [1,2,3]);
|
$this->getApi()->subscribeToLists(false, [1,2,3]);
|
||||||
|
83
tests/integration/API/MP/CustomFieldsTest.php
Normal file
83
tests/integration/API/MP/CustomFieldsTest.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Test\API\MP;
|
||||||
|
|
||||||
|
use MailPoet\API\MP\v1\API;
|
||||||
|
use MailPoet\CustomFields\CustomFieldsRepository;
|
||||||
|
use MailPoet\Entities\CustomFieldEntity;
|
||||||
|
|
||||||
|
class CustomFieldsTest extends \MailPoetTest {
|
||||||
|
/** @var API */
|
||||||
|
private $api;
|
||||||
|
|
||||||
|
/** @var CustomFieldsRepository */
|
||||||
|
private $customFieldRepository;
|
||||||
|
|
||||||
|
public function _before(): void {
|
||||||
|
parent::_before();
|
||||||
|
$this->customFieldRepository = $this->diContainer->get(CustomFieldsRepository::class);
|
||||||
|
$this->api = $this->diContainer->get(API::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItReturnsDefaultSubscriberFields() {
|
||||||
|
$response = $this->api->getSubscriberFields();
|
||||||
|
|
||||||
|
expect($response)->contains([
|
||||||
|
'id' => 'email',
|
||||||
|
'name' => __('Email', 'mailpoet'),
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '1',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
expect($response)->contains([
|
||||||
|
'id' => 'first_name',
|
||||||
|
'name' => __('First name', 'mailpoet'),
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
expect($response)->contains([
|
||||||
|
'id' => 'last_name',
|
||||||
|
'name' => __('Last name', 'mailpoet'),
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItReturnsCustomFields() {
|
||||||
|
$customField1 = $this->customFieldRepository->createOrUpdate([
|
||||||
|
'name' => 'text custom field',
|
||||||
|
'type' => CustomFieldEntity::TYPE_TEXT,
|
||||||
|
'params' => ['required' => '1', 'date_type' => 'year_month_day'],
|
||||||
|
]);
|
||||||
|
$customField2 = $this->customFieldRepository->createOrUpdate([
|
||||||
|
'name' => 'checkbox custom field',
|
||||||
|
'type' => CustomFieldEntity::TYPE_CHECKBOX,
|
||||||
|
'params' => ['required' => ''],
|
||||||
|
]);
|
||||||
|
$response = $this->api->getSubscriberFields();
|
||||||
|
expect($response)->contains([
|
||||||
|
'id' => 'cf_' . $customField1->getId(),
|
||||||
|
'name' => 'text custom field',
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '1',
|
||||||
|
'label' => 'text custom field',
|
||||||
|
'date_type' => 'year_month_day',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
expect($response)->contains([
|
||||||
|
'id' => 'cf_' . $customField2->getId(),
|
||||||
|
'name' => 'checkbox custom field',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'params' => [
|
||||||
|
'required' => '',
|
||||||
|
'label' => 'checkbox custom field',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user