From cf17d5b693fe61d6654a4e76e48b0df43f5775f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Wed, 27 Feb 2019 17:40:53 +0100 Subject: [PATCH] Add tests for sending error notices [MAILPOET-1699] --- tests/DataFactories/Settings.php | 13 ++++ .../acceptance/NewsletterSendingErrorCest.php | 59 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/acceptance/NewsletterSendingErrorCest.php diff --git a/tests/DataFactories/Settings.php b/tests/DataFactories/Settings.php index 17190b0415..b9e835a0a9 100644 --- a/tests/DataFactories/Settings.php +++ b/tests/DataFactories/Settings.php @@ -2,6 +2,7 @@ namespace MailPoet\Test\DataFactories; +use MailPoet\Mailer\Mailer; use MailPoet\Settings\SettingsController; class Settings { @@ -56,4 +57,16 @@ class Settings { $this->settings->set('show_congratulate_after_first_newsletter', 0); return $this; } + + function withSendingMethod($sending_method) { + $this->settings->set('mta.method', $sending_method); + $this->settings->set('mta_group', $sending_method === Mailer::METHOD_SMTP ? 'smtp' : 'website'); + } + + function withSendingError($error_message, $operation = 'send') { + $this->settings->set('mta_log.status', 'paused'); + $this->settings->set('mta_log.error.operation', $operation); + $this->settings->set('mta_log.error.error_message', $error_message); + return $this; + } } diff --git a/tests/acceptance/NewsletterSendingErrorCest.php b/tests/acceptance/NewsletterSendingErrorCest.php new file mode 100644 index 0000000000..635e986b5e --- /dev/null +++ b/tests/acceptance/NewsletterSendingErrorCest.php @@ -0,0 +1,59 @@ +wantTo('See proper sending error when sending failed'); + $I->login(); + + $errorMessage = 'Error while sending email.'; + $settings = new Settings(); + $settings->withSendingMethod(Mailer::METHOD_SMTP); + $settings->withSendingError($errorMessage); + + $I->amOnMailpoetPage('Emails'); + $I->waitForElement('.mailpoet_notice.notice-error div'); + $I->see('Sending has been paused due to a technical issue with SMTP: ' . $errorMessage, '.notice-error p'); + $I->see('Check your sending method settings.', '.notice-error p'); + $I->see('Resume sending', '.notice-error p'); + + $href = $I->grabAttributeFrom('//a[text()="sending method settings"]', 'href'); + expect($href)->endsWith('page=mailpoet-settings#mta'); + + $I->click('Resume sending'); + $I->waitForText('Sending has been resumed.'); + } + + function phpMailErrorNotice(\AcceptanceTester $I) { + $I->wantTo('See proper sending error when sending failed with PHPMail'); + $I->login(); + + $errorMessage = 'Could not instantiate mail function. Unprocessed subscriber: (test )'; + $settings = new Settings(); + $settings->withSendingMethod(Mailer::METHOD_PHPMAIL); + $settings->withSendingError($errorMessage); + + $I->amOnMailpoetPage('Emails'); + $I->waitForElement('.mailpoet_notice.notice-error div'); + $I->see('Sending has been paused due to a technical issue with PHPMail: ' . $errorMessage, '.notice-error p'); + $I->see('Please check your sending method configuration, you may need to consult with your hosting company.', '.notice-error p'); + $I->see('The easy alternative is to send emails with MailPoet Sending Service instead, like thousand of other users do.', '.notice-error p'); + $I->see('Sign up for free in minutes', '.notice-error p'); + $I->see('Resume sending', '.notice-error p'); + + $I->seeElement('a', [ + 'text' => 'Sign up for free in minutes', + 'href' => 'https://www.mailpoet.com/free-plan/?utm_source=plugin&utm_campaign=sending-error', + 'target' => '_blank', + ]); + + $I->click('Resume sending'); + $I->waitForText('Sending has been resumed.'); + } +}