Rename MSS check methods to better distinguish them from Premium ones [PREMIUM-4]

This commit is contained in:
Alexey Stoletniy
2017-05-04 09:36:38 +03:00
parent 0474985866
commit 3cb08e3c09
14 changed files with 38 additions and 38 deletions

View File

@@ -26,7 +26,7 @@ class Services extends APIEndpoint {
}
try {
$result = $this->bridge->checkKey($key);
$result = $this->bridge->checkAPIKey($key);
} catch(\Exception $e) {
return $this->errorResponse(array(
$e->getCode() => $e->getMessage()

View File

@@ -525,7 +525,7 @@ class Menu {
$show_notices = isset($_REQUEST['page'])
&& stripos($_REQUEST['page'], 'mailpoet-newsletters') === false;
$checker = $checker ?: new ServicesChecker();
$this->mp_api_key_valid = $checker->checkMailPoetAPIKeyValid($show_notices);
$this->mp_api_key_valid = $checker->isMailPoetAPIKeyValid($show_notices);
}
}

View File

@@ -11,7 +11,7 @@ use MailPoet\WP\Notice as WPNotice;
if(!defined('ABSPATH')) exit;
class ServicesChecker {
function checkMailPoetAPIKeyValid($display_error_notice = true) {
function isMailPoetAPIKeyValid($display_error_notice = true) {
if(!Bridge::isMPSendingServiceEnabled()) {
return null;
}

View File

@@ -87,7 +87,7 @@ class SendingServiceKeyCheck {
try {
$mailer_config = Mailer::getMailerConfig();
$result = $this->bridge->checkKey($mailer_config['mailpoet_api_key']);
$result = $this->bridge->checkAPIKey($mailer_config['mailpoet_api_key']);
$this->bridge->updateSubscriberCount($result);
} catch (\Exception $e) {
$result = false;

View File

@@ -22,7 +22,7 @@ class MailPoet {
}
function send($newsletter, $subscriber, $extra_params = array()) {
if($this->services_checker->checkMailPoetAPIKeyValid() === false) {
if($this->services_checker->isMailPoetAPIKeyValid() === false) {
$response = __('MailPoet API key is invalid!', 'mailpoet');
return Mailer::formatMailerSendErrorResult($response);
}

View File

@@ -54,13 +54,13 @@ class Bridge {
}
}
function checkKey($api_key) {
function checkAPIKey($api_key) {
$this->initApi($api_key);
$result = $this->api->checkKey();
return $this->processResult($result);
$result = $this->api->checkAPIKey();
return $this->processAPIKeyCheckResult($result);
}
function processResult(array $result) {
private function processAPIKeyCheckResult(array $result) {
$state_map = array(
200 => self::MAILPOET_KEY_VALID,
401 => self::MAILPOET_KEY_INVALID,
@@ -98,7 +98,7 @@ class Bridge {
return $this->processPremiumKeyCheckResult($result);
}
function processPremiumKeyCheckResult(array $result) {
private function processPremiumKeyCheckResult(array $result) {
$state_map = array(
200 => self::PREMIUM_KEY_VALID,
401 => self::PREMIUM_KEY_INVALID,
@@ -157,7 +157,7 @@ class Bridge {
$api_key_set = !empty($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['mailpoet_api_key']);
$premium_key_set = !empty($settings['premium']['premium_key']);
if($api_key_set && self::isMPSendingServiceEnabled()) {
$result = $this->checkKey($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['mailpoet_api_key']);
$result = $this->checkAPIKey($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['mailpoet_api_key']);
$this->updateSubscriberCount($result);
}
if($premium_key_set) {

View File

@@ -24,7 +24,7 @@ class API {
$this->setKey($api_key);
}
function checkKey() {
function checkAPIKey() {
$result = $this->request(
$this->url_me,
array('site' => home_url())

View File

@@ -20,7 +20,7 @@ class ServicesTest extends MailPoetTest {
function testItRespondsWithSuccessIfMSSKeyIsValid() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array('checkKey' => array('state' => Bridge::MAILPOET_KEY_VALID)),
array('checkAPIKey' => array('state' => Bridge::MAILPOET_KEY_VALID)),
$this
);
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
@@ -30,7 +30,7 @@ class ServicesTest extends MailPoetTest {
function testItRespondsWithErrorIfMSSKeyIsInvalid() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array('checkKey' => array('state' => Bridge::MAILPOET_KEY_INVALID)),
array('checkAPIKey' => array('state' => Bridge::MAILPOET_KEY_INVALID)),
$this
);
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
@@ -41,7 +41,7 @@ class ServicesTest extends MailPoetTest {
$date = new DateTime;
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array('checkKey' => array(
array('checkAPIKey' => array(
'state' => Bridge::MAILPOET_KEY_EXPIRING,
'data' => array('expire_at' => $date->format('c'))
)),
@@ -55,7 +55,7 @@ class ServicesTest extends MailPoetTest {
function testItRespondsWithErrorIfServiceIsUnavailableDuringMSSCheck() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array('checkKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
array('checkAPIKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
$this
);
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
@@ -66,7 +66,7 @@ class ServicesTest extends MailPoetTest {
function testItRespondsWithErrorIfMSSCheckThrowsAnException() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array('checkKey' => function() { throw new \Exception('test'); }),
array('checkAPIKey' => function() { throw new \Exception('test'); }),
$this
);
$response = $this->services_endpoint->verifyMailPoetKey($this->data);

View File

@@ -42,7 +42,7 @@ class MenuTest extends MailPoetTest {
$_REQUEST['page'] = 'mailpoet-newsletters';
$checker = Stub::make(
new ServicesChecker(),
array('checkMailPoetAPIKeyValid' => true),
array('isMailPoetAPIKeyValid' => true),
$this
);
$menu->checkMailPoetAPIKey($checker);
@@ -50,7 +50,7 @@ class MenuTest extends MailPoetTest {
$checker = Stub::make(
new ServicesChecker(),
array('checkMailPoetAPIKeyValid' => false),
array('isMailPoetAPIKeyValid' => false),
$this
);
$menu->checkMailPoetAPIKey($checker);

View File

@@ -8,7 +8,7 @@ use MailPoet\Services\Bridge;
class ServicesCheckerTest extends MailPoetTest {
function testItDoesNotCheckMSSKeyIfMPSendingServiceIsDisabled() {
$this->disableMailPoetSendingMethod();
$result = ServicesChecker::checkMailPoetAPIKeyValid();
$result = ServicesChecker::isMailPoetAPIKeyValid();
expect($result)->null();
}
@@ -18,14 +18,14 @@ class ServicesCheckerTest extends MailPoetTest {
Bridge::API_KEY_STATE_SETTING_NAME,
array('state' => Bridge::MAILPOET_KEY_VALID)
);
$result = ServicesChecker::checkMailPoetAPIKeyValid();
$result = ServicesChecker::isMailPoetAPIKeyValid();
expect($result)->true();
Setting::setValue(
Bridge::API_KEY_STATE_SETTING_NAME,
array('state' => Bridge::MAILPOET_KEY_INVALID)
);
$result = ServicesChecker::checkMailPoetAPIKeyValid();
$result = ServicesChecker::isMailPoetAPIKeyValid();
expect($result)->false();
Setting::setValue(
@@ -35,7 +35,7 @@ class ServicesCheckerTest extends MailPoetTest {
'data' => array('expire_at' => date('c'))
)
);
$result = ServicesChecker::checkMailPoetAPIKeyValid();
$result = ServicesChecker::isMailPoetAPIKeyValid();
expect($result)->true();
// unexpected state should be treated as valid
@@ -45,7 +45,7 @@ class ServicesCheckerTest extends MailPoetTest {
'state' => 'unexpected'
)
);
$result = ServicesChecker::checkMailPoetAPIKeyValid();
$result = ServicesChecker::isMailPoetAPIKeyValid();
expect($result)->true();
}

View File

@@ -95,7 +95,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
function testItProcesses() {
$this->sskeycheck->bridge = Stub::make(
new Bridge,
array('checkKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
array('checkAPIKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
$this
);
$this->setMailPoetSendingMethod();
@@ -113,7 +113,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
function testItProcessesSendingServiceKeyCheckQueue() {
$this->sskeycheck->bridge = Stub::make(
new Bridge,
array('checkKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
array('checkAPIKey' => array('code' => Bridge::MAILPOET_KEY_VALID)),
$this
);
$this->setMailPoetSendingMethod();
@@ -126,7 +126,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
function testItReschedulesCheckOnException() {
$this->sskeycheck->bridge = Stub::make(
new Bridge,
array('checkKey' => function () { throw new \Exception(); }),
array('checkAPIKey' => function () { throw new \Exception(); }),
$this
);
$this->setMailPoetSendingMethod();
@@ -140,7 +140,7 @@ class SendingServiceKeyCheckTest extends MailPoetTest {
function testItReschedulesCheckOnError() {
$this->sskeycheck->bridge = Stub::make(
new Bridge,
array('checkKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
array('checkAPIKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
$this
);
$this->setMailPoetSendingMethod();

View File

@@ -95,7 +95,7 @@ class MailPoetAPITest extends MailPoetTest {
$this->mailer->api_key = 'someapi';
$this->mailer->services_checker = Stub::make(
new ServicesChecker(),
array('checkMailPoetAPIKeyValid' => false),
array('isMailPoetAPIKeyValid' => false),
$this
);
$result = $this->mailer->send(

View File

@@ -47,24 +47,24 @@ class BridgeTest extends MailPoetTest {
}
function testItChecksMSSKey() {
$result = $this->bridge->checkKey($this->valid_key);
$result = $this->bridge->checkAPIKey($this->valid_key);
expect($result)->notEmpty();
expect($result['state'])->equals(Bridge::MAILPOET_KEY_VALID);
$result = $this->bridge->checkKey($this->invalid_key);
$result = $this->bridge->checkAPIKey($this->invalid_key);
expect($result)->notEmpty();
expect($result['state'])->equals(Bridge::MAILPOET_KEY_INVALID);
$result = $this->bridge->checkKey($this->expiring_key);
$result = $this->bridge->checkAPIKey($this->expiring_key);
expect($result)->notEmpty();
expect($result['state'])->equals(Bridge::MAILPOET_KEY_EXPIRING);
expect($result['data']['expire_at'])->notEmpty();
}
function testItReturnsErrorStateOnEmptyAPIResponseCodeDuringMSSCheck() {
$api = Stub::make(new API(null), array('checkKey' => array()), $this);
$api = Stub::make(new API(null), array('checkAPIKey' => array()), $this);
$this->bridge->api = $api;
$result = $this->bridge->checkKey($this->valid_key);
$result = $this->bridge->checkAPIKey($this->valid_key);
expect($result)->notEmpty();
expect($result['state'])->equals(Bridge::MAILPOET_KEY_CHECK_ERROR);
}
@@ -125,7 +125,7 @@ class BridgeTest extends MailPoetTest {
$api = Stub::make(
new API(null),
array(
'checkKey' => Stub::once(function() { return array(); }),
'checkAPIKey' => Stub::once(function() { return array(); }),
'checkPremiumKey' => Stub::once(function() { return array(); })
),
$this

View File

@@ -12,11 +12,11 @@ class MockAPI {
$this->setKey($api_key);
}
function checkKey() {
function checkAPIKey() {
// if a key begins with these codes, return them
$regex = '/^(401|402|503)/';
$code = preg_match($regex, $this->api_key, $m) ? $m[1] : 200;
return $this->processResponse($code);
return $this->processAPICheckResponse($code);
}
function checkPremiumKey() {
@@ -34,7 +34,7 @@ class MockAPI {
$this->api_key = $api_key;
}
private function processResponse($code) {
private function processAPICheckResponse($code) {
switch($code) {
case 200:
$body = array('subscriber_limit' => 10000);