Add unit tests [MAILPOET-743]

This commit is contained in:
Alexey Stoletniy
2017-01-16 20:09:17 +03:00
parent 1f91d40def
commit 438b4fb1ec
15 changed files with 596 additions and 34 deletions

View File

@ -9,18 +9,23 @@ use MailPoet\Services\Bridge;
if(!defined('ABSPATH')) exit;
class Services extends APIEndpoint {
public $bridge;
function __construct() {
$this->bridge = new Bridge();
}
function verifyMailPoetKey($data = array()) {
$key = isset($data['key']) ? trim($data['key']) : null;
if(!$key) {
return $this->badRequest(array(
APIError::BAD_REQUEST => __('You need to specify a key.', 'mailpoet')
APIError::BAD_REQUEST => __('Please specify a key.', 'mailpoet')
));
}
try {
$bridge = new Bridge($key);
$result = $bridge->checkKey();
$result = $this->bridge->checkKey($key);
} catch(\Exception $e) {
return $this->errorResponse(array(
$e->getCode() => $e->getMessage()

View File

@ -3,6 +3,7 @@ namespace MailPoet\API\Endpoints;
use MailPoet\API\Endpoint as APIEndpoint;
use MailPoet\API\Error as APIError;
use MailPoet\Models\Setting;
use MailPoet\Services\Bridge;
if(!defined('ABSPATH')) exit;
@ -21,6 +22,12 @@ class Settings extends APIEndpoint {
foreach($settings as $name => $value) {
Setting::setValue($name, $value);
}
if(!empty($settings['mta']['mailpoet_api_key'])
&& Bridge::isMPSendingServiceEnabled()
) {
$bridge = new Bridge();
$bridge->checkKey($settings['mta']['mailpoet_api_key']);
}
return $this->successResponse(Setting::getAll());
}
}