Refactor newsletter data factories to doctrine
[MAILPOET-3627]
This commit is contained in:
@ -118,6 +118,13 @@ class StatisticsClickEntity {
|
||||
$this->subscriber = $subscriber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SubscriberEntity|null
|
||||
*/
|
||||
public function getSubscriber(): ?SubscriberEntity {
|
||||
return $this->subscriber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewsletterLinkEntity|null $link
|
||||
*/
|
||||
|
@ -2,12 +2,18 @@
|
||||
|
||||
namespace MailPoet\Test\DataFactories;
|
||||
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\NewsletterOptionEntity;
|
||||
use MailPoet\Entities\NewsletterOptionFieldEntity;
|
||||
use MailPoet\Entities\NewsletterSegmentEntity;
|
||||
use MailPoet\Entities\ScheduledTaskEntity;
|
||||
use MailPoet\Entities\ScheduledTaskSubscriberEntity;
|
||||
use MailPoet\Entities\SegmentEntity;
|
||||
use MailPoet\Models\NewsletterSegment;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\ScheduledTaskSubscriber;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\Entities\SendingQueueEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
class Newsletter {
|
||||
|
||||
@ -60,22 +66,22 @@ class Newsletter {
|
||||
}
|
||||
|
||||
public function withActiveStatus() {
|
||||
$this->data['status'] = \MailPoet\Models\Newsletter::STATUS_ACTIVE;
|
||||
$this->data['status'] = NewsletterEntity::STATUS_ACTIVE;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withSentStatus() {
|
||||
$this->data['status'] = \MailPoet\Models\Newsletter::STATUS_SENT;
|
||||
$this->data['status'] = NewsletterEntity::STATUS_SENT;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDraftStatus() {
|
||||
$this->data['status'] = \MailPoet\Models\Newsletter::STATUS_DRAFT;
|
||||
$this->data['status'] = NewsletterEntity::STATUS_DRAFT;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withScheduledStatus() {
|
||||
$this->data['status'] = \MailPoet\Models\Newsletter::STATUS_SCHEDULED;
|
||||
$this->data['status'] = NewsletterEntity::STATUS_SCHEDULED;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -93,8 +99,8 @@ class Newsletter {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withParentId($parentId) {
|
||||
$this->data['parent_id'] = $parentId;
|
||||
public function withParent(NewsletterEntity $parent) {
|
||||
$this->data['parent'] = $parent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -130,7 +136,7 @@ class Newsletter {
|
||||
* @return Newsletter
|
||||
*/
|
||||
public function withPostNotificationHistoryType() {
|
||||
$this->data['type'] = \MailPoet\Models\Newsletter::TYPE_NOTIFICATION_HISTORY;
|
||||
$this->data['type'] = NewsletterEntity::TYPE_NOTIFICATION_HISTORY;
|
||||
$this->withOptions([]);
|
||||
return $this;
|
||||
}
|
||||
@ -247,14 +253,14 @@ class Newsletter {
|
||||
*/
|
||||
public function withSegments(array $segments) {
|
||||
foreach ($segments as $segment) {
|
||||
$this->segments[] = $segment->getId();
|
||||
$this->segments[] = $segment;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withSendingQueue(array $options = []) {
|
||||
$this->queueOptions = [
|
||||
'status' => ScheduledTask::STATUS_COMPLETED,
|
||||
'status' => ScheduledTaskEntity::STATUS_COMPLETED,
|
||||
'count_processed' => 1,
|
||||
'count_total' => 1,
|
||||
];
|
||||
@ -264,7 +270,7 @@ class Newsletter {
|
||||
|
||||
public function withScheduledQueue(array $options = []) {
|
||||
$this->queueOptions = [
|
||||
'status' => ScheduledTask::STATUS_SCHEDULED,
|
||||
'status' => ScheduledTaskEntity::STATUS_SCHEDULED,
|
||||
'count_processed' => 0,
|
||||
'count_total' => 1,
|
||||
];
|
||||
@ -272,9 +278,9 @@ class Newsletter {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withSubscriber($subscriber, array $data = []) {
|
||||
public function withSubscriber(SubscriberEntity $subscriber, array $data = []) {
|
||||
$this->taskSubscribers[] = array_merge([
|
||||
'subscriber_id' => $subscriber->id,
|
||||
'subscriber' => $subscriber,
|
||||
'processed' => 1,
|
||||
'failed' => 0,
|
||||
'error' => '',
|
||||
@ -282,49 +288,78 @@ class Newsletter {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailPoet\Models\Newsletter
|
||||
*/
|
||||
public function create() {
|
||||
$newsletter = \MailPoet\Models\Newsletter::createOrUpdate($this->data);
|
||||
foreach ($this->options as $optionId => $optionValue) {
|
||||
\MailPoet\Models\NewsletterOption::createOrUpdate(
|
||||
[
|
||||
'newsletter_id' => $newsletter->id,
|
||||
'option_field_id' => $optionId,
|
||||
'value' => $optionValue,
|
||||
]
|
||||
);
|
||||
}
|
||||
if ($this->data['sender_address']) {
|
||||
$newsletter->senderAddress = $this->data['sender_address'];
|
||||
$newsletter->save();
|
||||
}
|
||||
foreach ($this->segments as $segmentId) {
|
||||
NewsletterSegment::createOrUpdate([
|
||||
'newsletter_id' => $newsletter->id,
|
||||
'segment_id' => $segmentId,
|
||||
]);
|
||||
}
|
||||
if ($this->queueOptions) {
|
||||
$sendingTask = SendingTask::create();
|
||||
$sendingTask->newsletterId = $newsletter->id;
|
||||
$sendingTask->status = $this->queueOptions['status'];
|
||||
$sendingTask->countProcessed = $this->queueOptions['count_processed'];
|
||||
$sendingTask->countTotal = $this->queueOptions['count_total'];
|
||||
$sendingTask->newsletterRenderedSubject = $this->queueOptions['subject'] ?? $this->data['subject'];
|
||||
$sendingTask->save();
|
||||
public function create(): NewsletterEntity {
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$newsletter = $this->createNewsletter();
|
||||
$entityManager->persist($newsletter);
|
||||
|
||||
foreach ($this->taskSubscribers as $data) {
|
||||
$taskSubscriber = ScheduledTaskSubscriber::createOrUpdate([
|
||||
'subscriber_id' => $data['subscriber_id'],
|
||||
'task_id' => $sendingTask->taskId,
|
||||
'error' => $data['error'],
|
||||
'failed' => $data['failed'],
|
||||
'processed' => $data['processed'],
|
||||
]);
|
||||
}
|
||||
foreach ($this->options as $optionId => $optionValue) {
|
||||
$newsletterOption = $this->createOption($newsletter, $optionId, $optionValue);
|
||||
$entityManager->persist($newsletterOption);
|
||||
}
|
||||
|
||||
foreach ($this->segments as $segment) {
|
||||
$newsletterSegment = new NewsletterSegmentEntity($newsletter, $segment);
|
||||
$entityManager->persist($newsletterSegment);
|
||||
}
|
||||
|
||||
if ($this->queueOptions) {
|
||||
$this->createQueue($newsletter);
|
||||
}
|
||||
|
||||
$entityManager->flush();
|
||||
return $newsletter;
|
||||
}
|
||||
|
||||
private function createNewsletter(): NewsletterEntity {
|
||||
$newsletter = new NewsletterEntity();
|
||||
$newsletter->setSubject($this->data['subject']);
|
||||
$newsletter->setPreheader($this->data['preheader']);
|
||||
$newsletter->setType($this->data['type']);
|
||||
$newsletter->setStatus($this->data['status']);
|
||||
$newsletter->setBody($this->data['body']);
|
||||
if (isset($this->data['sender_address'])) {
|
||||
$newsletter->setSenderAddress($this->data['sender_address']);
|
||||
} else {
|
||||
$newsletter->setSenderAddress('john.doe@example.com');
|
||||
$newsletter->setSenderName('John Doe');
|
||||
}
|
||||
if (isset($this->data['parent'])) $newsletter->setParent($this->data['parent']);
|
||||
if (isset($this->data['deleted_at'])) $newsletter->setDeletedAt($this->data['deleted_at']);
|
||||
return $newsletter;
|
||||
}
|
||||
|
||||
private function createOption(NewsletterEntity $newsletter, int $optionId, string $optionValue): NewsletterOptionEntity {
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$newsletterOptionField = $entityManager->getReference(NewsletterOptionFieldEntity::class, $optionId);
|
||||
$newsletterOption = new NewsletterOptionEntity($newsletter, $newsletterOptionField);
|
||||
$newsletterOption->setValue($optionValue);
|
||||
return $newsletterOption;
|
||||
}
|
||||
|
||||
private function createQueue(NewsletterEntity $newsletter) {
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$scheduledTask = new ScheduledTaskEntity();
|
||||
$entityManager->persist($scheduledTask);
|
||||
$sendingQueue = new SendingQueueEntity();
|
||||
$sendingQueue->setTask($scheduledTask);
|
||||
$entityManager->persist($sendingQueue);
|
||||
$sendingQueue->setNewsletter($newsletter);
|
||||
$scheduledTask->setStatus($this->queueOptions['status']);
|
||||
$sendingQueue->setCountProcessed($this->queueOptions['count_processed']);
|
||||
$sendingQueue->setCountTotal($this->queueOptions['count_total']);
|
||||
$sendingQueue->setNewsletterRenderedSubject($this->queueOptions['subject'] ?? $this->data['subject']);
|
||||
$newsletter->getQueues()->add($sendingQueue);
|
||||
|
||||
foreach ($this->taskSubscribers as $data) {
|
||||
$taskSubscriber = new ScheduledTaskSubscriberEntity(
|
||||
$scheduledTask,
|
||||
$data['subscriber'],
|
||||
$data['processed'],
|
||||
$data['failed'],
|
||||
$data['error']
|
||||
);
|
||||
$entityManager->persist($taskSubscriber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,24 @@
|
||||
|
||||
namespace MailPoet\Test\DataFactories;
|
||||
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\NewsletterLink as NewsletterLinkModel;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\NewsletterLinkEntity;
|
||||
use MailPoet\Entities\SendingQueueEntity;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
class NewsletterLink {
|
||||
protected $data;
|
||||
|
||||
public function __construct(Newsletter $newsletter) {
|
||||
/** @var NewsletterEntity */
|
||||
private $newsletter;
|
||||
|
||||
public function __construct(NewsletterEntity $newsletter) {
|
||||
$this->data = [
|
||||
'newsletter_id' => $newsletter->id,
|
||||
'queue_id' => $newsletter->getQueue()->id,
|
||||
'url' => 'https://example.com/test',
|
||||
'hash' => 'hash',
|
||||
];
|
||||
$this->newsletter = $newsletter;
|
||||
}
|
||||
|
||||
public function withUrl($url) {
|
||||
@ -36,8 +41,18 @@ class NewsletterLink {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return NewsletterLinkModel */
|
||||
public function create() {
|
||||
return NewsletterLinkModel::createOrUpdate($this->data);
|
||||
public function create(): NewsletterLinkEntity {
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$queue = $this->newsletter->getLatestQueue();
|
||||
assert($queue instanceof SendingQueueEntity);
|
||||
$entity = new NewsletterLinkEntity(
|
||||
$this->newsletter,
|
||||
$queue,
|
||||
$this->data['url'],
|
||||
$this->data['hash']
|
||||
);
|
||||
$entityManager->persist($entity);
|
||||
$entityManager->flush();
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
@ -2,21 +2,29 @@
|
||||
|
||||
namespace MailPoet\Test\DataFactories;
|
||||
|
||||
use MailPoet\Models\NewsletterLink;
|
||||
use MailPoet\Models\StatisticsClicks as StatisticsClicksModel;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\NewsletterLinkEntity;
|
||||
use MailPoet\Entities\SendingQueueEntity;
|
||||
use MailPoet\Entities\StatisticsClickEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
class StatisticsClicks {
|
||||
protected $data;
|
||||
|
||||
public function __construct(NewsletterLink $newsletterLink, Subscriber $subscriber) {
|
||||
/** @var NewsletterLinkEntity */
|
||||
private $newsletterLink;
|
||||
|
||||
/** @var SubscriberEntity */
|
||||
private $subscriber;
|
||||
|
||||
public function __construct(NewsletterLinkEntity $newsletterLink, SubscriberEntity $subscriber) {
|
||||
$this->data = [
|
||||
'newsletter_id' => $newsletterLink->newsletterId,
|
||||
'subscriber_id' => $subscriber->id,
|
||||
'queue_id' => $newsletterLink->queueId,
|
||||
'link_id' => $newsletterLink->id,
|
||||
'count' => 1,
|
||||
];
|
||||
$this->newsletterLink = $newsletterLink;
|
||||
$this->subscriber = $subscriber;
|
||||
}
|
||||
|
||||
public function withCount($count) {
|
||||
@ -24,8 +32,21 @@ class StatisticsClicks {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return StatisticsClicksModel */
|
||||
public function create() {
|
||||
return StatisticsClicksModel::createOrUpdate($this->data);
|
||||
public function create(): StatisticsClickEntity {
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$newsletter = $this->newsletterLink->getNewsletter();
|
||||
assert($newsletter instanceof NewsletterEntity);
|
||||
$queue = $newsletter->getLatestQueue();
|
||||
assert($queue instanceof SendingQueueEntity);
|
||||
$entity = new StatisticsClickEntity(
|
||||
$newsletter,
|
||||
$queue,
|
||||
$this->subscriber,
|
||||
$this->newsletterLink,
|
||||
$this->data['count']
|
||||
);
|
||||
$entityManager->persist($entity);
|
||||
$entityManager->flush();
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
@ -7,33 +7,30 @@ use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\SendingQueueEntity;
|
||||
use MailPoet\Entities\StatisticsOpenEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
class StatisticsOpens {
|
||||
protected $data;
|
||||
|
||||
public function __construct(Newsletter $newsletter, Subscriber $subscriber) {
|
||||
$this->data = [
|
||||
'newsletter_id' => $newsletter->id,
|
||||
'subscriber_id' => $subscriber->id,
|
||||
'queue_id' => $newsletter->getQueue()->id,
|
||||
];
|
||||
/** @var NewsletterEntity */
|
||||
private $newsletter;
|
||||
|
||||
/** @var SubscriberEntity */
|
||||
private $subscriber;
|
||||
|
||||
public function __construct(NewsletterEntity $newsletter, SubscriberEntity $subscriber) {
|
||||
$this->newsletter = $newsletter;
|
||||
$this->subscriber = $subscriber;
|
||||
}
|
||||
|
||||
public function withCount($count) {
|
||||
$this->data['count'] = $count;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return StatisticsOpenEntity */
|
||||
public function create() {
|
||||
public function create(): StatisticsOpenEntity {
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$queue = $this->newsletter->getLatestQueue();
|
||||
assert($queue instanceof SendingQueueEntity);
|
||||
$entity = new StatisticsOpenEntity(
|
||||
$entityManager->getReference(NewsletterEntity::class, $this->data['newsletter_id']),
|
||||
$entityManager->getReference(SendingQueueEntity::class, $this->data['queue_id']),
|
||||
$entityManager->getReference(SubscriberEntity::class, $this->data['subscriber_id'])
|
||||
$this->newsletter,
|
||||
$queue,
|
||||
$this->subscriber
|
||||
);
|
||||
$entityManager->persist($entity);
|
||||
$entityManager->flush();
|
||||
|
@ -2,25 +2,52 @@
|
||||
|
||||
namespace MailPoet\Test\DataFactories;
|
||||
|
||||
use MailPoet\Models\StatisticsClicks;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\SendingQueueEntity;
|
||||
use MailPoet\Entities\StatisticsClickEntity;
|
||||
use MailPoet\Entities\StatisticsWooCommercePurchaseEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
class StatisticsWooCommercePurchases {
|
||||
protected $data;
|
||||
|
||||
public function __construct(StatisticsClicks $click, $order) {
|
||||
/** @var StatisticsClickEntity */
|
||||
private $click;
|
||||
|
||||
/** @var SubscriberEntity|null */
|
||||
private $subscriber;
|
||||
|
||||
public function __construct(StatisticsClickEntity $click, $order) {
|
||||
$this->data = [
|
||||
'newsletter_id' => $click->newsletterId,
|
||||
'subscriber_id' => $click->subscriberId,
|
||||
'queue_id' => $click->queueId,
|
||||
'click_id' => $click->id,
|
||||
'order_id' => $order['id'],
|
||||
'order_currency' => $order['currency'],
|
||||
'order_price_total' => $order['total'],
|
||||
];
|
||||
$this->subscriber = $click->getSubscriber();
|
||||
$this->click = $click;
|
||||
}
|
||||
|
||||
/** @return \MailPoet\Models\StatisticsWooCommercePurchases */
|
||||
public function create() {
|
||||
return \MailPoet\Models\StatisticsWooCommercePurchases::createOrUpdate($this->data);
|
||||
public function create(): StatisticsWooCommercePurchaseEntity {
|
||||
$newsletter = $this->click->getNewsletter();
|
||||
assert($newsletter instanceof NewsletterEntity);
|
||||
$queue = $newsletter->getLatestQueue();
|
||||
assert($queue instanceof SendingQueueEntity);
|
||||
assert($this->subscriber instanceof SubscriberEntity);
|
||||
$entity = new StatisticsWooCommercePurchaseEntity(
|
||||
$newsletter,
|
||||
$queue,
|
||||
$this->click,
|
||||
$this->data['order_id'],
|
||||
$this->data['order_currency'],
|
||||
$this->data['order_price_total']
|
||||
);
|
||||
$entity->setSubscriber($this->subscriber);
|
||||
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$entityManager->persist($entity);
|
||||
$entityManager->flush();
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,11 @@
|
||||
|
||||
namespace MailPoet\Test\DataFactories;
|
||||
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\SegmentEntity;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\Entities\SubscriberSegmentEntity;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
class Subscriber {
|
||||
|
||||
@ -76,17 +79,24 @@ class Subscriber {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailPoet\Models\Subscriber
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create() {
|
||||
$subscriber = \MailPoet\Models\Subscriber::createOrUpdate($this->data);
|
||||
public function create(): SubscriberEntity {
|
||||
$entityManager = ContainerWrapper::getInstance()->get(EntityManager::class);
|
||||
$subscriber = new SubscriberEntity();
|
||||
$subscriber->setStatus($this->data['status']);
|
||||
$subscriber->setEmail($this->data['email']);
|
||||
if (isset($this->data['count_confirmations'])) $subscriber->setConfirmationsCount($this->data['count_confirmations']);
|
||||
if (isset($this->data['last_name'])) $subscriber->setLastName($this->data['last_name']);
|
||||
if (isset($this->data['first_name'])) $subscriber->setFirstName($this->data['first_name']);
|
||||
$entityManager->persist($subscriber);
|
||||
|
||||
foreach ($this->segments as $segment) {
|
||||
SubscriberSegment::createOrUpdate([
|
||||
'subscriber_id' => $subscriber->id(),
|
||||
'segment_id' => $segment->getId(),
|
||||
]);
|
||||
$subscriberSegment = new SubscriberSegmentEntity($segment, $subscriber, 'subscribed');
|
||||
$entityManager->persist($subscriberSegment);
|
||||
}
|
||||
|
||||
$entityManager->flush();
|
||||
return $subscriber;
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ class WooCommercePastRevenues implements Generator {
|
||||
->withPostNotificationHistoryType()
|
||||
->withSegments([$subscribersListEntity])
|
||||
->withCreatedAt($sentAt)
|
||||
->withParentId($postNotification->id)
|
||||
->withParent($postNotification)
|
||||
->create();
|
||||
$sentPostNotifications[] = $this->createSentEmailData($newsletter, $sentAt, $subscribersIds, $subscribersList->id);
|
||||
}
|
||||
|
@ -159,10 +159,13 @@ class AcceptanceTester extends \Codeception\Actor {
|
||||
/**
|
||||
* Navigate to the editor for a newsletter.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int|null $id
|
||||
*/
|
||||
public function amEditingNewsletter($id) {
|
||||
$i = $this;
|
||||
if (is_null($id)) {
|
||||
throw new \Exception('No valid id passed');
|
||||
}
|
||||
$i->amOnPage('/wp-admin/admin.php?page=mailpoet-newsletter-editor&id=' . $id);
|
||||
$i->waitForElement('[data-automation-id="newsletter_title"]');
|
||||
$i->waitForElementNotVisible('.velocity-animating');
|
||||
@ -171,12 +174,12 @@ class AcceptanceTester extends \Codeception\Actor {
|
||||
public function createFormAndSubscribe(FormEntity $form = null) {
|
||||
$i = $this;
|
||||
// create form widget
|
||||
if ($form instanceof FormEntity) {
|
||||
if (!$form instanceof FormEntity) {
|
||||
$formFactory = new Form();
|
||||
$form = $formFactory->withName('Confirmation Form')->create();
|
||||
}
|
||||
$i->cli(['widget', 'reset', 'sidebar-1']);
|
||||
$i->cli(['widget', 'add', 'mailpoet_form', 'sidebar-1', '2', "--form=$form->getId()", '--title=Subscribe to Our Newsletter']);
|
||||
$i->cli(['widget', 'add', 'mailpoet_form', 'sidebar-1', '2', "--form={$form->getId()}", '--title=Subscribe to Our Newsletter']);
|
||||
|
||||
// subscribe
|
||||
/** @var FormMessageController $messageController */
|
||||
|
@ -13,7 +13,7 @@ class SubscriptionFormCest {
|
||||
/** @var string */
|
||||
private $subscriberEmail;
|
||||
|
||||
/** @var string|null */
|
||||
/** @var int|null */
|
||||
private $formId;
|
||||
|
||||
public function __construct() {
|
||||
|
@ -15,7 +15,7 @@ class ConfirmNotificationAutosaveCest {
|
||||
->create();
|
||||
// step 2 - Go to editor
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
// step 3 - Add subject, wait for Autosave
|
||||
$titleElement = '[data-automation-id="newsletter_title"]';
|
||||
$i->waitForElement($titleElement);
|
||||
|
@ -19,7 +19,7 @@ class ConfirmTitleAlignmentSettingsInALCBlockCest {
|
||||
|
||||
// open the newsletter in editor
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->waitForText($postTitle);
|
||||
|
||||
// open settings
|
||||
|
@ -16,16 +16,16 @@ class DeleteNotificationHistoryCest {
|
||||
$postNotificationHistory = (new Newsletter())
|
||||
->withSubject($newsletterName)
|
||||
->withPostNotificationHistoryType()
|
||||
->withParentId($postNotification->id)
|
||||
->withParent($postNotification)
|
||||
->create();
|
||||
// step 2 - Open list
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Emails');
|
||||
$i->click('Post Notifications', '[data-automation-id="newsletters_listing_tabs"]');
|
||||
$i->waitForElement('[data-automation-id="history-' . $postNotification->id . '"]');
|
||||
$i->click('[data-automation-id="history-' . $postNotification->id . '"]');
|
||||
$i->waitForElement('[data-automation-id="history-' . $postNotification->getId() . '"]');
|
||||
$i->click('[data-automation-id="history-' . $postNotification->getId() . '"]');
|
||||
//step 3 - Delete Notification
|
||||
$i->waitForElement('[data-automation-id="listing_item_' . $postNotificationHistory->id . '"]');
|
||||
$i->waitForElement('[data-automation-id="listing_item_' . $postNotificationHistory->getId() . '"]');
|
||||
$i->clickItemRowActionByItemName($newsletterName, 'Move to trash');
|
||||
$i->waitForElement('[data-automation-id="filters_trash"]');
|
||||
$i->click('[data-automation-id="filters_trash"]');
|
||||
|
@ -24,7 +24,7 @@ class EditExistingPostNotificationEmailCest {
|
||||
$i->click('Post Notifications', '[data-automation-id="newsletters_listing_tabs"]');
|
||||
|
||||
// step 3 - Open editation of post notifcation newsletter
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $newsletter->id . '"]';
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $newsletter->getId() . '"]';
|
||||
$i->waitForText('Edit Test Post Notification', 10, $listingAutomationSelector);
|
||||
$i->clickItemRowActionByItemName($newsletterTitle, 'Edit');
|
||||
|
||||
|
@ -15,7 +15,7 @@ class EditorDividerBlockCest {
|
||||
->loadBodyFrom('newsletterWithText.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->dragAndDrop('#automation_editor_block_divider', '#mce_0');
|
||||
$i->waitForElementNotVisible('.velocity-animating');
|
||||
//Open settings
|
||||
|
@ -14,7 +14,7 @@ class EditorFooterBlockCest {
|
||||
->loadBodyFrom('newsletterWithTextNoFooter.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->dragAndDrop('#automation_editor_block_footer', '#mce_0');
|
||||
//Open settings by clicking on block
|
||||
$i->moveMouseOver($footerInEditor, 3, 2);
|
||||
|
@ -15,7 +15,7 @@ class EditorHeaderBlockCest {
|
||||
->loadBodyFrom('newsletterWithTextNoHeader.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->dragAndDrop('#automation_editor_block_header', '#mce_0');
|
||||
//Prevent flakyness by adding footer mouse over and some checks
|
||||
$i->moveMouseOver($footer, 3, 2);
|
||||
|
@ -20,7 +20,7 @@ class EditorHistoryCest {
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$this->assessButtons($i, false, false);
|
||||
|
||||
$i->dragAndDrop('#automation_editor_block_button', '#mce_0');
|
||||
|
@ -12,7 +12,7 @@ class EditorImageBlockCest {
|
||||
->loadBodyFrom('newsletterWithText.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->dragAndDrop('#automation_editor_block_image', '#mce_0');
|
||||
$i->waitForText('Add images');
|
||||
$i->click('Media Library');
|
||||
|
@ -21,7 +21,7 @@ class EditorLineHeightCest {
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->click('.mailpoet_styles_region');
|
||||
|
||||
// set text sizes
|
||||
|
@ -2,13 +2,12 @@
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Models\Newsletter as NewsletterModel;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Test\DataFactories\Newsletter;
|
||||
use MailPoet\Test\DataFactories\WooCommerceProduct;
|
||||
use MailPoet\Util\Security;
|
||||
|
||||
class EditorProductsCest {
|
||||
|
||||
const EDITOR_PRODUCTS_SELECTOR = '.mailpoet_products_container > .mailpoet_block > .mailpoet_container';
|
||||
const EDITOR_PRODUCT_SELECTOR = '.mailpoet_products_container > .mailpoet_block > .mailpoet_container > .mailpoet_block';
|
||||
const PRICE_XPATH = '//*[name()="h2"][.//*[name()="span"][contains(@class, "woocommerce-Price-amount")]]';
|
||||
@ -30,7 +29,7 @@ class EditorProductsCest {
|
||||
/** @var WooCommerceProduct */
|
||||
private $productFactory;
|
||||
|
||||
/** @var NewsletterModel */
|
||||
/** @var NewsletterEntity */
|
||||
private $newsletter;
|
||||
|
||||
private function initializeNewsletter(\AcceptanceTester $i) {
|
||||
@ -44,7 +43,7 @@ class EditorProductsCest {
|
||||
$i->deactivateWooCommerce();
|
||||
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($this->newsletter->id);
|
||||
$i->amEditingNewsletter($this->newsletter->getId());
|
||||
|
||||
$i->waitForElementNotVisible('#automation_editor_block_products');
|
||||
}
|
||||
@ -91,7 +90,7 @@ class EditorProductsCest {
|
||||
|
||||
private function filterProducts(\AcceptanceTester $i) {
|
||||
$i->wantTo('Filter products');
|
||||
$i->amEditingNewsletter($this->newsletter->id);
|
||||
$i->amEditingNewsletter($this->newsletter->getId());
|
||||
|
||||
// Create products block (added wait checks to avoid flakiness)
|
||||
$i->waitForText('Content');
|
||||
|
@ -24,7 +24,7 @@ class EditorSettingsBehaviourCest {
|
||||
->withSubject($newsletterTitle)
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
|
||||
// Check settings are not visible at the beginning
|
||||
$i->dontSee(self::SETTINGS_PANEL_SELECTOR);
|
||||
|
@ -15,7 +15,7 @@ class EditorSocialBlockCest {
|
||||
->loadBodyFrom('newsletterWithText.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->dragAndDrop('#automation_editor_block_social', '#mce_1');
|
||||
//Prevent flakyness by adding footer mouse over
|
||||
$i->moveMouseOver($footer, 3, 2);
|
||||
|
@ -15,7 +15,7 @@ class EditorSpacerBlockCest {
|
||||
->loadBodyFrom('newsletterWithText.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->dragAndDrop('#automation_editor_block_spacer', '#mce_1');
|
||||
//Open settings by clicking on block
|
||||
$i->moveMouseOver($footer, 3, 2);
|
||||
|
@ -17,7 +17,7 @@ class EditorTextBlockCest {
|
||||
->loadBodyFrom('newsletterWithText.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->dragAndDrop('#automation_editor_block_text', '#mce_1');
|
||||
$i->waitForText('Edit this to insert text.');
|
||||
}
|
||||
@ -30,7 +30,7 @@ class EditorTextBlockCest {
|
||||
->loadBodyFrom('newsletterThreeCols.json')
|
||||
->create();
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->click(self::TEXT_BLOCK_SELECTOR);
|
||||
$i->waitForElementVisible(self::TINYMCE_SELECTOR);
|
||||
$i->click(self::CONTAINER_SELECTOR);
|
||||
|
@ -54,7 +54,7 @@ class ReceivePostNotificationCest {
|
||||
'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()
|
||||
. ' WHERE q.newsletter_id=' . $newsletter->getId()
|
||||
);
|
||||
|
||||
// confirm newsletter has been sent
|
||||
@ -63,7 +63,7 @@ class ReceivePostNotificationCest {
|
||||
$i->waitForText($newsletterSubject, 90);
|
||||
|
||||
$i->waitForText('View history', 90);
|
||||
$selector = sprintf('[data-automation-id="history-%d"]', $newsletter->id());
|
||||
$selector = sprintf('[data-automation-id="history-%d"]', $newsletter->getId());
|
||||
$i->click($selector);
|
||||
$i->waitForText('1 / 1', 90);
|
||||
|
||||
|
@ -18,7 +18,7 @@ class SaveNewsletterAsTemplateCest {
|
||||
|
||||
// step 2 - Go to editor
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
|
||||
//step 3 - save as a template
|
||||
$i->click('[data-automation-id="newsletter_save_options_toggle"]');
|
||||
|
@ -17,7 +17,7 @@ class SaveNotificationAsDraftCest {
|
||||
$segmentName = $i->createListWithSubscriber();
|
||||
// step 2 - Go to editor
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->click('Next');
|
||||
//Save Notification As Draft
|
||||
$sendFormElement = '[data-automation-id="newsletter_send_form"]';
|
||||
|
@ -20,7 +20,7 @@ class SavePostNotificationEmailAsTemplateCest {
|
||||
|
||||
// step 2 - Go to editor
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
|
||||
// step 3 - Save as template
|
||||
$saveTemplateOption = '[data-automation-id="newsletter_save_as_template_option"]';
|
||||
|
@ -17,7 +17,7 @@ class ScheduleNewsletterCest {
|
||||
|
||||
// step 2 - Go to editor
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->click('Next');
|
||||
|
||||
// step 4 - Choose list and schedule
|
||||
|
@ -33,12 +33,12 @@ class SendingStatusCest {
|
||||
// When I visit the newsletters page
|
||||
$i->login();
|
||||
$i->amOnMailPoetPage('Emails');
|
||||
$i->waitForText($newsletter->subject);
|
||||
$i->waitForText($newsletter->getSubject());
|
||||
// I click on the "Sent to 2 of 2" link
|
||||
$i->click('[data-automation-id="sending_status_' . $newsletter->id . '"]');
|
||||
$i->click('[data-automation-id="sending_status_' . $newsletter->getId() . '"]');
|
||||
$i->waitForText('Sending status');
|
||||
// I see the subscribers with related statuses
|
||||
$taskId = $newsletter->getQueue()->task_id;
|
||||
$taskId = $newsletter->getLatestQueue()->getTask()->getId();
|
||||
$this->checkSubscriber($i, $taskId, $luckySubscriber, 'Sent');
|
||||
$this->checkSubscriber($i, $taskId, $unluckySubscriber, 'Failed', 'Oh no!');
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class SentNewsletterCest {
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->waitForElement('.mailpoet_save_next.button-disabled');
|
||||
$i->see('This email has already been sent.');
|
||||
$i->see('It can be edited, but not sent again.');
|
||||
|
@ -18,8 +18,8 @@ class MailPoetCustomFieldSegmentCest {
|
||||
$subscriber3 = (new Subscriber())
|
||||
->withEmail('test3@example.com')
|
||||
->create();
|
||||
$customField->withSubscriber($subscriber2->id(), 'some value1 here');
|
||||
$customField->withSubscriber($subscriber3->id(), 'some value2 here');
|
||||
$customField->withSubscriber($subscriber2->getId(), 'some value1 here');
|
||||
$customField->withSubscriber($subscriber3->getId(), 'some value2 here');
|
||||
$customField->create();
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ class AuthorizedEmailAddressesValidationCest {
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->click('Next');
|
||||
$i->waitForText('Sender');
|
||||
$i->fillField('[name="sender_address"]', 'unauthorized@email.com');
|
||||
|
@ -37,7 +37,7 @@ class RevenueTrackingCookieCest {
|
||||
$i->waitForText('Settings saved');
|
||||
|
||||
// send any newsletter with a link
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->click('Next');
|
||||
|
||||
$i->waitForElement('[data-automation-id="newsletter_send_form"]');
|
||||
@ -75,7 +75,7 @@ class RevenueTrackingCookieCest {
|
||||
$i->click('[data-automation-id="settings-submit-button"]');
|
||||
$i->waitForText('Settings saved');
|
||||
// send any newsletter with a link
|
||||
$i->amEditingNewsletter($newsletter->id);
|
||||
$i->amEditingNewsletter($newsletter->getId());
|
||||
$i->click('Next');
|
||||
|
||||
$i->waitForElement('[data-automation-id="newsletter_send_form"]');
|
||||
|
@ -40,7 +40,9 @@ class SettingsArchivePageCest {
|
||||
$segment3 = $segmentFactory->withName('SentNewsletters')->create();
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletterFactory->withSubject('SentNewsletter')->withSentStatus()->withSendingQueue()->withSegments([$segment3])->create();
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletterFactory->withSubject('DraftNewsletter')->withDraftStatus()->withScheduledQueue()->withSegments([$segment3])->create();
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletterFactory->withSubject('ScheduledNewsletter')->withScheduledStatus()->withScheduledQueue()->withSegments([$segment3])->create();
|
||||
$pageTitle3 = 'SentNewsletterArchive';
|
||||
$pageContent3 = "[mailpoet_archive segments=\"{$segment3->getId()}\"]";
|
||||
@ -51,7 +53,9 @@ class SettingsArchivePageCest {
|
||||
$i->waitForText('SentNewsletter');
|
||||
$i->dontSee('DraftNewsletter');
|
||||
$i->dontSee('ScheduledNewsletter');
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletterFactory->withSubject('SentNewsletter2')->withDraftStatus()->withSendingQueue()->withSegments([$segment3])->create();
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletterFactory->withSubject('SentNewsletter3')->withDraftStatus()->withSendingQueue()->withSegments([$segment3])->create();
|
||||
$i->reloadPage();
|
||||
$i->waitForText('SentNewsletter');
|
||||
|
@ -12,7 +12,9 @@ class ExportSubscribersCest {
|
||||
$segment = $segmentFactory->withName($segmentName)->create();
|
||||
$subscriberFactory = new Subscriber();
|
||||
$subscriberFactory->withSegments([$segment])->withEmail('one@fake.fake')->create();
|
||||
$subscriberFactory = new Subscriber();
|
||||
$subscriberFactory->withSegments([$segment])->withEmail('two@fake.fake')->create();
|
||||
$subscriberFactory = new Subscriber();
|
||||
$subscriberFactory->withSegments([$segment])->withEmail('three@fake.fake')->create();
|
||||
$i->wantTo('Export a list of subscribers');
|
||||
$i->login();
|
||||
|
@ -75,8 +75,8 @@ class SubscribersListingCest {
|
||||
|
||||
$i->wantTo('Select first two subscribers and unsubscribe them');
|
||||
$i->waitForText('subscriber1@example.com');
|
||||
$i->click("[data-automation-id='listing-row-checkbox-$subscriber1->id']");
|
||||
$i->click("[data-automation-id='listing-row-checkbox-$subscriber2->id']");
|
||||
$i->click("[data-automation-id='listing-row-checkbox-{$subscriber1->getId()}']");
|
||||
$i->click("[data-automation-id='listing-row-checkbox-{$subscriber2->getId()}']");
|
||||
|
||||
$i->waitForElement("[data-automation-id='action-unsubscribe']");
|
||||
$i->click("[data-automation-id='action-unsubscribe']");
|
||||
@ -87,11 +87,11 @@ class SubscribersListingCest {
|
||||
|
||||
$i->wantTo('Check the final status');
|
||||
$i->waitForText('subscriber2@example.com');
|
||||
$i->waitForText('Unsubscribed', 10, "[data-automation-id='listing_item_$subscriber1->id']");
|
||||
$i->waitForText('Unsubscribed', 10, "[data-automation-id='listing_item_$subscriber2->id']");
|
||||
$i->waitForText('Subscribed', 10, "[data-automation-id='listing_item_$subscriber3->id']");
|
||||
$i->waitForText('Subscribed', 10, "[data-automation-id='listing_item_$subscriber4->id']");
|
||||
$i->dontSee('Unsubscribed', "[data-automation-id='listing_item_$subscriber3->id']");
|
||||
$i->dontSee('Unsubscribed', "[data-automation-id='listing_item_$subscriber4->id']");
|
||||
$i->waitForText('Unsubscribed', 10, "[data-automation-id='listing_item_{$subscriber1->getId()}']");
|
||||
$i->waitForText('Unsubscribed', 10, "[data-automation-id='listing_item_{$subscriber2->getId()}']");
|
||||
$i->waitForText('Subscribed', 10, "[data-automation-id='listing_item_{$subscriber3->getId()}']");
|
||||
$i->waitForText('Subscribed', 10, "[data-automation-id='listing_item_{$subscriber4->getId()}']");
|
||||
$i->dontSee('Unsubscribed', "[data-automation-id='listing_item_{$subscriber3->getId()}']");
|
||||
$i->dontSee('Unsubscribed', "[data-automation-id='listing_item_{$subscriber4->getId()}']");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user