Move Mailer error tests to unit [MAILPOET-2009]
This commit is contained in:
@ -8,8 +8,6 @@ use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper;
|
|||||||
use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper;
|
use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
|
||||||
|
|
||||||
class Mailer {
|
class Mailer {
|
||||||
public $mailer_config;
|
public $mailer_config;
|
||||||
public $sender;
|
public $sender;
|
||||||
|
@ -3,8 +3,6 @@ namespace MailPoet\Mailer;
|
|||||||
|
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
|
||||||
|
|
||||||
class MailerLog {
|
class MailerLog {
|
||||||
const SETTING_NAME = 'mta_log';
|
const SETTING_NAME = 'mta_log';
|
||||||
const STATUS_PAUSED = 'paused';
|
const STATUS_PAUSED = 'paused';
|
||||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Mailer\Methods\ErrorMappers;
|
|||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Mailer\SubscriberError;
|
use MailPoet\Mailer\SubscriberError;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class AmazonSESMapper {
|
class AmazonSESMapper {
|
||||||
use ConnectionErrorMapperTrait;
|
use ConnectionErrorMapperTrait;
|
||||||
@ -24,7 +25,7 @@ class AmazonSESMapper {
|
|||||||
function getErrorFromResponse($response, $subscriber) {
|
function getErrorFromResponse($response, $subscriber) {
|
||||||
$message = ($response) ?
|
$message = ($response) ?
|
||||||
$response->Error->Message->__toString() :
|
$response->Error->Message->__toString() :
|
||||||
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_AMAZONSES);
|
sprintf(WPFunctions::get()->__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_AMAZONSES);
|
||||||
|
|
||||||
$level = MailerError::LEVEL_HARD;
|
$level = MailerError::LEVEL_HARD;
|
||||||
if ($response && $response->Error->Code->__toString() === 'MessageRejected') {
|
if ($response && $response->Error->Code->__toString() === 'MessageRejected') {
|
||||||
|
@ -92,20 +92,20 @@ class MailPoetMapper {
|
|||||||
private function getUnauthorizedEmailMessage($sender, $newsletter) {
|
private function getUnauthorizedEmailMessage($sender, $newsletter) {
|
||||||
$email = $sender ? $sender['from_email'] : null;
|
$email = $sender ? $sender['from_email'] : null;
|
||||||
if ($email && (new FreeDomains())->isEmailOnFreeDomain($email)) {
|
if ($email && (new FreeDomains())->isEmailOnFreeDomain($email)) {
|
||||||
$message = '<p>' . sprintf(__('The MailPoet Sending Service can’t send email with the email address <i>%s</i>. You need to use an address like <i>you@yourdomain.com</i>.', 'mailpoet'), $email) . '</p>';
|
$message = '<p>' . sprintf(WPFunctions::get()->__('The MailPoet Sending Service can’t send email with the email address <i>%s</i>. You need to use an address like <i>you@yourdomain.com</i>.', 'mailpoet'), $email) . '</p>';
|
||||||
$message .= '<p>';
|
$message .= '<p>';
|
||||||
if ($newsletter && $newsletter['id']) {
|
if ($newsletter && $newsletter['id']) {
|
||||||
$message .= '<a class="button button-primary" href="admin.php?page=mailpoet-newsletters#/send/' . $newsletter['id'] .'">';
|
$message .= '<a class="button button-primary" href="admin.php?page=mailpoet-newsletters#/send/' . $newsletter['id'] .'">';
|
||||||
} else {
|
} else {
|
||||||
$message .= '<a class="button button-primary" href="admin.php?page=mailpoet-settings">';
|
$message .= '<a class="button button-primary" href="admin.php?page=mailpoet-settings">';
|
||||||
}
|
}
|
||||||
$message .= __('Change my email address', 'mailpoet');
|
$message .= WPFunctions::get()->__('Change my email address', 'mailpoet');
|
||||||
$message .= '</a>';
|
$message .= '</a>';
|
||||||
} else {
|
} else {
|
||||||
$message = sprintf(__('<p>The MailPoet Sending Service did not send your latest email because the address <i>%s</i> is not yet authorized.</p>', 'mailpoet'), $email ?: __('Unknown address'));
|
$message = sprintf(WPFunctions::get()->__('<p>The MailPoet Sending Service did not send your latest email because the address <i>%s</i> is not yet authorized.</p>', 'mailpoet'), $email ?: WPFunctions::get()->__('Unknown address'));
|
||||||
$message .= '<p>';
|
$message .= '<p>';
|
||||||
$message .= Helpers::replaceLinkTags(
|
$message .= Helpers::replaceLinkTags(
|
||||||
__('[link]Authorize your email in your account now.[/link]', 'mailpoet'),
|
WPFunctions::get()->__('[link]Authorize your email in your account now.[/link]', 'mailpoet'),
|
||||||
'https://account.mailpoet.com/authorization',
|
'https://account.mailpoet.com/authorization',
|
||||||
array(
|
array(
|
||||||
'class' => 'button button-primary',
|
'class' => 'button button-primary',
|
||||||
@ -114,15 +114,15 @@ class MailPoetMapper {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$message .= ' <button class="button js-button-resume-sending">' . __('Resume sending', 'mailpoet') . '</button>';
|
$message .= ' <button class="button js-button-resume-sending">' . WPFunctions::get()->__('Resume sending', 'mailpoet') . '</button>';
|
||||||
$message .= '</p>';
|
$message .= '</p>';
|
||||||
$message .= "<script>jQuery('.js-button-resume-sending').on('click', function() { MailPoet.Ajax.post({ api_version: window.mailpoet_api_version, endpoint: 'mailer', action: 'resumeSending' }).done(function() { jQuery('.js-error-unauthorized-email').slideUp(); MailPoet.Notice.success('" . __('Sending has been resumed.') . "'); if (window.mailpoet_listing) { window.mailpoet_listing.forceUpdate(); }}).fail(function(response) { if (response.errors.length > 0) { MailPoet.Notice.error(response.errors.map(function(error) { return error.message }), { scroll: true }); }}); })</script>";
|
$message .= "<script>jQuery('.js-button-resume-sending').on('click', function() { MailPoet.Ajax.post({ api_version: window.mailpoet_api_version, endpoint: 'mailer', action: 'resumeSending' }).done(function() { jQuery('.js-error-unauthorized-email').slideUp(); MailPoet.Notice.success('" . WPFunctions::get()->__('Sending has been resumed.') . "'); if (window.mailpoet_listing) { window.mailpoet_listing.forceUpdate(); }}).fail(function(response) { if (response.errors.length > 0) { MailPoet.Notice.error(response.errors.map(function(error) { return error.message }), { scroll: true }); }}); })</script>";
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAccountBannedMessage() {
|
private function getAccountBannedMessage() {
|
||||||
return Helpers::replaceLinkTags(
|
return Helpers::replaceLinkTags(
|
||||||
__('You currently are not permitted to send any emails with MailPoet Sending Service, which may have happened due to poor deliverability. Please [link]contact our support team[/link] to resolve the issue.', 'mailpoet'),
|
WPFunctions::get()->__('You currently are not permitted to send any emails with MailPoet Sending Service, which may have happened due to poor deliverability. Please [link]contact our support team[/link] to resolve the issue.', 'mailpoet'),
|
||||||
'https://www.mailpoet.com/support/',
|
'https://www.mailpoet.com/support/',
|
||||||
array(
|
array(
|
||||||
'target' => '_blank',
|
'target' => '_blank',
|
||||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Mailer\Methods\ErrorMappers;
|
|||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Mailer\SubscriberError;
|
use MailPoet\Mailer\SubscriberError;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class PHPMailMapper {
|
class PHPMailMapper {
|
||||||
use ConnectionErrorMapperTrait;
|
use ConnectionErrorMapperTrait;
|
||||||
@ -19,7 +20,7 @@ class PHPMailMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getErrorForSubscriber($subscriber) {
|
function getErrorForSubscriber($subscriber) {
|
||||||
$message = sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_PHPMAIL);
|
$message = sprintf(WPFunctions::get()->__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_PHPMAIL);
|
||||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||||
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $message, null, $subscriber_errors);
|
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $message, null, $subscriber_errors);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Mailer\Methods\ErrorMappers;
|
|||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Mailer\SubscriberError;
|
use MailPoet\Mailer\SubscriberError;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class SMTPMapper {
|
class SMTPMapper {
|
||||||
use ConnectionErrorMapperTrait;
|
use ConnectionErrorMapperTrait;
|
||||||
@ -32,7 +33,7 @@ class SMTPMapper {
|
|||||||
// remove line breaks from the message due to how logger's dump() method works
|
// remove line breaks from the message due to how logger's dump() method works
|
||||||
$message = preg_replace('/\r|\n/', '', $message);
|
$message = preg_replace('/\r|\n/', '', $message);
|
||||||
} else {
|
} else {
|
||||||
$message = sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SMTP);
|
$message = sprintf(WPFunctions::get()->__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SMTP);
|
||||||
}
|
}
|
||||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||||
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $message, null, $subscriber_errors);
|
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $message, null, $subscriber_errors);
|
||||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Mailer\Methods\ErrorMappers;
|
|||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Mailer\SubscriberError;
|
use MailPoet\Mailer\SubscriberError;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class SendGridMapper {
|
class SendGridMapper {
|
||||||
use ConnectionErrorMapperTrait;
|
use ConnectionErrorMapperTrait;
|
||||||
@ -11,7 +12,7 @@ class SendGridMapper {
|
|||||||
function getErrorFromResponse($response, $subscriber) {
|
function getErrorFromResponse($response, $subscriber) {
|
||||||
$response = (!empty($response['errors'][0])) ?
|
$response = (!empty($response['errors'][0])) ?
|
||||||
$response['errors'][0] :
|
$response['errors'][0] :
|
||||||
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SENDGRID);
|
sprintf(WPFunctions::get()->__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SENDGRID);
|
||||||
|
|
||||||
$level = MailerError::LEVEL_HARD;
|
$level = MailerError::LEVEL_HARD;
|
||||||
if (strpos($response, 'Invalid email address') === 0) {
|
if (strpos($response, 'Invalid email address') === 0) {
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
namespace MailPoet\Services\Bridge;
|
namespace MailPoet\Services\Bridge;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
|
||||||
|
|
||||||
class API {
|
class API {
|
||||||
const SENDING_STATUS_OK = 'ok';
|
const SENDING_STATUS_OK = 'ok';
|
||||||
const SENDING_STATUS_CONNECTION_ERROR = 'connection_error';
|
const SENDING_STATUS_CONNECTION_ERROR = 'connection_error';
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Test\Mailer;
|
namespace MailPoet\Test\Mailer;
|
||||||
|
|
||||||
|
use Codeception\Stub;
|
||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\SubscriberError;
|
use MailPoet\Mailer\SubscriberError;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class MailerErrorTest extends \MailPoetTest {
|
class MailerErrorTest extends \MailPoetUnitTest {
|
||||||
|
|
||||||
|
function _before() {
|
||||||
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'__' => function ($value) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
function testItCanComposeErrorMessageWithoutSubscribers() {
|
function testItCanComposeErrorMessageWithoutSubscribers() {
|
||||||
$error = new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, 'Some Message');
|
$error = new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, 'Some Message');
|
||||||
@ -37,4 +47,8 @@ class MailerErrorTest extends \MailPoetTest {
|
|||||||
'Some Message Unprocessed subscribers: (email1@example.com: Subscriber 1 message), (email2@example.com)'
|
'Some Message Unprocessed subscribers: (email1@example.com: Subscriber 1 message), (email2@example.com)'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
WPFunctions::set(new WPFunctions);
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ use MailPoet\Mailer\MailerError;
|
|||||||
use MailPoet\Mailer\Methods\ErrorMappers\AmazonSESMapper;
|
use MailPoet\Mailer\Methods\ErrorMappers\AmazonSESMapper;
|
||||||
use SimpleXMLElement;
|
use SimpleXMLElement;
|
||||||
|
|
||||||
class AmazonSESMapperTest extends \MailPoetTest {
|
class AmazonSESMapperTest extends \MailPoetUnitTest {
|
||||||
|
|
||||||
/** @var AmazonSESMapper*/
|
/** @var AmazonSESMapper*/
|
||||||
private $mapper;
|
private $mapper;
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
__halt_compiler();
|
||||||
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
||||||
|
|
||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
@ -6,7 +7,7 @@ use MailPoet\Mailer\Methods\ErrorMappers\MailPoetMapper;
|
|||||||
use MailPoet\Services\Bridge\API;
|
use MailPoet\Services\Bridge\API;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
class MailPoetMapperTest extends \MailPoetTest {
|
class MailPoetMapperTest extends \MailPoetUnitTest {
|
||||||
/** @var MailPoetMapper */
|
/** @var MailPoetMapper */
|
||||||
private $mapper;
|
private $mapper;
|
||||||
|
|
@ -1,10 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
||||||
|
|
||||||
|
use Codeception\Stub;
|
||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\Methods\ErrorMappers\PHPMailMapper;
|
use MailPoet\Mailer\Methods\ErrorMappers\PHPMailMapper;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class PHPMailMapperTest extends \MailPoetTest {
|
class PHPMailMapperTest extends \MailPoetUnitTest {
|
||||||
|
|
||||||
/** @var PHPMailMapper*/
|
/** @var PHPMailMapper*/
|
||||||
private $mapper;
|
private $mapper;
|
||||||
@ -12,6 +14,11 @@ class PHPMailMapperTest extends \MailPoetTest {
|
|||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->mapper = new PHPMailMapper();
|
$this->mapper = new PHPMailMapper();
|
||||||
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'__' => function ($value) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetProperErrorForSubscriber() {
|
function testGetProperErrorForSubscriber() {
|
||||||
@ -32,4 +39,8 @@ class PHPMailMapperTest extends \MailPoetTest {
|
|||||||
$error = $this->mapper->getErrorFromException(new \Exception('Invalid address. (Add ...'), 'john@rambo.com');
|
$error = $this->mapper->getErrorFromException(new \Exception('Invalid address. (Add ...'), 'john@rambo.com');
|
||||||
expect($error->getLevel())->equals(MailerError::LEVEL_SOFT);
|
expect($error->getLevel())->equals(MailerError::LEVEL_SOFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
WPFunctions::set(new WPFunctions);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
||||||
|
|
||||||
|
use Codeception\Stub;
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper;
|
use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class SMTPMapperTest extends \MailPoetTest {
|
class SMTPMapperTest extends \MailPoetUnitTest {
|
||||||
|
|
||||||
/** @var SMTPMapper */
|
/** @var SMTPMapper */
|
||||||
private $mapper;
|
private $mapper;
|
||||||
@ -13,6 +15,11 @@ class SMTPMapperTest extends \MailPoetTest {
|
|||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->mapper = new SMTPMapper();
|
$this->mapper = new SMTPMapper();
|
||||||
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
|
'__' => function ($value) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanProcessExceptionMessage() {
|
function testItCanProcessExceptionMessage() {
|
||||||
@ -55,4 +62,8 @@ class SMTPMapperTest extends \MailPoetTest {
|
|||||||
->equals(Mailer::METHOD_SMTP . ' has returned an unknown error.');
|
->equals(Mailer::METHOD_SMTP . ' has returned an unknown error.');
|
||||||
expect($error->getSubscriberErrors()[0]->getEmail('moi@mrcasual.com'));
|
expect($error->getSubscriberErrors()[0]->getEmail('moi@mrcasual.com'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
WPFunctions::set(new WPFunctions);
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
|||||||
use MailPoet\Mailer\MailerError;
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper;
|
use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper;
|
||||||
|
|
||||||
class SendGridMapperTest extends \MailPoetTest {
|
class SendGridMapperTest extends \MailPoetUnitTest {
|
||||||
|
|
||||||
/** @var SendGridMapper*/
|
/** @var SendGridMapper*/
|
||||||
private $mapper;
|
private $mapper;
|
Reference in New Issue
Block a user