Decodes meta option field if it exists on the object
This commit is contained in:
@@ -975,4 +975,10 @@ class Newsletter extends Model {
|
||||
return parent::where('hash', $hash)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
function getMeta() {
|
||||
if(!$this->meta) return;
|
||||
|
||||
return (Helpers::isJson($this->meta)) ? json_decode($this->meta, true) : $this->meta;
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
@@ -840,7 +839,42 @@ class NewsletterTest extends \MailPoetTest {
|
||||
expect($result[1]->id)->equals($newsletter_2->id);
|
||||
}
|
||||
|
||||
function testPauseTaskWhenDisablePostNotification() {
|
||||
function testItGetsAndDecodesNewsletterOptionMetaField() {
|
||||
$newsletter = Newsletter::createOrUpdate(
|
||||
array(
|
||||
'subject' => 'Test Option Meta Field',
|
||||
'preheader' => 'Pre Header',
|
||||
'type' => Newsletter::TYPE_AUTOMATIC
|
||||
)
|
||||
);
|
||||
$newsletter_option_field = NewsletterOptionField::create();
|
||||
$newsletter_option_field->hydrate(
|
||||
array(
|
||||
'newsletter_type' => Newsletter::TYPE_AUTOMATIC,
|
||||
'name' => 'meta'
|
||||
)
|
||||
);
|
||||
$newsletter_option_field->save();
|
||||
$newsletter_option = NewsletterOption::create();
|
||||
$meta = array('some' => 'value');
|
||||
$newsletter_option->hydrate(
|
||||
array(
|
||||
'newsletter_id' => $newsletter->id,
|
||||
'option_field_id' => $newsletter_option_field->id,
|
||||
'value' => json_encode($meta)
|
||||
)
|
||||
);
|
||||
$newsletter_option->save();
|
||||
|
||||
// by default meta option does not exist on newsletter object
|
||||
expect($newsletter->getMeta())->isEmpty();
|
||||
|
||||
// if meta option exists, it should be returned as an array
|
||||
$newsletter = Newsletter::filter('filterWithOptions')->findOne($newsletter->id);
|
||||
expect($newsletter->getMeta())->equals($meta);
|
||||
}
|
||||
|
||||
function testPausesTaskWhenPostNotificationIsDisabled() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'type' => Newsletter::TYPE_NOTIFICATION
|
||||
));
|
||||
@@ -854,7 +888,7 @@ class NewsletterTest extends \MailPoetTest {
|
||||
expect($task_found->status)->equals(ScheduledTask::STATUS_PAUSED);
|
||||
}
|
||||
|
||||
function testUnPauseTaskWhenEnablePostNotification() {
|
||||
function testUnpausesTasksWhenPostNotificationIsEnabled() {
|
||||
$newsletter = Newsletter::createOrUpdate(array(
|
||||
'type' => Newsletter::TYPE_NOTIFICATION
|
||||
));
|
||||
@@ -870,8 +904,6 @@ class NewsletterTest extends \MailPoetTest {
|
||||
$task_found = ScheduledTask::findOne($task->id());
|
||||
expect($task_found->status)->equals(ScheduledTask::STATUS_SCHEDULED);
|
||||
}
|
||||
|
||||
|
||||
function _after() {
|
||||
\ORM::raw_execute('TRUNCATE ' . NewsletterOption::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||
|
Reference in New Issue
Block a user