- Updates unit tests

- Addresses #628 (3)
This commit is contained in:
Vlad
2016-11-03 20:51:16 -04:00
parent 0d32c09df3
commit 9cd7b1a204
2 changed files with 48 additions and 17 deletions

View File

@@ -7,11 +7,10 @@ if(!defined('ABSPATH')) exit;
class ShortcodesTaskTest extends MailPoetTest { class ShortcodesTaskTest extends MailPoetTest {
function testItCanReplaceShortcodes() { function testItCanReplaceShortcodes() {
$queue = $newsletter = array( $queue = $newsletter = (object)array(
'id' => 1 'id' => 1
); );
$subscriber = array( $subscriber = (object)array(
'email' => 'test@xample. com', 'email' => 'test@xample. com',
'first_name' => 'John', 'first_name' => 'John',
'last_name' => 'Doe' 'last_name' => 'Doe'

View File

@@ -2,6 +2,7 @@
use MailPoet\Config\Populator; use MailPoet\Config\Populator;
use MailPoet\Models\CustomField; use MailPoet\Models\CustomField;
use MailPoet\Models\Newsletter;
use MailPoet\Models\SendingQueue; use MailPoet\Models\SendingQueue;
use MailPoet\Models\Setting; use MailPoet\Models\Setting;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
@@ -22,11 +23,7 @@ class ShortcodesTest extends MailPoetTest {
$this->WP_user = $this->_createWPUser(); $this->WP_user = $this->_createWPUser();
$this->WP_post = $this->_createWPPost(); $this->WP_post = $this->_createWPPost();
$this->subscriber = $this->_createSubscriber(); $this->subscriber = $this->_createSubscriber();
$this->newsletter = array( $this->newsletter = $this->_createNewsletter();
'subject' => 'some subject',
'type' => 'notification',
'id' => 2
);
$this->shortcodes_object = new MailPoet\Newsletter\Shortcodes\Shortcodes( $this->shortcodes_object = new MailPoet\Newsletter\Shortcodes\Shortcodes(
$this->newsletter, $this->newsletter,
$this->subscriber $this->subscriber
@@ -98,7 +95,7 @@ class ShortcodesTest extends MailPoetTest {
'<a href="#">not post</a>'; '<a href="#">not post</a>';
$result = $result =
$shortcodes_object->process(array('[newsletter:subject]')); $shortcodes_object->process(array('[newsletter:subject]'));
expect($result[0])->equals($this->newsletter['subject']); expect($result[0])->equals($this->newsletter->subject);
$result = $result =
$shortcodes_object->process(array('[newsletter:total]'), $content); $shortcodes_object->process(array('[newsletter:total]'), $content);
expect($result[0])->equals(2); expect($result[0])->equals(2);
@@ -106,12 +103,32 @@ class ShortcodesTest extends MailPoetTest {
$shortcodes_object->process(array('[newsletter:post_title]')); $shortcodes_object->process(array('[newsletter:post_title]'));
$wp_post = get_post($this->WP_post); $wp_post = get_post($this->WP_post);
expect($result['0'])->equals($wp_post->post_title); expect($result['0'])->equals($wp_post->post_title);
$result = }
$shortcodes_object->process(array('[newsletter:number]'));
function itCanProcessPostNotificationNewsletterNumberShortcode() {
// create first post notification
$post_notification_history = $this->_createNewsletter(
$parent_id = $this->newsletter_id,
$type = Newsletter::TYPE_NOTIFICATION_HISTORY
);
$shortcodes_object = new MailPoet\Newsletter\Shortcodes\Shortcodes(
$post_notification_history,
$this->subscriber
);
$result = $shortcodes_object->process(array('[newsletter:number]'));
expect($result['0'])->equals(1); expect($result['0'])->equals(1);
$queue = $this->_createQueue();
$result = // create another post notification
$shortcodes_object->process(array('[newsletter:number]')); $post_notification_history = $this->_createNewsletter(
$parent_id = $this->newsletter_id,
$type = Newsletter::TYPE_NOTIFICATION_HISTORY
);
$shortcodes_object = new MailPoet\Newsletter\Shortcodes\Shortcodes(
$post_notification_history,
$this->subscriber
);
$result = $shortcodes_object->process(array('[newsletter:number]'));
expect($result['0'])->equals(2); expect($result['0'])->equals(2);
} }
@@ -271,15 +288,30 @@ class ShortcodesTest extends MailPoetTest {
return Subscriber::findOne($subscriber->id); return Subscriber::findOne($subscriber->id);
} }
function _createNewsletter($parent_id = null, $type = Newsletter::TYPE_NOTIFICATION) {
$newsletter = Newsletter::create();
$newsletter->hydrate(
array(
'subject' => 'some subject',
'type' => $type,
'status' => Newsletter::STATUS_SENT,
'parent_id' => $parent_id,
)
);
$newsletter->save();
return Newsletter::findOne($newsletter->id);
}
function _createQueue() { function _createQueue() {
$queue = SendingQueue::create(); $queue = SendingQueue::create();
$queue->newsletter_id = $this->newsletter['id']; $queue->newsletter_id = $this->newsletter['id'];
$queue->status = 'completed'; $queue->status = 'completed';
$queue->save(); $queue->save();
return $queue; return SendingQueue::findOne($queue->id);
} }
function _after() { function _after() {
ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table); ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table); ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table);
ORM::raw_execute('TRUNCATE ' . CustomField::$_table); ORM::raw_execute('TRUNCATE ' . CustomField::$_table);