From cad3ee2aabb8c5e272ddbbab2b32e1763ef8995f Mon Sep 17 00:00:00 2001 From: Veljko V Date: Mon, 6 Jul 2020 13:23:03 +0200 Subject: [PATCH] Add scenario various status newsletters MAILPOET-3042 --- tests/DataFactories/Newsletter.php | 21 +++++++++++ tests/acceptance/SettingsArchivePageCest.php | 38 ++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/tests/DataFactories/Newsletter.php b/tests/DataFactories/Newsletter.php index 221e4210bf..590e279b72 100644 --- a/tests/DataFactories/Newsletter.php +++ b/tests/DataFactories/Newsletter.php @@ -66,6 +66,16 @@ class Newsletter { return $this; } + public function withDraftStatus() { + $this->data['status'] = \MailPoet\Models\Newsletter::STATUS_DRAFT; + return $this; + } + + public function withScheduledStatus() { + $this->data['status'] = \MailPoet\Models\Newsletter::STATUS_SCHEDULED; + return $this; + } + public function withSenderAddress($address) { $this->data['sender_address'] = $address; return $this; @@ -249,6 +259,16 @@ class Newsletter { return $this; } + public function withScheduledQueue(array $options = []) { + $this->queueOptions = [ + 'status' => ScheduledTask::STATUS_SCHEDULED, + 'count_processed' => 0, + 'count_total' => 1, + ]; + $this->queueOptions = array_merge($this->queueOptions, $options); + return $this; + } + public function withSubscriber($subscriber, array $data = []) { $this->taskSubscribers[] = array_merge([ 'subscriber_id' => $subscriber->id, @@ -289,6 +309,7 @@ class Newsletter { $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(); foreach ($this->taskSubscribers as $data) { diff --git a/tests/acceptance/SettingsArchivePageCest.php b/tests/acceptance/SettingsArchivePageCest.php index 9896a08dd5..03dfa979ba 100644 --- a/tests/acceptance/SettingsArchivePageCest.php +++ b/tests/acceptance/SettingsArchivePageCest.php @@ -37,4 +37,42 @@ class SettingsArchivePageCest { $i->waitForText($pageTitle2); $i->waitForText('SentNewsletter'); } + + public function createArchivePageWithVariousStatusNewsletters(\AcceptanceTester $i) { + $i->wantTo('Create page with MP archive shortcode, showing only sent newsletters but having various in database'); + $segmentFactory = new Segment(); + $segment3 = $segmentFactory->withName('SentNewsletters')->create(); + $newsletterFactory = new Newsletter(); + $newsletterFactory->withSubject('SentNewsletter')->withSentStatus()->withSendingQueue()->withSegments([$segment3])->create(); + $newsletterFactory->withSubject('DraftNewsletter')->withDraftStatus()->withScheduledQueue()->withSegments([$segment3])->create(); + $newsletterFactory->withSubject('ScheduledNewsletter')->withScheduledStatus()->withScheduledQueue()->withSegments([$segment3])->create(); + $pageTitle3 = 'SentNewsletterArchive'; + $pageContent3 = "[mailpoet_archive segments=\"$segment3->id\"]"; + $i->cli(['post', 'create', '--post_type=page', '--post_status=publish', "--post_title=$pageTitle3", "--post_content=$pageContent3"]); + $i->login(); + $i->amOnPage('/wp-admin/edit.php?post_type=page'); + $i->waitForText($pageTitle3); + $i->clickItemRowActionByItemName($pageTitle3, 'View'); + $i->waitForText($pageTitle3); + $i->waitForText('SentNewsletter'); + $i->dontSee('DraftNewsletter'); + $i->dontSee('ScheduledNewsletter'); + $newsletterFactory->withSubject('SentNewsletter2')->withDraftStatus()->withSendingQueue()->withSegments([$segment3])->create(); + $newsletterFactory->withSubject('SentNewsletter3')->withDraftStatus()->withSendingQueue()->withSegments([$segment3])->create(); + $i->reloadPage(); + $i->waitForText('SentNewsletter'); + $i->waitForText('SentNewsletter2'); + $i->waitForText('SentNewsletter3'); + $i->amOnMailpoetPage('Emails'); + $i->waitForText('SentNewsletter3'); + $i->clickItemRowActionByItemName('SentNewsletter3', 'Move to trash'); + $i->waitForText('1 email was moved to the trash.'); + $i->amOnPage('/wp-admin/edit.php?post_type=page'); + $i->waitForText($pageTitle3); + $i->clickItemRowActionByItemName($pageTitle3, 'View'); + $i->waitForText($pageTitle3); + $i->waitForText('SentNewsletter'); + $i->waitForText('SentNewsletter2'); + $i->dontSee('SentNewsletter3'); + } }