Fix PR remarks [MAILPOET-2176]
This commit is contained in:
@@ -12,22 +12,18 @@ trait BlacklistTrait {
|
||||
return $this->getBlacklist()->isBlacklisted($email);
|
||||
}
|
||||
|
||||
function getSubscriberEmailForBlacklistCheck($subscriber) {
|
||||
preg_match('!(?P<name>.*?)\s<(?P<email>.*?)>!', $subscriber, $subscriber_data);
|
||||
private function getSubscriberEmailForBlacklistCheck($subscriber_string) {
|
||||
preg_match('!(?P<name>.*?)\s<(?P<email>.*?)>!', $subscriber_string, $subscriber_data);
|
||||
if (!isset($subscriber_data['email'])) {
|
||||
return $subscriber;
|
||||
return $subscriber_string;
|
||||
}
|
||||
return $subscriber_data['email'];
|
||||
}
|
||||
|
||||
function getBlacklist() {
|
||||
private function getBlacklist() {
|
||||
if (!$this->blacklist instanceof Blacklist) {
|
||||
$this->blacklist = new Blacklist();
|
||||
}
|
||||
return $this->blacklist;
|
||||
}
|
||||
|
||||
function setBlacklist(Blacklist $blacklist) {
|
||||
$this->blacklist = $blacklist;
|
||||
}
|
||||
}
|
||||
|
@@ -135,8 +135,4 @@ class MailPoet {
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
function checkBlacklist(array $subscribers) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -8,17 +8,18 @@ class Blacklist {
|
||||
'e60c6e0e73997c92d4ceac78a6b6cbbe6249244c4106a3c31de421fc50370ecd' => 1,
|
||||
];
|
||||
|
||||
public function __construct(array $blacklist = null) {
|
||||
if ($blacklist) {
|
||||
$this->blacklist = array_fill_keys(array_map([$this, 'hash'], $blacklist), 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function isBlacklisted($email) {
|
||||
$hashed_email = $this->hash($email);
|
||||
return !empty($this->blacklist[$hashed_email]);
|
||||
return isset($this->blacklist[$hashed_email]);
|
||||
}
|
||||
|
||||
public function hash($email) {
|
||||
private function hash($email) {
|
||||
return hash('sha256', $email . self::SALT);
|
||||
}
|
||||
|
||||
public function addEmail($email) {
|
||||
$hashed_email = $this->hash($email);
|
||||
$this->blacklist[$hashed_email] = 1;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Mailer\Methods;
|
||||
|
||||
use Codeception\Stub;
|
||||
use MailPoet\Mailer\MailerError;
|
||||
use MailPoet\Mailer\Methods\AmazonSES;
|
||||
use MailPoet\Mailer\Methods\ErrorMappers\AmazonSESMapper;
|
||||
@@ -236,10 +237,13 @@ class AmazonSESTest extends \MailPoetTest {
|
||||
|
||||
function testItChecksBlacklistBeforeSending() {
|
||||
$blacklisted_subscriber = 'blacklist_test@example.com';
|
||||
$blacklist = new Blacklist();
|
||||
$blacklist->addEmail($blacklisted_subscriber);
|
||||
$this->mailer->setBlacklist($blacklist);
|
||||
$result = $this->mailer->send(
|
||||
$blacklist = Stub::make(new Blacklist(), ['isBlacklisted' => true], $this);
|
||||
$mailer = Stub::make(
|
||||
$this->mailer,
|
||||
['blacklist' => $blacklist, 'error_mapper' => new AmazonSESMapper()],
|
||||
$this
|
||||
);
|
||||
$result = $mailer->send(
|
||||
$this->newsletter,
|
||||
$blacklisted_subscriber
|
||||
);
|
||||
|
@@ -259,10 +259,21 @@ class MailPoetAPITest extends \MailPoetTest {
|
||||
|
||||
function testItChecksBlacklistBeforeSendingToASingleSubscriber() {
|
||||
$blacklisted_subscriber = 'blacklist_test@example.com';
|
||||
$blacklist = new Blacklist();
|
||||
$blacklist->addEmail($blacklisted_subscriber);
|
||||
$this->mailer->setBlacklist($blacklist);
|
||||
$result = $this->mailer->send(
|
||||
$blacklist = Stub::make(new Blacklist(), ['isBlacklisted' => true], $this);
|
||||
$mailer = Stub::make(
|
||||
$this->mailer,
|
||||
[
|
||||
'blacklist' => $blacklist,
|
||||
'error_mapper' => new MailPoetMapper(),
|
||||
'services_checker' => Stub::make(
|
||||
new ServicesChecker(),
|
||||
['isMailPoetAPIKeyValid' => true],
|
||||
$this
|
||||
),
|
||||
],
|
||||
$this
|
||||
);
|
||||
$result = $mailer->send(
|
||||
$this->newsletter,
|
||||
$blacklisted_subscriber
|
||||
);
|
||||
@@ -274,10 +285,21 @@ class MailPoetAPITest extends \MailPoetTest {
|
||||
|
||||
function testItChecksBlacklistBeforeSendingToMultipleSubscribers() {
|
||||
$blacklisted_subscriber = 'blacklist_test@example.com';
|
||||
$blacklist = new Blacklist();
|
||||
$blacklist->addEmail($blacklisted_subscriber);
|
||||
$this->mailer->setBlacklist($blacklist);
|
||||
$result = $this->mailer->send(
|
||||
$blacklist = Stub::make(new Blacklist(), ['isBlacklisted' => true], $this);
|
||||
$mailer = Stub::make(
|
||||
$this->mailer,
|
||||
[
|
||||
'blacklist' => $blacklist,
|
||||
'error_mapper' => new MailPoetMapper(),
|
||||
'services_checker' => Stub::make(
|
||||
new ServicesChecker(),
|
||||
['isMailPoetAPIKeyValid' => true],
|
||||
$this
|
||||
),
|
||||
],
|
||||
$this
|
||||
);
|
||||
$result = $mailer->send(
|
||||
$this->newsletter,
|
||||
['good@example.com', $blacklisted_subscriber, 'good2@example.com']
|
||||
);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Mailer\Methods;
|
||||
|
||||
use Codeception\Stub;
|
||||
use MailPoet\Mailer\MailerError;
|
||||
use MailPoet\Mailer\Methods\ErrorMappers\PHPMailMapper;
|
||||
use MailPoet\Mailer\Methods\PHPMail;
|
||||
@@ -116,16 +117,18 @@ class PHPMailTest extends \MailPoetTest {
|
||||
|
||||
function testItChecksBlacklistBeforeSending() {
|
||||
$blacklisted_subscriber = 'blacklist_test@example.com';
|
||||
$blacklist = new Blacklist();
|
||||
$blacklist->addEmail($blacklisted_subscriber);
|
||||
$this->mailer->setBlacklist($blacklist);
|
||||
$result = $this->mailer->send(
|
||||
$blacklist = Stub::make(new Blacklist(), ['isBlacklisted' => true], $this);
|
||||
$mailer = Stub::make(
|
||||
$this->mailer,
|
||||
['blacklist' => $blacklist, 'error_mapper' => new PHPMailMapper()],
|
||||
$this
|
||||
);
|
||||
$result = $mailer->send(
|
||||
$this->newsletter,
|
||||
$blacklisted_subscriber
|
||||
);
|
||||
expect($result['response'])->false();
|
||||
expect($result['error'])->isInstanceOf(MailerError::class);
|
||||
expect($result['error']->getMessage())->contains('unknown error');
|
||||
expect($result['error']->getMessage())->contains('PHPMail has returned an unknown error.');
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Mailer\Methods;
|
||||
|
||||
use Codeception\Stub;
|
||||
use MailPoet\Mailer\MailerError;
|
||||
use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper;
|
||||
use MailPoet\Mailer\Methods\SMTP;
|
||||
@@ -175,10 +176,13 @@ class SMTPTest extends \MailPoetTest {
|
||||
|
||||
function testItChecksBlacklistBeforeSending() {
|
||||
$blacklisted_subscriber = 'blacklist_test@example.com';
|
||||
$blacklist = new Blacklist();
|
||||
$blacklist->addEmail($blacklisted_subscriber);
|
||||
$this->mailer->setBlacklist($blacklist);
|
||||
$result = $this->mailer->send(
|
||||
$blacklist = Stub::make(new Blacklist(), ['isBlacklisted' => true], $this);
|
||||
$mailer = Stub::make(
|
||||
$this->mailer,
|
||||
['blacklist' => $blacklist, 'error_mapper' => new SMTPMapper()],
|
||||
$this
|
||||
);
|
||||
$result = $mailer->send(
|
||||
$this->newsletter,
|
||||
$blacklisted_subscriber
|
||||
);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Mailer\Methods;
|
||||
|
||||
use Codeception\Stub;
|
||||
use MailPoet\Mailer\MailerError;
|
||||
use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper;
|
||||
use MailPoet\Mailer\Methods\SendGrid;
|
||||
@@ -86,10 +87,13 @@ class SendGridTest extends \MailPoetTest {
|
||||
|
||||
function testItChecksBlacklistBeforeSending() {
|
||||
$blacklisted_subscriber = 'blacklist_test@example.com';
|
||||
$blacklist = new Blacklist();
|
||||
$blacklist->addEmail($blacklisted_subscriber);
|
||||
$this->mailer->setBlacklist($blacklist);
|
||||
$result = $this->mailer->send(
|
||||
$blacklist = Stub::make(new Blacklist(), ['isBlacklisted' => true], $this);
|
||||
$mailer = Stub::make(
|
||||
$this->mailer,
|
||||
['blacklist' => $blacklist, 'error_mapper' => new SendGridMapper()],
|
||||
$this
|
||||
);
|
||||
$result = $mailer->send(
|
||||
$this->newsletter,
|
||||
$blacklisted_subscriber
|
||||
);
|
||||
|
@@ -7,7 +7,7 @@ class BlacklistTest extends \MailPoetUnitTest {
|
||||
$blacklist = new Blacklist();
|
||||
$result = $blacklist->isBlacklisted($email);
|
||||
expect($result)->equals(false);
|
||||
$blacklist->addEmail($email);
|
||||
$blacklist = new Blacklist([$email]);
|
||||
$result = $blacklist->isBlacklisted($email);
|
||||
expect($result)->equals(true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user