Use MailerFactory in Mailer api
[MAILPOET-4115]
This commit is contained in:
committed by
Veljko V
parent
06fb13bd86
commit
6b758d90e6
@ -5,6 +5,7 @@ namespace MailPoet\API\JSON\v1;
|
|||||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||||
use MailPoet\API\JSON\Error as APIError;
|
use MailPoet\API\JSON\Error as APIError;
|
||||||
use MailPoet\Config\AccessControl;
|
use MailPoet\Config\AccessControl;
|
||||||
|
use MailPoet\Mailer\MailerFactory;
|
||||||
use MailPoet\Mailer\MailerLog;
|
use MailPoet\Mailer\MailerLog;
|
||||||
use MailPoet\Mailer\MetaInfo;
|
use MailPoet\Mailer\MetaInfo;
|
||||||
use MailPoet\Services\AuthorizedEmailsController;
|
use MailPoet\Services\AuthorizedEmailsController;
|
||||||
@ -26,6 +27,9 @@ class Mailer extends APIEndpoint {
|
|||||||
/** @var MetaInfo */
|
/** @var MetaInfo */
|
||||||
private $mailerMetaInfo;
|
private $mailerMetaInfo;
|
||||||
|
|
||||||
|
/** @var MailerFactory */
|
||||||
|
private $mailerFactory;
|
||||||
|
|
||||||
public $permissions = [
|
public $permissions = [
|
||||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS,
|
'global' => AccessControl::PERMISSION_MANAGE_EMAILS,
|
||||||
];
|
];
|
||||||
@ -34,21 +38,22 @@ class Mailer extends APIEndpoint {
|
|||||||
AuthorizedEmailsController $authorizedEmailsController,
|
AuthorizedEmailsController $authorizedEmailsController,
|
||||||
SettingsController $settings,
|
SettingsController $settings,
|
||||||
Bridge $bridge,
|
Bridge $bridge,
|
||||||
|
MailerFactory $mailerFactory,
|
||||||
MetaInfo $mailerMetaInfo
|
MetaInfo $mailerMetaInfo
|
||||||
) {
|
) {
|
||||||
$this->authorizedEmailsController = $authorizedEmailsController;
|
$this->authorizedEmailsController = $authorizedEmailsController;
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->bridge = $bridge;
|
$this->bridge = $bridge;
|
||||||
|
$this->mailerFactory = $mailerFactory;
|
||||||
$this->mailerMetaInfo = $mailerMetaInfo;
|
$this->mailerMetaInfo = $mailerMetaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function send($data = []) {
|
public function send($data = []) {
|
||||||
try {
|
try {
|
||||||
$mailer = new \MailPoet\Mailer\Mailer();
|
$mailer = $this->mailerFactory->buildMailer(
|
||||||
$mailer->init(
|
(isset($data['mailer'])) ? $data['mailer'] : null,
|
||||||
(isset($data['mailer'])) ? $data['mailer'] : false,
|
(isset($data['sender'])) ? $data['sender'] : null,
|
||||||
(isset($data['sender'])) ? $data['sender'] : false,
|
(isset($data['reply_to'])) ? $data['reply_to'] : null
|
||||||
(isset($data['reply_to'])) ? $data['reply_to'] : false
|
|
||||||
);
|
);
|
||||||
// report this as 'sending_test' in metadata since this endpoint is only used to test sending methods for now
|
// report this as 'sending_test' in metadata since this endpoint is only used to test sending methods for now
|
||||||
$extraParams = [
|
$extraParams = [
|
||||||
|
@ -5,6 +5,7 @@ namespace MailPoet\Test\API\JSON\v1;
|
|||||||
use Codeception\Stub\Expected;
|
use Codeception\Stub\Expected;
|
||||||
use MailPoet\API\JSON\Response as APIResponse;
|
use MailPoet\API\JSON\Response as APIResponse;
|
||||||
use MailPoet\API\JSON\v1\Mailer;
|
use MailPoet\API\JSON\v1\Mailer;
|
||||||
|
use MailPoet\Mailer\MailerFactory;
|
||||||
use MailPoet\Mailer\MailerLog;
|
use MailPoet\Mailer\MailerLog;
|
||||||
use MailPoet\Mailer\MetaInfo;
|
use MailPoet\Mailer\MetaInfo;
|
||||||
use MailPoet\Services\AuthorizedEmailsController;
|
use MailPoet\Services\AuthorizedEmailsController;
|
||||||
@ -23,7 +24,7 @@ class MailerTest extends \MailPoetTest {
|
|||||||
$authorizedEmailsController = $this->makeEmpty(AuthorizedEmailsController::class, ['checkAuthorizedEmailAddresses' => Expected::never()]);
|
$authorizedEmailsController = $this->makeEmpty(AuthorizedEmailsController::class, ['checkAuthorizedEmailAddresses' => Expected::never()]);
|
||||||
// resumeSending() method should clear the mailer log's status
|
// resumeSending() method should clear the mailer log's status
|
||||||
$bridge = new Bridge($settings);
|
$bridge = new Bridge($settings);
|
||||||
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, new MetaInfo);
|
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, $this->diContainer->get(MailerFactory::class), new MetaInfo);
|
||||||
$response = $mailerEndpoint->resumeSending();
|
$response = $mailerEndpoint->resumeSending();
|
||||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||||
$mailerLog = MailerLog::getMailerLog();
|
$mailerLog = MailerLog::getMailerLog();
|
||||||
@ -35,7 +36,7 @@ class MailerTest extends \MailPoetTest {
|
|||||||
$settings->set(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, ['invalid_sender_address' => 'a@b.c']);
|
$settings->set(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, ['invalid_sender_address' => 'a@b.c']);
|
||||||
$authorizedEmailsController = $this->makeEmpty(AuthorizedEmailsController::class, ['checkAuthorizedEmailAddresses' => Expected::once()]);
|
$authorizedEmailsController = $this->makeEmpty(AuthorizedEmailsController::class, ['checkAuthorizedEmailAddresses' => Expected::once()]);
|
||||||
$bridge = new Bridge($settings);
|
$bridge = new Bridge($settings);
|
||||||
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, new MetaInfo);
|
$mailerEndpoint = new Mailer($authorizedEmailsController, $settings, $bridge, $this->diContainer->get(MailerFactory::class), new MetaInfo);
|
||||||
$mailerEndpoint->resumeSending();
|
$mailerEndpoint->resumeSending();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user