diff --git a/tests/integration/API/MP/APITest.php b/tests/integration/API/MP/APITest.php index d7357aea4f..366a12d3e1 100644 --- a/tests/integration/API/MP/APITest.php +++ b/tests/integration/API/MP/APITest.php @@ -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() { try { $this->getApi()->subscribeToLists(false, [1,2,3]); diff --git a/tests/integration/API/MP/CustomFieldsTest.php b/tests/integration/API/MP/CustomFieldsTest.php new file mode 100644 index 0000000000..eaba21b68f --- /dev/null +++ b/tests/integration/API/MP/CustomFieldsTest.php @@ -0,0 +1,83 @@ +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', + ], + ]); + } +}