- Refactors MailPoet mailer class + tests
- Includes MailPoet mailer inside Mailer router - Adjusts Newsletter router to work with new MailPoet mailer - Updates tests for all mailers
This commit is contained in:
@ -4,9 +4,9 @@ namespace MailPoet\Mailer\API;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class AmazonSES {
|
||||
function __construct($region, $access_key, $secret_key, $from) {
|
||||
$this->awsAccessKey = $access_key;
|
||||
$this->awsSecret_key = $secret_key;
|
||||
function __construct($region, $accessKey, $secretKey, $from) {
|
||||
$this->awsAccessKey = $accessKey;
|
||||
$this->awsSecret_key = $secretKey;
|
||||
$this->awsRegion = $region;
|
||||
$this->awsEndpoint = sprintf('email.%s.amazonaws.com', $region);
|
||||
$this->awsSigningAlgorithm = 'AWS4-HMAC-SHA256';
|
||||
@ -26,11 +26,14 @@ class AmazonSES {
|
||||
$this->url,
|
||||
$this->request()
|
||||
);
|
||||
return ($result['response']['code'] === 200);
|
||||
return (
|
||||
!is_wp_error($result) === true &&
|
||||
wp_remote_retrieve_response_code($result) === 200
|
||||
);
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
$parameters = array(
|
||||
return array(
|
||||
'Action' => 'SendEmail',
|
||||
'Version' => '2010-12-01',
|
||||
'Source' => $this->from,
|
||||
@ -40,7 +43,6 @@ class AmazonSES {
|
||||
'Message.Body.Text.Data' => $this->newsletter['body']['text'],
|
||||
'ReturnPath' => $this->from
|
||||
);
|
||||
return urldecode(http_build_query($parameters));
|
||||
}
|
||||
|
||||
function request() {
|
||||
@ -53,7 +55,7 @@ class AmazonSES {
|
||||
'Authorization' => $this->signRequest($this->getBody()),
|
||||
'X-Amz-Date' => $this->date
|
||||
),
|
||||
'body' => $this->getBody()
|
||||
'body' => urldecode(http_build_query($this->getBody()))
|
||||
);
|
||||
}
|
||||
|
||||
@ -85,7 +87,7 @@ class AmazonSES {
|
||||
'x-amz-date:' . $this->date,
|
||||
'',
|
||||
'host;x-amz-date',
|
||||
hash($this->hashAlgorithm, $this->getBody())
|
||||
hash($this->hashAlgorithm, urldecode(http_build_query($this->getBody())))
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,11 @@ namespace MailPoet\Mailer\API;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class ElasticEmail {
|
||||
function __construct($api_key, $from_email, $from_name) {
|
||||
function __construct($apiKey, $fromEmail, $fromName) {
|
||||
$this->url = 'https://api.elasticemail.com/mailer/send';
|
||||
$this->api_key = $api_key;
|
||||
$this->from_name = $from_name;
|
||||
$this->from_email = $from_email;
|
||||
$this->apiKey = $apiKey;
|
||||
$this->fromEmail = $fromEmail;
|
||||
$this->fromName = $fromName;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@ -17,21 +17,22 @@ class ElasticEmail {
|
||||
$result = wp_remote_post(
|
||||
$this->url,
|
||||
$this->request());
|
||||
if(is_object($result) && get_class($result) === 'WP_Error') return false;
|
||||
return (!preg_match('/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/', $result['body']) === false);
|
||||
return (
|
||||
!is_wp_error($result) === true &&
|
||||
!preg_match('/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/', $result['body']) === false
|
||||
);
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
$parameters = array(
|
||||
'api_key' => $this->api_key,
|
||||
'from' => $this->from_email,
|
||||
'from_name' => $this->from_name,
|
||||
return array(
|
||||
'api_key' => $this->apiKey,
|
||||
'from' => $this->fromEmail,
|
||||
'from_name' => $this->fromName,
|
||||
'to' => $this->subscriber,
|
||||
'subject' => $this->newsletter['subject'],
|
||||
'body_html' => $this->newsletter['body']['html'],
|
||||
'body_text' => $this->newsletter['body']['text']
|
||||
);
|
||||
return urldecode(http_build_query($parameters));
|
||||
}
|
||||
|
||||
function request() {
|
||||
@ -39,7 +40,7 @@ class ElasticEmail {
|
||||
'timeout' => 10,
|
||||
'httpversion' => '1.0',
|
||||
'method' => 'POST',
|
||||
'body' => $this->getBody()
|
||||
'body' => urldecode(http_build_query($this->getBody()))
|
||||
);
|
||||
}
|
||||
}
|
@ -4,10 +4,9 @@ namespace MailPoet\Mailer\API;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class MailGun {
|
||||
function __construct($domain, $api_key, $from) {
|
||||
$this->url = 'https://api.mailgun.net/v3';
|
||||
$this->domain = $domain;
|
||||
$this->api_key = $api_key;
|
||||
function __construct($domain, $apiKey, $from) {
|
||||
$this->url = sprintf('https://api.mailgun.net/v3/%s/messages', $domain);
|
||||
$this->apiKey = $apiKey;
|
||||
$this->from = $from;
|
||||
}
|
||||
|
||||
@ -15,26 +14,27 @@ class MailGun {
|
||||
$this->newsletter = $newsletter;
|
||||
$this->subscriber = $subscriber;
|
||||
$result = wp_remote_post(
|
||||
$this->url . '/' . $this->domain . '/messages',
|
||||
$this->url,
|
||||
$this->request()
|
||||
);
|
||||
if(is_object($result) && get_class($result) === 'WP_Error') return false;
|
||||
return ($result['response']['code'] === 200);
|
||||
return (
|
||||
!is_wp_error($result) === true &&
|
||||
wp_remote_retrieve_response_code($result) === 200
|
||||
);
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
$parameters = array(
|
||||
return array(
|
||||
'from' => $this->from,
|
||||
'to' => $this->subscriber,
|
||||
'subject' => $this->newsletter['subject'],
|
||||
'html' => $this->newsletter['body']['html'],
|
||||
'text' => $this->newsletter['body']['text']
|
||||
);
|
||||
return urldecode(http_build_query($parameters));
|
||||
}
|
||||
|
||||
function auth() {
|
||||
return 'Basic ' . base64_encode('api:' . $this->api_key);
|
||||
return 'Basic ' . base64_encode('api:' . $this->apiKey);
|
||||
}
|
||||
|
||||
function request() {
|
||||
@ -46,7 +46,7 @@ class MailGun {
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'Authorization' => $this->auth()
|
||||
),
|
||||
'body' => $this->getBody()
|
||||
'body' => urldecode(http_build_query($this->getBody()))
|
||||
);
|
||||
}
|
||||
}
|
73
lib/Mailer/API/MailPoet.php
Normal file
73
lib/Mailer/API/MailPoet.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace MailPoet\Mailer\API;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class MailPoet {
|
||||
function __construct($apiKey, $fromEmail, $fromName) {
|
||||
$this->url = 'https://bridge.mailpoet.com/api/messages';
|
||||
$this->apiKey = $apiKey;
|
||||
$this->fromEmail = $fromEmail;
|
||||
$this->fromName = $fromName;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
$this->newsletter = $newsletter;
|
||||
$this->subscriber = $this->processSubscriber($subscriber);
|
||||
$result = wp_remote_post(
|
||||
$this->url,
|
||||
$this->request()
|
||||
);
|
||||
return (
|
||||
!is_wp_error($result) === true &&
|
||||
wp_remote_retrieve_response_code($result) === 201
|
||||
);
|
||||
}
|
||||
|
||||
function processSubscriber($subscriber) {
|
||||
preg_match('!(?P<name>.*?)\s<(?P<email>.*?)>!', $subscriber, $subscriberData);
|
||||
if(!isset($subscriberData['email'])) {
|
||||
$subscriberData = array(
|
||||
'email' => $subscriber,
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'email' => $subscriberData['email'],
|
||||
'name' => (isset($subscriberData['name'])) ? $subscriberData['name'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
return array(
|
||||
'to' => (array(
|
||||
'address' => $this->subscriber['email'],
|
||||
'name' => $this->subscriber['name']
|
||||
)),
|
||||
'from' => (array(
|
||||
'address' => $this->fromEmail,
|
||||
'name' => $this->fromName
|
||||
)),
|
||||
'subject' => $this->newsletter['subject'],
|
||||
'html' => $this->newsletter['body']['html'],
|
||||
'text' => $this->newsletter['body']['text']
|
||||
);
|
||||
}
|
||||
|
||||
function auth() {
|
||||
return 'Basic ' . base64_encode('api:' . $this->apiKey);
|
||||
}
|
||||
|
||||
function request() {
|
||||
$request = array(
|
||||
'timeout' => 10,
|
||||
'httpversion' => '1.0',
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => $this->auth()
|
||||
),
|
||||
'body' => json_encode(array($this->getBody()))
|
||||
);
|
||||
return $request;
|
||||
}
|
||||
}
|
@ -4,11 +4,11 @@ namespace MailPoet\Mailer\API;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Mandrill {
|
||||
function __construct($api_key, $from_email, $from_name) {
|
||||
function __construct($apiKey, $fromEmail, $fromName) {
|
||||
$this->url = 'https://mandrillapp.com/api/1.0/messages/send.json';
|
||||
$this->api_key = $api_key;
|
||||
$this->from_name = $from_name;
|
||||
$this->from_email = $from_email;
|
||||
$this->apiKey = $apiKey;
|
||||
$this->fromName = $fromName;
|
||||
$this->fromEmail = $fromEmail;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@ -18,8 +18,11 @@ class Mandrill {
|
||||
$this->url,
|
||||
$this->request()
|
||||
);
|
||||
if(is_object($result) && get_class($result) === 'WP_Error') return false;
|
||||
return (!preg_match('!invalid!', $result['body']) === true && $result['response']['code'] === 200);
|
||||
return (
|
||||
!is_wp_error($result) === true &&
|
||||
!preg_match('!invalid!', $result['body']) === true &&
|
||||
wp_remote_retrieve_response_code($result) === 200
|
||||
);
|
||||
}
|
||||
|
||||
function processSubscriber($subscriber) {
|
||||
@ -30,20 +33,18 @@ class Mandrill {
|
||||
);
|
||||
}
|
||||
return array(
|
||||
array(
|
||||
'name' => (isset($subscriberData['name'])) ? $subscriberData['name'] : '',
|
||||
'email' => $subscriberData['email']
|
||||
)
|
||||
'email' => $subscriberData['email'],
|
||||
'name' => (isset($subscriberData['name'])) ? $subscriberData['name'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
return array(
|
||||
'key' => $this->api_key,
|
||||
'key' => $this->apiKey,
|
||||
'message' => array(
|
||||
'from_email' => $this->from_email,
|
||||
'from_name' => $this->from_name,
|
||||
'to' => $this->subscriber,
|
||||
'from_email' => $this->fromEmail,
|
||||
'from_name' => $this->fromName,
|
||||
'to' => array($this->subscriber),
|
||||
'subject' => $this->newsletter['subject'],
|
||||
'html' => $this->newsletter['body']['html'],
|
||||
'text' => $this->newsletter['body']['text']
|
||||
|
@ -4,11 +4,11 @@ namespace MailPoet\Mailer\API;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class SendGrid {
|
||||
function __construct($api_key, $from_email, $from_name) {
|
||||
function __construct($apiKey, $fromEmail, $fromName) {
|
||||
$this->url = 'https://api.sendgrid.com/api/mail.send.json';
|
||||
$this->api_key = $api_key;
|
||||
$this->fromEmail = $from_email;
|
||||
$this->fromName = $from_name;
|
||||
$this->apiKey = $apiKey;
|
||||
$this->fromEmail = $fromEmail;
|
||||
$this->fromName = $fromName;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@ -18,13 +18,16 @@ class SendGrid {
|
||||
$this->url,
|
||||
$this->request()
|
||||
);
|
||||
if(is_object($result) && get_class($result) === 'WP_Error') return false;
|
||||
$result = json_decode($result['body'], true);
|
||||
return (!isset($result['errors']) === true);
|
||||
return (
|
||||
!is_wp_error($result) === true &&
|
||||
!preg_match('!invalid!', $result['body']) === true &&
|
||||
!isset(json_decode($result['body'], true)['errors']) === true &&
|
||||
wp_remote_retrieve_response_code($result) === 200
|
||||
);
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
$parameters = array(
|
||||
return array(
|
||||
'to' => $this->subscriber,
|
||||
'from' => $this->fromEmail,
|
||||
'fromname' => $this->fromName,
|
||||
@ -32,11 +35,10 @@ class SendGrid {
|
||||
'html' => $this->newsletter['body']['html'],
|
||||
'text' => $this->newsletter['body']['text']
|
||||
);
|
||||
return urldecode(http_build_query($parameters));
|
||||
}
|
||||
|
||||
function auth() {
|
||||
return 'Bearer ' . $this->api_key;
|
||||
return 'Bearer ' . $this->apiKey;
|
||||
}
|
||||
|
||||
function request() {
|
||||
@ -47,7 +49,7 @@ class SendGrid {
|
||||
'headers' => array(
|
||||
'Authorization' => $this->auth()
|
||||
),
|
||||
'body' => $this->getBody()
|
||||
'body' => urldecode(http_build_query($this->getBody()))
|
||||
);
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Mailer\API;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Bridge {
|
||||
protected $from_address = null;
|
||||
protected $from_name = '';
|
||||
protected $reply_to_address = null;
|
||||
protected $reply_to_name = '';
|
||||
protected $newsletter = null;
|
||||
protected $subscribers = null;
|
||||
protected $api_key = null;
|
||||
|
||||
function __construct($newsletter, $subscribers) {
|
||||
$this->newsletter = $newsletter;
|
||||
$this->subscribers = $subscribers;
|
||||
|
||||
$this->from_address = (
|
||||
isset($this->newsletter['from_address'])
|
||||
)
|
||||
? $this->newsletter['from_address']
|
||||
: Setting::getValue('from_address');
|
||||
|
||||
$this->from_name = (
|
||||
isset($this->newsletter['from_name'])
|
||||
)
|
||||
? $this->newsletter['from_name']
|
||||
: Setting::getValue('from_name', '');
|
||||
|
||||
$this->reply_to_address = (
|
||||
isset($this->newsletter['reply_to_address'])
|
||||
)
|
||||
? $this->newsletter['reply_to_address']
|
||||
: Setting::getValue('reply_to_address');
|
||||
|
||||
$this->reply_to_name = (
|
||||
isset($this->newsletter['reply_to_name'])
|
||||
)
|
||||
? $this->newsletter['reply_to_name']
|
||||
: Setting::getValue('reply_to_name', '');
|
||||
|
||||
$this->api_key = Setting::where('name', 'api_key')->findOne()->value;
|
||||
}
|
||||
|
||||
function messages() {
|
||||
$messages = array_map(
|
||||
array($this, 'generateMessage'),
|
||||
$this->subscribers
|
||||
);
|
||||
return $messages;
|
||||
}
|
||||
|
||||
function generateMessage($subscriber) {
|
||||
$message = array(
|
||||
'subject' => $this->newsletter['subject'],
|
||||
'to' => array(
|
||||
'address' => $subscriber['email'],
|
||||
'name' => $subscriber['first_name'].' '.$subscriber['last_name']
|
||||
),
|
||||
'from' => array(
|
||||
'address' => $this->from_address,
|
||||
'name' => $this->from_name
|
||||
),
|
||||
'text' => "",
|
||||
'html' => $this->newsletter['body']
|
||||
);
|
||||
|
||||
if($this->reply_to_address !== null) {
|
||||
$message['reply_to'] = array(
|
||||
'address' => $this->reply_to_address,
|
||||
'name' => $this->reply_to_name
|
||||
);
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
function auth() {
|
||||
$auth = 'Basic '
|
||||
. base64_encode('api:' . $this->api_key);
|
||||
return $auth;
|
||||
}
|
||||
|
||||
function request() {
|
||||
$request = array(
|
||||
'timeout' => 10,
|
||||
'httpversion' => '1.0',
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'Authorization' => $this->auth(),
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'body' => json_encode($this->messages())
|
||||
);
|
||||
return $request;
|
||||
}
|
||||
|
||||
function send() {
|
||||
$result = wp_remote_post(
|
||||
'https://bridge.mailpoet.com/api/messages',
|
||||
$this->request()
|
||||
);
|
||||
|
||||
$success =
|
||||
(wp_remote_retrieve_response_code($result) === 201);
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
62
lib/Mailer/SMTP/SMTP.php
Normal file
62
lib/Mailer/SMTP/SMTP.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace MailPoet\Mailer\SMTP;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class SMTP {
|
||||
function __construct($host, $port, $authentication, $encryption,
|
||||
$fromEmail, $fromName) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->authentication = $authentication;
|
||||
$this->encryption = $encryption;
|
||||
$this->fromName = $fromName;
|
||||
$this->fromEmail = $fromEmail;
|
||||
$this->mailer = $this->buildMailer();
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
try {
|
||||
$message = $this->createMessage($newsletter, $subscriber);
|
||||
$result = $this->mailer->send($message);
|
||||
} catch (\Exception $e) {
|
||||
$result = false;
|
||||
}
|
||||
return ($result === 1);
|
||||
}
|
||||
|
||||
function buildMailer() {
|
||||
$transport = \Swift_SmtpTransport::newInstance(
|
||||
$this->host, $this->port, $this->encryption);
|
||||
$transport->setTimeout(10);
|
||||
if($this->authentication) {
|
||||
$transport
|
||||
->setUsername($this->authentication['login'])
|
||||
->setPassword($this->authentication['password']);
|
||||
}
|
||||
return \Swift_Mailer::newInstance($transport);
|
||||
}
|
||||
|
||||
|
||||
function createMessage($newsletter, $subscriber) {
|
||||
return \Swift_Message::newInstance()
|
||||
->setFrom(array($this->fromEmail => $this->fromName))
|
||||
->setTo($this->processSubscriber($subscriber))
|
||||
->setSubject($newsletter['subject'])
|
||||
->setBody($newsletter['body']['html'], 'text/html')
|
||||
->addPart($newsletter['body']['text'], 'text/plain');
|
||||
}
|
||||
|
||||
function processSubscriber($subscriber) {
|
||||
preg_match('!(?P<name>.*?)\s<(?P<email>.*?)>!', $subscriber, $subscriberData);
|
||||
if(!isset($subscriberData['email'])) {
|
||||
$subscriberData = array(
|
||||
'email' => $subscriber,
|
||||
);
|
||||
}
|
||||
return array(
|
||||
$subscriberData['email'] =>
|
||||
(isset($subscriberData['name'])) ? $subscriberData['name'] : '',
|
||||
);
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ class Mailer {
|
||||
case 'MailGun':
|
||||
$mailer = new $this->mailer['class']($this->mailer['domain'], $this->mailer['api_key'], $this->from);
|
||||
break;
|
||||
case 'MailPoet':
|
||||
$mailer = new $this->mailer['class']($this->mailer['api_key'], $this->fromEmail, $this->fromName);
|
||||
break;
|
||||
case 'Mandrill':
|
||||
$mailer = new $this->mailer['class']($this->mailer['api_key'], $this->fromEmail, $this->fromName);
|
||||
break;
|
||||
@ -72,6 +75,11 @@ class Mailer {
|
||||
'api_key' => 'key-6cf5g5qjzenk-7nodj44gdt8phe6vam2',
|
||||
'domain' => 'mrcasual.com'
|
||||
),
|
||||
array(
|
||||
'name' => 'MailPoet',
|
||||
'type' => 'API',
|
||||
'api_key' => 'dhNSqj1XHkVltIliyQDvMiKzQShOA5rs0m_DdRUVZHU'
|
||||
),
|
||||
array(
|
||||
'name' => 'Mandrill',
|
||||
'type' => 'API',
|
||||
|
@ -3,7 +3,7 @@
|
||||
use MailPoet\Mailer\API\AmazonSES;
|
||||
|
||||
class AmazonSESCest {
|
||||
function __construct() {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'name' => 'AmazonSES',
|
||||
'type' => 'API',
|
||||
@ -12,8 +12,13 @@ class AmazonSESCest {
|
||||
'region' => 'us-east-1',
|
||||
);
|
||||
$this->from = 'Sender <vlad@mailpoet.com>';
|
||||
$this->mailer = new AmazonSES($this->settings['region'], $this->settings['access_key'], $this->settings['secret_key'], $this->from);
|
||||
$this->mailer->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer = new AmazonSES(
|
||||
$this->settings['region'],
|
||||
$this->settings['access_key'],
|
||||
$this->settings['secret_key'],
|
||||
$this->from);
|
||||
$this->mailer->subscriber =
|
||||
'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer->newsletter = array(
|
||||
'subject' => 'testing AmazonSES',
|
||||
'body' => array(
|
||||
@ -31,23 +36,19 @@ class AmazonSESCest {
|
||||
}
|
||||
|
||||
function itCanGenerateBody() {
|
||||
$body = explode('&', $this->mailer->getBody());
|
||||
expect($body[0])
|
||||
->equals('Action=SendEmail');
|
||||
expect($body[1])
|
||||
->equals('Version=2010-12-01');
|
||||
expect($body[2])
|
||||
->equals('Source=' . $this->from);
|
||||
expect($body[3])
|
||||
->contains('Destination.ToAddresses.member.1=' . $this->mailer->subscriber);
|
||||
expect($body[4])
|
||||
->equals('Message.Subject.Data=' . $this->mailer->newsletter['subject']);
|
||||
expect($body[5])
|
||||
->equals('Message.Body.Html.Data=' . $this->mailer->newsletter['body']['html']);
|
||||
expect($body[6])
|
||||
->equals('Message.Body.Text.Data=' . $this->mailer->newsletter['body']['text']);
|
||||
expect($body[7])
|
||||
->equals('ReturnPath=' . $this->from);
|
||||
$body = $this->mailer->getBody();
|
||||
expect($body['Action'])->equals('SendEmail');
|
||||
expect($body['Version'])->equals('2010-12-01');
|
||||
expect($body['Source'])->equals($this->from);
|
||||
expect($body['Destination.ToAddresses.member.1'])
|
||||
->contains($this->mailer->subscriber);
|
||||
expect($body['Message.Subject.Data'])
|
||||
->equals($this->mailer->newsletter['subject']);
|
||||
expect($body['Message.Body.Html.Data'])
|
||||
->equals($this->mailer->newsletter['body']['html']);
|
||||
expect($body['Message.Body.Text.Data'])
|
||||
->equals($this->mailer->newsletter['body']['text']);
|
||||
expect($body['ReturnPath'])->equals($this->from);
|
||||
}
|
||||
|
||||
function itCanCreateRequest() {
|
||||
@ -65,7 +66,7 @@ class AmazonSESCest {
|
||||
expect($request['headers']['X-Amz-Date'])
|
||||
->equals($this->mailer->date);
|
||||
expect($request['body'])
|
||||
->equals($this->mailer->getBody());
|
||||
->equals(urldecode(http_build_query($this->mailer->getBody())));
|
||||
}
|
||||
|
||||
function itCanCreateCanonicalRequest() {
|
||||
@ -80,7 +81,9 @@ class AmazonSESCest {
|
||||
'x-amz-date:' . $this->mailer->date,
|
||||
'',
|
||||
'host;x-amz-date',
|
||||
hash($this->mailer->hashAlgorithm, $this->mailer->getBody())
|
||||
hash($this->mailer->hashAlgorithm,
|
||||
urldecode(http_build_query($this->mailer->getBody()))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -128,11 +131,10 @@ class AmazonSESCest {
|
||||
}
|
||||
|
||||
function itCannotSendWithoutProperAccessKey() {
|
||||
$mailer = clone $this->mailer;
|
||||
$mailer->awsAccessKey = 'somekey';
|
||||
$result = $mailer->send(
|
||||
$mailer->newsletter,
|
||||
$mailer->subscriber
|
||||
$this->mailer->awsAccessKey = 'somekey';
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->false();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use MailPoet\Mailer\API\ElasticEmail;
|
||||
|
||||
class ElasticEmailCest {
|
||||
function __construct() {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'name' => 'ElasticEmail',
|
||||
'type' => 'API',
|
||||
@ -11,8 +11,13 @@ class ElasticEmailCest {
|
||||
);
|
||||
$this->fromEmail = 'staff@mailpoet.com';
|
||||
$this->fromName = 'Sender';
|
||||
$this->mailer = new ElasticEmail($this->settings['api_key'], $this->fromEmail, $this->fromName);
|
||||
$this->mailer->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer = new ElasticEmail(
|
||||
$this->settings['api_key'],
|
||||
$this->fromEmail,
|
||||
$this->fromName
|
||||
);
|
||||
$this->mailer->subscriber =
|
||||
'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer->newsletter = array(
|
||||
'subject' => 'testing ElasticEmail',
|
||||
'body' => array(
|
||||
@ -23,21 +28,21 @@ class ElasticEmailCest {
|
||||
}
|
||||
|
||||
function itCanGenerateBody() {
|
||||
$body = explode('&', $this->mailer->getBody());
|
||||
expect($body[0])
|
||||
->equals('api_key=' . $this->settings['api_key']);
|
||||
expect($body[1])
|
||||
->equals('from=' . $this->fromEmail);
|
||||
expect($body[2])
|
||||
->equals('from_name=' . $this->fromName);
|
||||
expect($body[3])
|
||||
->contains('to=' . $this->mailer->subscriber);
|
||||
expect($body[4])
|
||||
->equals('subject=' . $this->mailer->newsletter['subject']);
|
||||
expect($body[5])
|
||||
->equals('body_html=' . $this->mailer->newsletter['body']['html']);
|
||||
expect($body[6])
|
||||
->equals('body_text=' . $this->mailer->newsletter['body']['text']);
|
||||
$body = $this->mailer->getBody();
|
||||
expect($body['api_key'])
|
||||
->equals($this->settings['api_key']);
|
||||
expect($body['from'])
|
||||
->equals($this->fromEmail);
|
||||
expect($body['from_name'])
|
||||
->equals($this->fromName);
|
||||
expect($body['to'])
|
||||
->contains($this->mailer->subscriber);
|
||||
expect($body['subject'])
|
||||
->equals($this->mailer->newsletter['subject']);
|
||||
expect($body['body_html'])
|
||||
->equals($this->mailer->newsletter['body']['html']);
|
||||
expect($body['body_text'])
|
||||
->equals($this->mailer->newsletter['body']['text']);
|
||||
}
|
||||
|
||||
function itCanCreateRequest() {
|
||||
@ -49,15 +54,14 @@ class ElasticEmailCest {
|
||||
expect($request['method'])
|
||||
->equals('POST');
|
||||
expect($request['body'])
|
||||
->equals($this->mailer->getBody());
|
||||
->equals(urldecode(http_build_query($this->mailer->getBody())));
|
||||
}
|
||||
|
||||
function itCannotSendWithoutProperAPIKey() {
|
||||
$mailer = clone $this->mailer;
|
||||
$mailer->api_key = 'someapi';
|
||||
$result = $mailer->send(
|
||||
$mailer->newsletter,
|
||||
$mailer->subscriber
|
||||
$this->mailer->apiKey = 'someapi';
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->false();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use MailPoet\Mailer\API\MailGun;
|
||||
|
||||
class MailGunCest {
|
||||
function __construct() {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'name' => 'MailGun',
|
||||
'type' => 'API',
|
||||
@ -11,8 +11,13 @@ class MailGunCest {
|
||||
'domain' => 'mrcasual.com'
|
||||
);
|
||||
$this->from = 'Sender <staff@mailpoet.com>';
|
||||
$this->mailer = new MailGun($this->settings['domain'], $this->settings['api_key'], $this->from);
|
||||
$this->mailer->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer = new MailGun(
|
||||
$this->settings['domain'],
|
||||
$this->settings['api_key'],
|
||||
$this->from
|
||||
);
|
||||
$this->mailer->subscriber =
|
||||
'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer->newsletter = array(
|
||||
'subject' => 'testing MailGun',
|
||||
'body' => array(
|
||||
@ -24,17 +29,16 @@ class MailGunCest {
|
||||
|
||||
function itCanGenerateBody() {
|
||||
$body = $this->mailer->getBody();
|
||||
$body = explode('&', $body);
|
||||
expect($body[0])
|
||||
->equals('from=' . $this->from);
|
||||
expect($body[1])
|
||||
->equals('to=' . $this->mailer->subscriber);
|
||||
expect($body[2])
|
||||
->equals('subject=' . $this->mailer->newsletter['subject']);
|
||||
expect($body[3])
|
||||
->equals('html=' . $this->mailer->newsletter['body']['html']);
|
||||
expect($body[4])
|
||||
->equals('text=' . $this->mailer->newsletter['body']['text']);
|
||||
expect($body['from'])
|
||||
->equals($this->from);
|
||||
expect($body['to'])
|
||||
->equals($this->mailer->subscriber);
|
||||
expect($body['subject'])
|
||||
->equals($this->mailer->newsletter['subject']);
|
||||
expect($body['html'])
|
||||
->equals($this->mailer->newsletter['body']['html']);
|
||||
expect($body['text'])
|
||||
->equals($this->mailer->newsletter['body']['text']);
|
||||
}
|
||||
|
||||
function itCanDoBasicAuth() {
|
||||
@ -55,25 +59,24 @@ class MailGunCest {
|
||||
expect($request['headers']['Authorization'])
|
||||
->equals('Basic ' . base64_encode('api:' . $this->settings['api_key']));
|
||||
expect($request['body'])
|
||||
->equals($this->mailer->getBody());
|
||||
->equals(urldecode(http_build_query($this->mailer->getBody())));
|
||||
}
|
||||
|
||||
function itCannotSendWithoutProperAPIKey() {
|
||||
$mailer = clone $this->mailer;
|
||||
$mailer->api_key = 'someapi';
|
||||
$result = $mailer->send(
|
||||
$mailer->newsletter,
|
||||
$mailer->subscriber
|
||||
$this->mailer->apiKey = 'someapi';
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->false();
|
||||
}
|
||||
|
||||
function itCannotSendWithoutProperDomain() {
|
||||
$mailer = clone $this->mailer;
|
||||
$mailer->domain = 'somedomain';
|
||||
$result = $mailer->send(
|
||||
$mailer->newsletter,
|
||||
$mailer->subscriber
|
||||
$this->mailer->url =
|
||||
str_replace($this->settings['domain'], 'somedomain', $this->mailer->url);
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->false();
|
||||
}
|
||||
|
105
tests/unit/Mailer/API/MailPoetCest.php
Normal file
105
tests/unit/Mailer/API/MailPoetCest.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Mailer\API\MailPoet;
|
||||
|
||||
class MailPoetCest {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'name' => 'MailPoet',
|
||||
'type' => 'API',
|
||||
'api_key' => 'dhNSqj1XHkVltIliyQDvMiKzQShOA5rs0m_DdRUVZHU'
|
||||
);
|
||||
$this->fromEmail = 'staff@mailpoet.com';
|
||||
$this->fromName = 'Sender';
|
||||
$this->mailer = new MailPoet(
|
||||
$this->settings['api_key'],
|
||||
$this->fromEmail,
|
||||
$this->fromName
|
||||
);
|
||||
$this->mailer->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer->newsletter = array(
|
||||
'subject' => 'testing MailPoet',
|
||||
'body' => array(
|
||||
'html' => 'HTML body',
|
||||
'text' => 'TEXT body'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function itCanGenerateBody() {
|
||||
$this->mailer->subscriber = $this->mailer->processSubscriber($this->mailer->subscriber);
|
||||
$body = $this->mailer->getBody();
|
||||
expect($body['to']['address'])
|
||||
->equals($this->mailer->subscriber['email']);
|
||||
expect($body['to']['name'])
|
||||
->equals($this->mailer->subscriber['name']);
|
||||
expect($body['from']['address'])
|
||||
->equals($this->fromEmail);
|
||||
expect($body['subject'])
|
||||
->equals($this->mailer->newsletter['subject']);
|
||||
expect($body['html'])
|
||||
->equals($this->mailer->newsletter['body']['html']);
|
||||
expect($body['text'])
|
||||
->equals($this->mailer->newsletter['body']['text']);
|
||||
}
|
||||
|
||||
function itCanCreateRequest() {
|
||||
$this->mailer->subscriber = $this->mailer->processSubscriber($this->mailer->subscriber);
|
||||
$request = $this->mailer->request();
|
||||
expect($request['timeout'])
|
||||
->equals(10);
|
||||
expect($request['httpversion'])
|
||||
->equals('1.0');
|
||||
expect($request['method'])
|
||||
->equals('POST');
|
||||
expect($request['headers']['Content-Type'])
|
||||
->equals('application/json');
|
||||
expect($request['headers']['Authorization'])
|
||||
->equals($this->mailer->auth());
|
||||
expect($request['body'])
|
||||
->equals(json_encode(array($this->mailer->getBody())));
|
||||
}
|
||||
|
||||
function itCanProcessSubscriber() {
|
||||
expect($this->mailer->processSubscriber('test@test.com'))
|
||||
->equals(
|
||||
array(
|
||||
'email' => 'test@test.com',
|
||||
'name' => ''
|
||||
));
|
||||
expect($this->mailer->processSubscriber('First <test@test.com>'))
|
||||
->equals(
|
||||
array(
|
||||
'email' => 'test@test.com',
|
||||
'name' => 'First'
|
||||
));
|
||||
expect($this->mailer->processSubscriber('First Last <test@test.com>'))
|
||||
->equals(
|
||||
array(
|
||||
'email' => 'test@test.com',
|
||||
'name' => 'First Last'
|
||||
));
|
||||
}
|
||||
|
||||
function itCanDoBasicAuth() {
|
||||
expect($this->mailer->auth())
|
||||
->equals('Basic ' . base64_encode('api:' . $this->settings['api_key']));
|
||||
}
|
||||
|
||||
function itCannotSendWithoutProperAPIKey() {
|
||||
$this->mailer->apiKey = 'someapi';
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->false();
|
||||
}
|
||||
|
||||
function itCanSend() {
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->true();
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
use MailPoet\Mailer\API\Mandrill;
|
||||
|
||||
class MandrillCest {
|
||||
function __construct() {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'name' => 'Mandrill',
|
||||
'type' => 'API',
|
||||
@ -11,8 +11,13 @@ class MandrillCest {
|
||||
);
|
||||
$this->fromEmail = 'staff@mailpoet.com';
|
||||
$this->fromName = 'Sender';
|
||||
$this->mailer = new Mandrill($this->settings['api_key'], $this->fromEmail, $this->fromName);
|
||||
$this->mailer->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer = new Mandrill(
|
||||
$this->settings['api_key'],
|
||||
$this->fromEmail,
|
||||
$this->fromName
|
||||
);
|
||||
$this->mailer->subscriber =
|
||||
'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer->newsletter = array(
|
||||
'subject' => 'testing Mandrill',
|
||||
'body' => array(
|
||||
@ -32,7 +37,7 @@ class MandrillCest {
|
||||
$this->fromName
|
||||
);
|
||||
expect($body['message']['to'])->equals(
|
||||
$this->mailer->subscriber
|
||||
array($this->mailer->subscriber)
|
||||
);
|
||||
expect($body['message']['subject'])->equals(
|
||||
$this->mailer->newsletter['subject']
|
||||
@ -62,34 +67,30 @@ class MandrillCest {
|
||||
|
||||
function itCanProcessSubscriber() {
|
||||
expect($this->mailer->processSubscriber('test@test.com'))
|
||||
->equals(array(
|
||||
->equals(
|
||||
array(
|
||||
'email' => 'test@test.com',
|
||||
'name' => ''
|
||||
)
|
||||
));
|
||||
expect($this->mailer->processSubscriber('First <test@test.com>'))
|
||||
->equals(array(
|
||||
->equals(
|
||||
array(
|
||||
'email' => 'test@test.com',
|
||||
'name' => 'First'
|
||||
)
|
||||
));
|
||||
expect($this->mailer->processSubscriber('First Last <test@test.com>'))
|
||||
->equals(array(
|
||||
->equals(
|
||||
array(
|
||||
'email' => 'test@test.com',
|
||||
'name' => 'First Last'
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
function itCannotSendWithoutProperAPIKey() {
|
||||
$mailer = clone $this->mailer;
|
||||
$mailer->api_key = 'someapi';
|
||||
$result = $mailer->send(
|
||||
$mailer->newsletter,
|
||||
$mailer->subscriber
|
||||
$this->mailer->apiKey = 'someapi';
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->false();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use MailPoet\Mailer\API\SendGrid;
|
||||
|
||||
class SendGridCest {
|
||||
function __construct() {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'name' => 'SendGrid',
|
||||
'type' => 'API',
|
||||
@ -11,8 +11,13 @@ class SendGridCest {
|
||||
);
|
||||
$this->fromEmail = 'staff@mailpoet.com';
|
||||
$this->fromName = 'Sender';
|
||||
$this->mailer = new SendGrid($this->settings['api_key'], $this->fromEmail, $this->fromName);
|
||||
$this->mailer->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer = new SendGrid(
|
||||
$this->settings['api_key'],
|
||||
$this->fromEmail,
|
||||
$this->fromName
|
||||
);
|
||||
$this->mailer->subscriber =
|
||||
'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->mailer->newsletter = array(
|
||||
'subject' => 'testing SendGrid',
|
||||
'body' => array(
|
||||
@ -23,19 +28,19 @@ class SendGridCest {
|
||||
}
|
||||
|
||||
function itCanGenerateBody() {
|
||||
$body = explode('&', $this->mailer->getBody());
|
||||
expect($body[0])
|
||||
->contains('to=' . $this->mailer->subscriber);
|
||||
expect($body[1])
|
||||
->equals('from=' . $this->fromEmail);
|
||||
expect($body[2])
|
||||
->equals('fromname=' . $this->fromName);
|
||||
expect($body[3])
|
||||
->equals('subject=' . $this->mailer->newsletter['subject']);
|
||||
expect($body[4])
|
||||
->equals('html=' . $this->mailer->newsletter['body']['html']);
|
||||
expect($body[5])
|
||||
->equals('text=' . $this->mailer->newsletter['body']['text']);
|
||||
$body = $this->mailer->getBody();
|
||||
expect($body['to'])
|
||||
->contains($this->mailer->subscriber);
|
||||
expect($body['from'])
|
||||
->equals($this->fromEmail);
|
||||
expect($body['fromname'])
|
||||
->equals($this->fromName);
|
||||
expect($body['subject'])
|
||||
->equals($this->mailer->newsletter['subject']);
|
||||
expect($body['html'])
|
||||
->equals($this->mailer->newsletter['body']['html']);
|
||||
expect($body['text'])
|
||||
->equals($this->mailer->newsletter['body']['text']);
|
||||
}
|
||||
|
||||
function itCanCreateRequest() {
|
||||
@ -49,7 +54,7 @@ class SendGridCest {
|
||||
expect($request['headers']['Authorization'])
|
||||
->equals('Bearer ' . $this->settings['api_key']);
|
||||
expect($request['body'])
|
||||
->equals($this->mailer->getBody());
|
||||
->equals(urldecode(http_build_query($this->mailer->getBody())));
|
||||
}
|
||||
|
||||
function itCanDoBasicAuth() {
|
||||
@ -58,11 +63,10 @@ class SendGridCest {
|
||||
}
|
||||
|
||||
function itCannotSendWithoutProperAPIKey() {
|
||||
$mailer = clone $this->mailer;
|
||||
$mailer->api_key = 'someapi';
|
||||
$result = $mailer->send(
|
||||
$mailer->newsletter,
|
||||
$mailer->subscriber
|
||||
$this->mailer->apiKey = 'someapi';
|
||||
$result = $this->mailer->send(
|
||||
$this->mailer->newsletter,
|
||||
$this->mailer->subscriber
|
||||
);
|
||||
expect($result)->false();
|
||||
}
|
||||
|
@ -1,123 +0,0 @@
|
||||
<?php
|
||||
use MailPoet\Mailer\Bridge;
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
class BridgeCest {
|
||||
|
||||
function _before() {
|
||||
$from_name = Setting::create();
|
||||
$from_name->name = 'from_name';
|
||||
$from_name->value = 'Marco';
|
||||
$from_name->save();
|
||||
|
||||
$from_address = Setting::create();
|
||||
$from_address->name = 'from_address';
|
||||
$from_address->value = 'marco@mailpoet.com';
|
||||
$from_address->save();
|
||||
|
||||
$api_key = Setting::create();
|
||||
$api_key->name = 'api_key';
|
||||
$api_key->value = 'xxxccc';
|
||||
$api_key->save();
|
||||
|
||||
$this->newsletter = array(
|
||||
'subject' => 'A test message from mp3',
|
||||
'body' => 'Hey, I am mp3, chapter two.'
|
||||
);
|
||||
$this->subscribers = array(
|
||||
array(
|
||||
'first_name' => 'Marco',
|
||||
'last_name' => 'Lisci',
|
||||
'email' => 'marco@mailpoet.com'
|
||||
),
|
||||
array(
|
||||
'first_name' => 'Jonathan',
|
||||
'last_name' => 'Labreuille',
|
||||
'email' => 'jonathan@mailpoet.com'
|
||||
)
|
||||
);
|
||||
|
||||
$this->mailer = new Bridge(
|
||||
$this->newsletter,
|
||||
$this->subscribers
|
||||
);
|
||||
}
|
||||
|
||||
function itCanDoBasicAuth() {
|
||||
$api_key = Setting::where('name', 'api_key')
|
||||
->findOne()->value;
|
||||
expect($this->mailer->auth())->equals(
|
||||
'Basic '
|
||||
. base64_encode('api:' . $api_key)
|
||||
);
|
||||
}
|
||||
|
||||
function itCanGenerateACorrectMessage() {
|
||||
$subscriber = $this->subscribers[0];
|
||||
$message =
|
||||
$this->mailer->generateMessage($subscriber);
|
||||
|
||||
expect($message['to']['address'])
|
||||
->equals($subscriber['email']);
|
||||
|
||||
expect($message['to']['name'])
|
||||
->equals($subscriber['first_name'].' '.$subscriber['last_name']);
|
||||
|
||||
expect($message['subject'])
|
||||
->equals($this->newsletter['subject']);
|
||||
|
||||
expect($message['html'])
|
||||
->equals($this->newsletter['body']);
|
||||
|
||||
expect($message['text'])
|
||||
->equals('');
|
||||
}
|
||||
|
||||
function itCanGenerateCorrectMessages() {
|
||||
$messages = $this->mailer->messages();
|
||||
|
||||
expect(count($messages))
|
||||
->equals(count($this->subscribers));
|
||||
}
|
||||
|
||||
function itCanCreateARequest() {
|
||||
$request = $this->mailer->request();
|
||||
|
||||
expect($request['timeout'])
|
||||
->equals(10);
|
||||
|
||||
expect($request['httpversion'])
|
||||
->equals('1.0');
|
||||
|
||||
expect($request['method'])
|
||||
->equals('POST');
|
||||
|
||||
expect($request['headers']['Content-Type'])
|
||||
->equals('application/json');
|
||||
}
|
||||
|
||||
function itCannotSendWithoutSubscribers() {
|
||||
$subscribers = array();
|
||||
|
||||
$mailer = new Bridge(
|
||||
$this->newsletter,
|
||||
$subscribers
|
||||
);
|
||||
|
||||
expect($mailer->send())->equals(false);
|
||||
}
|
||||
|
||||
function itCanSend() {
|
||||
/* $result = $this->mailer->send(); */
|
||||
/* expect($result)->equals(true); */
|
||||
}
|
||||
|
||||
function _after() {
|
||||
Setting::where('name', 'from_name')
|
||||
->findOne()->delete();
|
||||
Setting::where('name', 'from_address')
|
||||
->findOne()->delete();
|
||||
Setting::where('name', 'api_key')
|
||||
->findOne()->delete();
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
use MailPoet\Mailer\SMTP\SMTP;
|
||||
|
||||
class SMTPCest {
|
||||
function __construct() {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'name' => 'SMTP',
|
||||
'type' => 'SMTP',
|
||||
@ -17,7 +17,14 @@ class SMTPCest {
|
||||
);
|
||||
$this->fromEmail = 'staff@mailpoet.com';
|
||||
$this->fromName = 'Sender';
|
||||
$this->mailer = new SMTP($this->settings['host'], $this->settings['port'], $this->settings['authentication'], $this->settings['encryption'], $this->fromEmail, $this->fromName);
|
||||
$this->mailer = new SMTP(
|
||||
$this->settings['host'],
|
||||
$this->settings['port'],
|
||||
$this->settings['authentication'],
|
||||
$this->settings['encryption'],
|
||||
$this->fromEmail,
|
||||
$this->fromName
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
'subject' => 'testing SMTP',
|
||||
@ -71,10 +78,9 @@ class SMTPCest {
|
||||
}
|
||||
|
||||
function itCantSentWithoutProperAuthentication() {
|
||||
$mailer = clone $this->mailer;
|
||||
$mailer->smtpAuthentication['login'] = 'someone';
|
||||
$mailer->mailer = $mailer->buildMailer();
|
||||
$result = $mailer->send(
|
||||
$this->mailer->authentication['login'] = 'someone';
|
||||
$this->mailer->mailer = $this->mailer->buildMailer();
|
||||
$result = $this->mailer->send(
|
||||
$this->newsletter,
|
||||
$this->subscriber
|
||||
);
|
||||
|
Reference in New Issue
Block a user