Add Acceptance test for receive post notification
[MQ-69]
This commit is contained in:
@@ -288,6 +288,7 @@ const NewsletterListNotification = createReactClass({ // eslint-disable-line rea
|
||||
}
|
||||
return (
|
||||
<Link
|
||||
data-automation-id={`history-${newsletter.id}`}
|
||||
to={`/notification/history/${newsletter.id}`}
|
||||
>{ MailPoet.I18n.t('viewHistory') }</Link>
|
||||
);
|
||||
|
@@ -38,6 +38,7 @@ class ListingTabs extends React.Component {
|
||||
<Link
|
||||
key={`tab-${tab.label}`}
|
||||
className={tabClasses}
|
||||
data-automation-id={`tab-${tab.label}`}
|
||||
to={tab.link}
|
||||
onClick={() => MailPoet.trackEvent(`Tab Emails > ${tab.name} clicked`,
|
||||
{ 'MailPoet Free version': window.mailpoet_version }
|
||||
|
@@ -2,6 +2,7 @@
|
||||
namespace MailPoet\Test\DataFactories;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use MailPoet\Models\NewsletterSegment;
|
||||
|
||||
class Newsletter {
|
||||
|
||||
@@ -11,6 +12,9 @@ class Newsletter {
|
||||
/** @var array */
|
||||
private $options;
|
||||
|
||||
/** @var array */
|
||||
private $segments;
|
||||
|
||||
public function __construct() {
|
||||
$this->data = [
|
||||
'subject' => 'Some subject',
|
||||
@@ -19,6 +23,7 @@ class Newsletter {
|
||||
'status' => 'draft',
|
||||
];
|
||||
$this->options = [];
|
||||
$this->segments = [];
|
||||
$this->loadBodyFrom('newsletterWithALC.json');
|
||||
}
|
||||
|
||||
@@ -38,6 +43,23 @@ class Newsletter {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withActiveStatus() {
|
||||
$this->data['status'] = 'active';
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withImmediateSendingSettings() {
|
||||
$this->withOptions([
|
||||
8 => 'immediately', # intervalType
|
||||
9 => '0', # timeOfDay
|
||||
10 => '1', # intervalType
|
||||
11 => '0', # monthDay
|
||||
12 => '1', # nthWeekDay
|
||||
13 => '* * * * *', # schedule
|
||||
]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Newsletter
|
||||
*/
|
||||
@@ -87,6 +109,17 @@ class Newsletter {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailPoet\Models\Segment[] $segments
|
||||
* @return Newsletter
|
||||
*/
|
||||
public function withSegments(array $segments) {
|
||||
foreach($segments as $segment) {
|
||||
$this->segments[] = $segment->id();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailPoet\Models\Newsletter
|
||||
*/
|
||||
@@ -101,6 +134,12 @@ class Newsletter {
|
||||
]
|
||||
);
|
||||
}
|
||||
foreach($this->segments as $segment_id) {
|
||||
NewsletterSegment::createOrUpdate([
|
||||
'newsletter_id' => $newsletter->id,
|
||||
'segment_id' => $segment_id,
|
||||
]);
|
||||
}
|
||||
return $newsletter;
|
||||
}
|
||||
}
|
||||
|
72
tests/acceptance/ReceivePostNotificationCest.php
Normal file
72
tests/acceptance/ReceivePostNotificationCest.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use Codeception\Util\Locator;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Test\DataFactories\Newsletter;
|
||||
use MailPoet\Test\DataFactories\Segment;
|
||||
use MailPoet\Test\DataFactories\Subscriber;
|
||||
|
||||
require_once __DIR__ . '/../DataFactories/Newsletter.php';
|
||||
require_once __DIR__ . '/../DataFactories/Segment.php';
|
||||
require_once __DIR__ . '/../DataFactories/Subscriber.php';
|
||||
|
||||
class ReceivePostNotificationCest {
|
||||
|
||||
function receivePostNotification(\AcceptanceTester $I) {
|
||||
Setting::setValue('tracking.enabled', false); // tracking makes this test very slow for some reason
|
||||
$I->wantTo('Receive a post notification email');
|
||||
$newsletter_subject = 'Post Notification Receive Test';
|
||||
$post_title = 'A post ' . \MailPoet\Util\Security::generateRandomString();
|
||||
|
||||
$segment_factory = new Segment();
|
||||
$segment = $segment_factory->withName('Receive Post Notification List')->create();
|
||||
|
||||
$subscriber_factory = new Subscriber();
|
||||
$subscriber_factory->withSegments([$segment])->create();
|
||||
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletter = $newsletterFactory->withSubject($newsletter_subject)
|
||||
->withPostNotificationsType()
|
||||
->withActiveStatus()
|
||||
->withImmediateSendingSettings()
|
||||
->withSegments([$segment])
|
||||
->create();
|
||||
$I->wait(1); //waiting 1 second so that post created time is after the newsletter
|
||||
|
||||
$I->cli(sprintf("post create --post_title='%s' --post_content='Lorem Ipsum' --post_status='publish' --allow-root", $post_title));
|
||||
|
||||
$I->login();
|
||||
|
||||
// scheduler will create a task and schedule run in the next whole minute, that can break the test
|
||||
// I move the task to the past
|
||||
// this workaround is not ideal, but we cannot wait another minute for the task to execute :(
|
||||
ScheduledTask::rawExecute(
|
||||
'UPDATE `' . ScheduledTask::$_table . '` t '
|
||||
. ' JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` '
|
||||
. ' SET t.scheduled_at="2016-01-01 01:02:03", t.updated_at="2016-01-01 01:02:03" '
|
||||
. ' WHERE q.newsletter_id=' . $newsletter->id()
|
||||
);
|
||||
|
||||
// confirm newsletter has been sent
|
||||
$I->amOnMailpoetPage('Emails');
|
||||
$I->click('[data-automation-id="tab-Post Notifications"]');
|
||||
$I->waitForText($newsletter_subject, 90);
|
||||
|
||||
$I->waitForText('View history', 90);
|
||||
$selector = sprintf('[data-automation-id="history-%d"]', $newsletter->id());
|
||||
$I->click($selector);
|
||||
$I->waitForText('Sent to 1 of 1', 90);
|
||||
|
||||
// confirm newsletter is received
|
||||
$I->amOnUrl('http://mailhog:8025');
|
||||
$I->waitForText($newsletter_subject, 90);
|
||||
$I->click(Locator::contains('span.subject', $newsletter_subject));
|
||||
$I->switchToIframe('preview-html');
|
||||
$I->waitForText($post_title, 90);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user