Add scenario various status newsletters

MAILPOET-3042
This commit is contained in:
Veljko V
2020-07-06 13:23:03 +02:00
committed by Rostislav Wolný
parent f3e48867b8
commit cad3ee2aab
2 changed files with 59 additions and 0 deletions

View File

@ -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) {

View File

@ -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');
}
}