Return all information in getSubcriberFields response
[MAILPOET-2099]
This commit is contained in:
@ -41,23 +41,42 @@ class API {
|
|||||||
[
|
[
|
||||||
'id' => 'email',
|
'id' => 'email',
|
||||||
'name' => WPFunctions::get()->__('Email', 'mailpoet'),
|
'name' => WPFunctions::get()->__('Email', 'mailpoet'),
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '1',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 'first_name',
|
'id' => 'first_name',
|
||||||
'name' => WPFunctions::get()->__('First name', 'mailpoet'),
|
'name' => WPFunctions::get()->__('First name', 'mailpoet'),
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 'last_name',
|
'id' => 'last_name',
|
||||||
'name' => WPFunctions::get()->__('Last name', 'mailpoet'),
|
'name' => WPFunctions::get()->__('Last name', 'mailpoet'),
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$custom_fields = CustomField::selectMany(['id', 'name'])->findMany();
|
$custom_fields = CustomField::selectMany(['id', 'name', 'type', 'params'])->findMany();
|
||||||
foreach ($custom_fields as $custom_field) {
|
foreach ($custom_fields as $custom_field) {
|
||||||
$data[] = [
|
$result = [
|
||||||
'id' => 'cf_' . $custom_field->id,
|
'id' => 'cf_' . $custom_field->id,
|
||||||
'name' => $custom_field->name,
|
'name' => $custom_field->name,
|
||||||
|
'type' => $custom_field->type,
|
||||||
];
|
];
|
||||||
|
if (is_serialized($custom_field->params)) {
|
||||||
|
$result['params'] = unserialize($custom_field->params);
|
||||||
|
} else {
|
||||||
|
$result['params'] = $custom_field->params;
|
||||||
|
}
|
||||||
|
$data[] = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -28,34 +28,66 @@ class APITest extends \MailPoetTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItReturnsSubscriberFields() {
|
function testItReturnsDefaultSubscriberFields() {
|
||||||
$custom_field = CustomField::create();
|
|
||||||
$custom_field->name = 'test custom field';
|
|
||||||
$custom_field->type = CustomField::TYPE_TEXT;
|
|
||||||
$custom_field->save();
|
|
||||||
|
|
||||||
$response = $this->getApi()->getSubscriberFields();
|
$response = $this->getApi()->getSubscriberFields();
|
||||||
|
|
||||||
expect($response)->equals(
|
expect($response)->contains([
|
||||||
[
|
'id' => 'email',
|
||||||
[
|
'name' => __('Email', 'mailpoet'),
|
||||||
'id' => 'email',
|
'type' => 'text',
|
||||||
'name' => __('Email', 'mailpoet'),
|
'params' => [
|
||||||
],
|
'required' => '1',
|
||||||
[
|
],
|
||||||
'id' => 'first_name',
|
]);
|
||||||
'name' => __('First name', 'mailpoet'),
|
expect($response)->contains([
|
||||||
],
|
'id' => 'first_name',
|
||||||
[
|
'name' => __('First name', 'mailpoet'),
|
||||||
'id' => 'last_name',
|
'type' => 'text',
|
||||||
'name' => __('Last name', 'mailpoet'),
|
'params' => [
|
||||||
],
|
'required' => '',
|
||||||
[
|
],
|
||||||
'id' => 'cf_' . $custom_field->id,
|
]);
|
||||||
'name' => $custom_field->name,
|
expect($response)->contains([
|
||||||
],
|
'id' => 'last_name',
|
||||||
]
|
'name' => __('Last name', 'mailpoet'),
|
||||||
);
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItReturnsCustomFields() {
|
||||||
|
$custom_field1 = CustomField::createOrUpdate([
|
||||||
|
'name' => 'text custom field',
|
||||||
|
'type' => CustomField::TYPE_TEXT,
|
||||||
|
'params' => ['required' => '1', 'date_type' => 'year_month_day'],
|
||||||
|
]);
|
||||||
|
$custom_field2 = CustomField::createOrUpdate([
|
||||||
|
'name' => 'checkbox custom field',
|
||||||
|
'type' => CustomField::TYPE_CHECKBOX,
|
||||||
|
'params' => ['required' => ''],
|
||||||
|
]);
|
||||||
|
$response = $this->getApi()->getSubscriberFields();
|
||||||
|
expect($response)->contains([
|
||||||
|
'id' => 'cf_' . $custom_field1->id,
|
||||||
|
'name' => 'text custom field',
|
||||||
|
'type' => 'text',
|
||||||
|
'params' => [
|
||||||
|
'required' => '1',
|
||||||
|
'label' => 'text custom field',
|
||||||
|
'date_type' => 'year_month_day',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
expect($response)->contains([
|
||||||
|
'id' => 'cf_' . $custom_field2->id,
|
||||||
|
'name' => 'checkbox custom field',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'params' => [
|
||||||
|
'required' => '',
|
||||||
|
'label' => 'checkbox custom field',
|
||||||
|
],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItDoesNotSubscribeMissingSubscriberToLists() {
|
function testItDoesNotSubscribeMissingSubscriberToLists() {
|
||||||
|
Reference in New Issue
Block a user