Add SPF check API method to backend [MAILPOET-2295]

This commit is contained in:
wxa
2019-09-02 09:46:48 +03:00
committed by Jack Kitterhing
parent e72ea01f68
commit f67e356202
4 changed files with 103 additions and 0 deletions

View File

@ -7,6 +7,7 @@ use MailPoet\API\JSON\v1\Services;
use MailPoet\API\JSON\Response as APIResponse;
use MailPoet\Config\Installer;
use MailPoet\Services\Bridge;
use MailPoet\Services\SPFCheck;
use MailPoet\Settings\SettingsController;
class ServicesTest extends \MailPoetTest {
@ -20,6 +21,30 @@ class ServicesTest extends \MailPoetTest {
$this->settings = new SettingsController();
}
function testItRespondsWithErrorIfSPFCheckFails() {
$email = 'spf_test@example.com';
$this->settings->set('sender.address', $email);
$this->services_endpoint->spf_check = Stub::make(
SPFCheck::class,
['checkSPFRecord' => false],
$this
);
$response = $this->services_endpoint->checkSPFRecord([]);
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->meta['sender_address'])->equals($email);
expect($response->meta['domain_name'])->equals('example.com');
}
function testItRespondsWithSuccessIfSPFCheckPasses() {
$this->services_endpoint->spf_check = Stub::make(
SPFCheck::class,
['checkSPFRecord' => true],
$this
);
$response = $this->services_endpoint->checkSPFRecord([]);
expect($response->status)->equals(APIResponse::STATUS_OK);
}
function testItRespondsWithErrorIfNoMSSKeyIsGiven() {
$response = $this->services_endpoint->checkMSSKey(['key' => '']);
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);