Unit tests for new methods in model subscriber
This commit is contained in:
@@ -324,12 +324,6 @@ class Menu {
|
|||||||
$data['date_formats'] = Block\Date::getDateFormats();
|
$data['date_formats'] = Block\Date::getDateFormats();
|
||||||
$data['month_names'] = Block\Date::getMonthNames();
|
$data['month_names'] = Block\Date::getMonthNames();
|
||||||
|
|
||||||
|
|
||||||
// print "<pre>";
|
|
||||||
// print_r($data['custom_fields']);
|
|
||||||
// print "</pre>";
|
|
||||||
// exit;
|
|
||||||
|
|
||||||
echo $this->renderer->render('subscribers/subscribers.html', $data);
|
echo $this->renderer->render('subscribers/subscribers.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -264,7 +264,7 @@ class Subscriber extends Model {
|
|||||||
return $subscriber;
|
return $subscriber;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCustomFields() {
|
function withCustomFields() {
|
||||||
$custom_fields = CustomField::select('id')->findArray();
|
$custom_fields = CustomField::select('id')->findArray();
|
||||||
if(empty($custom_fields)) return $this;
|
if(empty($custom_fields)) return $this;
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@ class Subscribers {
|
|||||||
} else {
|
} else {
|
||||||
$segments = $subscriber->segments()->findArray();
|
$segments = $subscriber->segments()->findArray();
|
||||||
|
|
||||||
$subscriber = $subscriber->getCustomFields()->asArray();
|
$subscriber = $subscriber->withCustomFields()->asArray();
|
||||||
$subscriber['segments'] = array_map(function($segment) {
|
$subscriber['segments'] = array_map(function($segment) {
|
||||||
return $segment['id'];
|
return $segment['id'];
|
||||||
}, $segments);
|
}, $segments);
|
||||||
|
@@ -372,6 +372,47 @@ class SubscriberCest {
|
|||||||
expect($subscriber->last_name)->equals('DoDo');
|
expect($subscriber->last_name)->equals('DoDo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function itCanSetCustomField() {
|
||||||
|
$custom_field = CustomField::createOrUpdate(array(
|
||||||
|
'name' => 'Date of Birth',
|
||||||
|
'type' => 'date'
|
||||||
|
));
|
||||||
|
|
||||||
|
expect($custom_field->id() > 0)->true();
|
||||||
|
|
||||||
|
$value = array(
|
||||||
|
'year' => 1984,
|
||||||
|
'month' => 3,
|
||||||
|
'day' => 9
|
||||||
|
);
|
||||||
|
|
||||||
|
$subscriber = Subscriber::findOne($this->subscriber->id());
|
||||||
|
$subscriber->setCustomField($custom_field->id(), $value);
|
||||||
|
|
||||||
|
$subscriber = $subscriber->withCustomFields()->asArray();
|
||||||
|
|
||||||
|
expect($subscriber['cf_'.$custom_field->id()])->equals(
|
||||||
|
mktime(0, 0, 0, $value['month'], $value['day'], $value['year'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itCanGetCustomField() {
|
||||||
|
$subscriber = Subscriber::findOne($this->subscriber->id());
|
||||||
|
|
||||||
|
expect($subscriber->getCustomField(9999, 'default_value'))
|
||||||
|
->equals('default_value');
|
||||||
|
|
||||||
|
$custom_field = CustomField::createOrUpdate(array(
|
||||||
|
'name' => 'Custom field: text input',
|
||||||
|
'type' => 'input'
|
||||||
|
));
|
||||||
|
|
||||||
|
$subscriber->setCustomField($custom_field->id(), 'non_default_value');
|
||||||
|
|
||||||
|
expect($subscriber->getCustomField($custom_field->id(), 'default_value'))
|
||||||
|
->equals('non_default_value');
|
||||||
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
ORM::forTable(Subscriber::$_table)
|
ORM::forTable(Subscriber::$_table)
|
||||||
->deleteMany();
|
->deleteMany();
|
||||||
|
Reference in New Issue
Block a user