Move Mailer error tests to unit [MAILPOET-2009]
This commit is contained in:
@ -4,6 +4,7 @@ namespace MailPoet\Mailer\Methods\ErrorMappers;
|
||||
use MailPoet\Mailer\MailerError;
|
||||
use MailPoet\Mailer\Mailer;
|
||||
use MailPoet\Mailer\SubscriberError;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class AmazonSESMapper {
|
||||
use ConnectionErrorMapperTrait;
|
||||
@ -24,7 +25,7 @@ class AmazonSESMapper {
|
||||
function getErrorFromResponse($response, $subscriber) {
|
||||
$message = ($response) ?
|
||||
$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;
|
||||
if ($response && $response->Error->Code->__toString() === 'MessageRejected') {
|
||||
|
@ -92,20 +92,20 @@ class MailPoetMapper {
|
||||
private function getUnauthorizedEmailMessage($sender, $newsletter) {
|
||||
$email = $sender ? $sender['from_email'] : null;
|
||||
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>';
|
||||
if ($newsletter && $newsletter['id']) {
|
||||
$message .= '<a class="button button-primary" href="admin.php?page=mailpoet-newsletters#/send/' . $newsletter['id'] .'">';
|
||||
} else {
|
||||
$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>';
|
||||
} 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 .= 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',
|
||||
array(
|
||||
'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 .= "<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;
|
||||
}
|
||||
|
||||
private function getAccountBannedMessage() {
|
||||
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/',
|
||||
array(
|
||||
'target' => '_blank',
|
||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Mailer\Methods\ErrorMappers;
|
||||
use MailPoet\Mailer\MailerError;
|
||||
use MailPoet\Mailer\Mailer;
|
||||
use MailPoet\Mailer\SubscriberError;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class PHPMailMapper {
|
||||
use ConnectionErrorMapperTrait;
|
||||
@ -19,7 +20,7 @@ class PHPMailMapper {
|
||||
}
|
||||
|
||||
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)];
|
||||
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\Mailer;
|
||||
use MailPoet\Mailer\SubscriberError;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class SMTPMapper {
|
||||
use ConnectionErrorMapperTrait;
|
||||
@ -32,7 +33,7 @@ class SMTPMapper {
|
||||
// remove line breaks from the message due to how logger's dump() method works
|
||||
$message = preg_replace('/\r|\n/', '', $message);
|
||||
} 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)];
|
||||
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\Mailer;
|
||||
use MailPoet\Mailer\SubscriberError;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class SendGridMapper {
|
||||
use ConnectionErrorMapperTrait;
|
||||
@ -11,7 +12,7 @@ class SendGridMapper {
|
||||
function getErrorFromResponse($response, $subscriber) {
|
||||
$response = (!empty($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;
|
||||
if (strpos($response, 'Invalid email address') === 0) {
|
||||
|
Reference in New Issue
Block a user