Unify key state constant names, leave back compat with unlocker [MAILPOET-1070]
This commit is contained in:
@ -44,9 +44,9 @@ class Services extends APIEndpoint {
|
|||||||
$state = !empty($result['state']) ? $result['state'] : null;
|
$state = !empty($result['state']) ? $result['state'] : null;
|
||||||
|
|
||||||
$success_message = null;
|
$success_message = null;
|
||||||
if($state == Bridge::PREMIUM_KEY_VALID) {
|
if($state == Bridge::KEY_VALID) {
|
||||||
$success_message = __('Your MailPoet Sending Service key has been successfully validated.', 'mailpoet');
|
$success_message = __('Your MailPoet Sending Service key has been successfully validated.', 'mailpoet');
|
||||||
} elseif($state == Bridge::PREMIUM_KEY_EXPIRING) {
|
} elseif($state == Bridge::KEY_EXPIRING) {
|
||||||
$success_message = sprintf(
|
$success_message = sprintf(
|
||||||
__('Your MailPoet Sending Service key expires on %s!', 'mailpoet'),
|
__('Your MailPoet Sending Service key expires on %s!', 'mailpoet'),
|
||||||
$this->date_time->formatDate(strtotime($result['data']['expire_at']))
|
$this->date_time->formatDate(strtotime($result['data']['expire_at']))
|
||||||
@ -58,7 +58,7 @@ class Services extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch($state) {
|
switch($state) {
|
||||||
case Bridge::PREMIUM_KEY_INVALID:
|
case Bridge::KEY_INVALID:
|
||||||
$error = __('Your MailPoet Sending Service key is invalid.', 'mailpoet');
|
$error = __('Your MailPoet Sending Service key is invalid.', 'mailpoet');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -94,9 +94,9 @@ class Services extends APIEndpoint {
|
|||||||
$state = !empty($result['state']) ? $result['state'] : null;
|
$state = !empty($result['state']) ? $result['state'] : null;
|
||||||
|
|
||||||
$success_message = null;
|
$success_message = null;
|
||||||
if($state == Bridge::PREMIUM_KEY_VALID) {
|
if($state == Bridge::KEY_VALID) {
|
||||||
$success_message = __('Your Premium key has been successfully validated.', 'mailpoet');
|
$success_message = __('Your Premium key has been successfully validated.', 'mailpoet');
|
||||||
} elseif($state == Bridge::PREMIUM_KEY_EXPIRING) {
|
} elseif($state == Bridge::KEY_EXPIRING) {
|
||||||
$success_message = sprintf(
|
$success_message = sprintf(
|
||||||
__('Your Premium key expires on %s.', 'mailpoet'),
|
__('Your Premium key expires on %s.', 'mailpoet'),
|
||||||
$this->date_time->formatDate(strtotime($result['data']['expire_at']))
|
$this->date_time->formatDate(strtotime($result['data']['expire_at']))
|
||||||
@ -111,10 +111,10 @@ class Services extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch($state) {
|
switch($state) {
|
||||||
case Bridge::PREMIUM_KEY_INVALID:
|
case Bridge::KEY_INVALID:
|
||||||
$error = __('Your Premium key is invalid.', 'mailpoet');
|
$error = __('Your Premium key is invalid.', 'mailpoet');
|
||||||
break;
|
break;
|
||||||
case Bridge::PREMIUM_KEY_ALREADY_USED:
|
case Bridge::KEY_ALREADY_USED:
|
||||||
$error = __('Your Premium key is already used on another site.', 'mailpoet');
|
$error = __('Your Premium key is already used on another site.', 'mailpoet');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -22,7 +22,7 @@ class ServicesChecker {
|
|||||||
|
|
||||||
if(!$mss_key_specified
|
if(!$mss_key_specified
|
||||||
|| empty($mss_key['state'])
|
|| empty($mss_key['state'])
|
||||||
|| $mss_key['state'] == Bridge::PREMIUM_KEY_INVALID
|
|| $mss_key['state'] == Bridge::KEY_INVALID
|
||||||
) {
|
) {
|
||||||
if($display_error_notice) {
|
if($display_error_notice) {
|
||||||
$error = Helpers::replaceLinkTags(
|
$error = Helpers::replaceLinkTags(
|
||||||
@ -33,7 +33,7 @@ class ServicesChecker {
|
|||||||
WPNotice::displayError($error);
|
WPNotice::displayError($error);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} elseif($mss_key['state'] == Bridge::PREMIUM_KEY_EXPIRING
|
} elseif($mss_key['state'] == Bridge::KEY_EXPIRING
|
||||||
&& !empty($mss_key['data']['expire_at'])
|
&& !empty($mss_key['data']['expire_at'])
|
||||||
) {
|
) {
|
||||||
if($display_error_notice) {
|
if($display_error_notice) {
|
||||||
@ -48,7 +48,7 @@ class ServicesChecker {
|
|||||||
WPNotice::displayWarning($error);
|
WPNotice::displayWarning($error);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} elseif($mss_key['state'] == Bridge::PREMIUM_KEY_VALID) {
|
} elseif($mss_key['state'] == Bridge::KEY_VALID) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +66,8 @@ class ServicesChecker {
|
|||||||
|
|
||||||
if(!$premium_key_specified
|
if(!$premium_key_specified
|
||||||
|| empty($premium_key['state'])
|
|| empty($premium_key['state'])
|
||||||
|| $premium_key['state'] === Bridge::PREMIUM_KEY_INVALID
|
|| $premium_key['state'] === Bridge::KEY_INVALID
|
||||||
|| $premium_key['state'] === Bridge::PREMIUM_KEY_ALREADY_USED
|
|| $premium_key['state'] === Bridge::KEY_ALREADY_USED
|
||||||
) {
|
) {
|
||||||
if($display_error_notice) {
|
if($display_error_notice) {
|
||||||
$error = Helpers::replaceLinkTags(
|
$error = Helpers::replaceLinkTags(
|
||||||
@ -78,7 +78,7 @@ class ServicesChecker {
|
|||||||
WPNotice::displayError($error);
|
WPNotice::displayError($error);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} elseif($premium_key['state'] === Bridge::PREMIUM_KEY_EXPIRING
|
} elseif($premium_key['state'] === Bridge::KEY_EXPIRING
|
||||||
&& !empty($premium_key['data']['expire_at'])
|
&& !empty($premium_key['data']['expire_at'])
|
||||||
) {
|
) {
|
||||||
if($display_error_notice) {
|
if($display_error_notice) {
|
||||||
@ -93,7 +93,7 @@ class ServicesChecker {
|
|||||||
WPNotice::displayWarning($error);
|
WPNotice::displayWarning($error);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} elseif($premium_key['state'] === Bridge::PREMIUM_KEY_VALID) {
|
} elseif($premium_key['state'] === Bridge::KEY_VALID) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,12 +15,13 @@ class Bridge {
|
|||||||
const PREMIUM_KEY_SETTING_NAME = 'premium.premium_key';
|
const PREMIUM_KEY_SETTING_NAME = 'premium.premium_key';
|
||||||
const PREMIUM_KEY_STATE_SETTING_NAME = 'premium.premium_key_state';
|
const PREMIUM_KEY_STATE_SETTING_NAME = 'premium.premium_key_state';
|
||||||
|
|
||||||
const PREMIUM_KEY_VALID = 'valid';
|
const PREMIUM_KEY_VALID = 'valid'; // for backwards compatibility until version 3.0.0
|
||||||
const PREMIUM_KEY_INVALID = 'invalid';
|
const KEY_VALID = 'valid';
|
||||||
const PREMIUM_KEY_EXPIRING = 'expiring';
|
const KEY_INVALID = 'invalid';
|
||||||
const PREMIUM_KEY_ALREADY_USED = 'already_used';
|
const KEY_EXPIRING = 'expiring';
|
||||||
|
const KEY_ALREADY_USED = 'already_used';
|
||||||
|
|
||||||
const PREMIUM_KEY_CHECK_ERROR = 'check_error';
|
const KEY_CHECK_ERROR = 'check_error';
|
||||||
|
|
||||||
const CHECK_ERROR_UNAVAILABLE = 503;
|
const CHECK_ERROR_UNAVAILABLE = 503;
|
||||||
const CHECK_ERROR_UNKNOWN = 'unknown';
|
const CHECK_ERROR_UNKNOWN = 'unknown';
|
||||||
@ -58,12 +59,12 @@ class Bridge {
|
|||||||
function checkMSSKey($api_key) {
|
function checkMSSKey($api_key) {
|
||||||
$this->initApi($api_key);
|
$this->initApi($api_key);
|
||||||
$result = $this->api->checkMSSKey();
|
$result = $this->api->checkMSSKey();
|
||||||
return $this->processPremiumKeyCheckResult($result);
|
return $this->processKeyCheckResult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeMSSKeyAndState($key, $state) {
|
function storeMSSKeyAndState($key, $state) {
|
||||||
if(empty($state['state'])
|
if(empty($state['state'])
|
||||||
|| $state['state'] === self::PREMIUM_KEY_CHECK_ERROR
|
|| $state['state'] === self::KEY_CHECK_ERROR
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -84,27 +85,27 @@ class Bridge {
|
|||||||
function checkPremiumKey($key) {
|
function checkPremiumKey($key) {
|
||||||
$this->initApi($key);
|
$this->initApi($key);
|
||||||
$result = $this->api->checkPremiumKey();
|
$result = $this->api->checkPremiumKey();
|
||||||
return $this->processPremiumKeyCheckResult($result);
|
return $this->processKeyCheckResult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processPremiumKeyCheckResult(array $result) {
|
private function processKeyCheckResult(array $result) {
|
||||||
$state_map = array(
|
$state_map = array(
|
||||||
200 => self::PREMIUM_KEY_VALID,
|
200 => self::KEY_VALID,
|
||||||
401 => self::PREMIUM_KEY_INVALID,
|
401 => self::KEY_INVALID,
|
||||||
402 => self::PREMIUM_KEY_ALREADY_USED,
|
402 => self::KEY_ALREADY_USED,
|
||||||
403 => self::PREMIUM_KEY_INVALID
|
403 => self::KEY_INVALID
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!empty($result['code']) && isset($state_map[$result['code']])) {
|
if(!empty($result['code']) && isset($state_map[$result['code']])) {
|
||||||
if($state_map[$result['code']] == self::PREMIUM_KEY_VALID
|
if($state_map[$result['code']] == self::KEY_VALID
|
||||||
&& !empty($result['data']['expire_at'])
|
&& !empty($result['data']['expire_at'])
|
||||||
) {
|
) {
|
||||||
$key_state = self::PREMIUM_KEY_EXPIRING;
|
$key_state = self::KEY_EXPIRING;
|
||||||
} else {
|
} else {
|
||||||
$key_state = $state_map[$result['code']];
|
$key_state = $state_map[$result['code']];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$key_state = self::PREMIUM_KEY_CHECK_ERROR;
|
$key_state = self::KEY_CHECK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->buildKeyState(
|
return $this->buildKeyState(
|
||||||
@ -115,7 +116,7 @@ class Bridge {
|
|||||||
|
|
||||||
function storePremiumKeyAndState($key, $state) {
|
function storePremiumKeyAndState($key, $state) {
|
||||||
if(empty($state['state'])
|
if(empty($state['state'])
|
||||||
|| $state['state'] === self::PREMIUM_KEY_CHECK_ERROR
|
|| $state['state'] === self::KEY_CHECK_ERROR
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -145,8 +146,8 @@ class Bridge {
|
|||||||
|
|
||||||
function updateSubscriberCount($result) {
|
function updateSubscriberCount($result) {
|
||||||
if(!empty($result['state'])
|
if(!empty($result['state'])
|
||||||
&& ($result['state'] === self::PREMIUM_KEY_VALID
|
&& ($result['state'] === self::KEY_VALID
|
||||||
|| $result['state'] === self::PREMIUM_KEY_EXPIRING)
|
|| $result['state'] === self::KEY_EXPIRING)
|
||||||
) {
|
) {
|
||||||
return $this->api->updateSubscriberCount(Subscriber::getTotalSubscribers());
|
return $this->api->updateSubscriberCount(Subscriber::getTotalSubscribers());
|
||||||
}
|
}
|
||||||
@ -156,7 +157,7 @@ class Bridge {
|
|||||||
static function invalidateKey() {
|
static function invalidateKey() {
|
||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
self::API_KEY_STATE_SETTING_NAME,
|
self::API_KEY_STATE_SETTING_NAME,
|
||||||
array('state' => self::PREMIUM_KEY_INVALID)
|
array('state' => self::KEY_INVALID)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class ServicesTest extends \MailPoetTest {
|
|||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array(
|
array(
|
||||||
'checkMSSKey' => array('state' => Bridge::PREMIUM_KEY_VALID),
|
'checkMSSKey' => array('state' => Bridge::KEY_VALID),
|
||||||
'storeMSSKeyAndState' => Stub::once()
|
'storeMSSKeyAndState' => Stub::once()
|
||||||
),
|
),
|
||||||
$this
|
$this
|
||||||
@ -36,7 +36,7 @@ class ServicesTest extends \MailPoetTest {
|
|||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array(
|
array(
|
||||||
'checkMSSKey' => array('state' => Bridge::PREMIUM_KEY_INVALID),
|
'checkMSSKey' => array('state' => Bridge::KEY_INVALID),
|
||||||
'storeMSSKeyAndState' => Stub::once()
|
'storeMSSKeyAndState' => Stub::once()
|
||||||
),
|
),
|
||||||
$this
|
$this
|
||||||
@ -51,7 +51,7 @@ class ServicesTest extends \MailPoetTest {
|
|||||||
new Bridge(),
|
new Bridge(),
|
||||||
array(
|
array(
|
||||||
'checkMSSKey' => array(
|
'checkMSSKey' => array(
|
||||||
'state' => Bridge::PREMIUM_KEY_EXPIRING,
|
'state' => Bridge::KEY_EXPIRING,
|
||||||
'data' => array('expire_at' => $date->format('c'))
|
'data' => array('expire_at' => $date->format('c'))
|
||||||
),
|
),
|
||||||
'storeMSSKeyAndState' => Stub::once()
|
'storeMSSKeyAndState' => Stub::once()
|
||||||
@ -140,7 +140,7 @@ class ServicesTest extends \MailPoetTest {
|
|||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array(
|
array(
|
||||||
'checkPremiumKey' => array('state' => Bridge::PREMIUM_KEY_VALID),
|
'checkPremiumKey' => array('state' => Bridge::KEY_VALID),
|
||||||
'storePremiumKeyAndState' => Stub::once()
|
'storePremiumKeyAndState' => Stub::once()
|
||||||
),
|
),
|
||||||
$this
|
$this
|
||||||
@ -156,7 +156,7 @@ class ServicesTest extends \MailPoetTest {
|
|||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array(
|
array(
|
||||||
'checkPremiumKey' => array('state' => Bridge::PREMIUM_KEY_INVALID),
|
'checkPremiumKey' => array('state' => Bridge::KEY_INVALID),
|
||||||
'storePremiumKeyAndState' => Stub::once()
|
'storePremiumKeyAndState' => Stub::once()
|
||||||
),
|
),
|
||||||
$this
|
$this
|
||||||
@ -169,7 +169,7 @@ class ServicesTest extends \MailPoetTest {
|
|||||||
$this->services_endpoint->bridge = Stub::make(
|
$this->services_endpoint->bridge = Stub::make(
|
||||||
new Bridge(),
|
new Bridge(),
|
||||||
array(
|
array(
|
||||||
'checkPremiumKey' => array('state' => Bridge::PREMIUM_KEY_ALREADY_USED),
|
'checkPremiumKey' => array('state' => Bridge::KEY_ALREADY_USED),
|
||||||
'storePremiumKeyAndState' => Stub::once()
|
'storePremiumKeyAndState' => Stub::once()
|
||||||
),
|
),
|
||||||
$this
|
$this
|
||||||
@ -184,7 +184,7 @@ class ServicesTest extends \MailPoetTest {
|
|||||||
new Bridge(),
|
new Bridge(),
|
||||||
array(
|
array(
|
||||||
'checkPremiumKey' => array(
|
'checkPremiumKey' => array(
|
||||||
'state' => Bridge::PREMIUM_KEY_EXPIRING,
|
'state' => Bridge::KEY_EXPIRING,
|
||||||
'data' => array('expire_at' => $date->format('c'))
|
'data' => array('expire_at' => $date->format('c'))
|
||||||
),
|
),
|
||||||
'storePremiumKeyAndState' => Stub::once()
|
'storePremiumKeyAndState' => Stub::once()
|
||||||
|
@ -34,7 +34,7 @@ class ServicesCheckerTest extends \MailPoetTest {
|
|||||||
function testItReturnsTrueIfMSSKeyIsValid() {
|
function testItReturnsTrueIfMSSKeyIsValid() {
|
||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::API_KEY_STATE_SETTING_NAME,
|
Bridge::API_KEY_STATE_SETTING_NAME,
|
||||||
array('state' => Bridge::PREMIUM_KEY_VALID)
|
array('state' => Bridge::KEY_VALID)
|
||||||
);
|
);
|
||||||
$result = $this->services_checker->isMailPoetAPIKeyValid();
|
$result = $this->services_checker->isMailPoetAPIKeyValid();
|
||||||
expect($result)->true();
|
expect($result)->true();
|
||||||
@ -43,7 +43,7 @@ class ServicesCheckerTest extends \MailPoetTest {
|
|||||||
function testItReturnsFalseIfMSSKeyIsInvalid() {
|
function testItReturnsFalseIfMSSKeyIsInvalid() {
|
||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::API_KEY_STATE_SETTING_NAME,
|
Bridge::API_KEY_STATE_SETTING_NAME,
|
||||||
array('state' => Bridge::PREMIUM_KEY_INVALID)
|
array('state' => Bridge::KEY_INVALID)
|
||||||
);
|
);
|
||||||
$result = $this->services_checker->isMailPoetAPIKeyValid();
|
$result = $this->services_checker->isMailPoetAPIKeyValid();
|
||||||
expect($result)->false();
|
expect($result)->false();
|
||||||
@ -53,7 +53,7 @@ class ServicesCheckerTest extends \MailPoetTest {
|
|||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::API_KEY_STATE_SETTING_NAME,
|
Bridge::API_KEY_STATE_SETTING_NAME,
|
||||||
array(
|
array(
|
||||||
'state' => Bridge::PREMIUM_KEY_EXPIRING,
|
'state' => Bridge::KEY_EXPIRING,
|
||||||
'data' => array('expire_at' => date('c'))
|
'data' => array('expire_at' => date('c'))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -92,7 +92,7 @@ class ServicesCheckerTest extends \MailPoetTest {
|
|||||||
function testItReturnsTrueIfPremiumKeyIsValid() {
|
function testItReturnsTrueIfPremiumKeyIsValid() {
|
||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
||||||
array('state' => Bridge::PREMIUM_KEY_VALID)
|
array('state' => Bridge::KEY_VALID)
|
||||||
);
|
);
|
||||||
$result = $this->services_checker->isPremiumKeyValid();
|
$result = $this->services_checker->isPremiumKeyValid();
|
||||||
expect($result)->true();
|
expect($result)->true();
|
||||||
@ -101,7 +101,7 @@ class ServicesCheckerTest extends \MailPoetTest {
|
|||||||
function testItReturnsFalseIfPremiumKeyIsInvalid() {
|
function testItReturnsFalseIfPremiumKeyIsInvalid() {
|
||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
||||||
array('state' => Bridge::PREMIUM_KEY_INVALID)
|
array('state' => Bridge::KEY_INVALID)
|
||||||
);
|
);
|
||||||
$result = $this->services_checker->isPremiumKeyValid();
|
$result = $this->services_checker->isPremiumKeyValid();
|
||||||
expect($result)->false();
|
expect($result)->false();
|
||||||
@ -110,7 +110,7 @@ class ServicesCheckerTest extends \MailPoetTest {
|
|||||||
function testItReturnsFalseIfPremiumKeyIsAlreadyUsed() {
|
function testItReturnsFalseIfPremiumKeyIsAlreadyUsed() {
|
||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
||||||
array('state' => Bridge::PREMIUM_KEY_ALREADY_USED)
|
array('state' => Bridge::KEY_ALREADY_USED)
|
||||||
);
|
);
|
||||||
$result = $this->services_checker->isPremiumKeyValid();
|
$result = $this->services_checker->isPremiumKeyValid();
|
||||||
expect($result)->false();
|
expect($result)->false();
|
||||||
@ -120,7 +120,7 @@ class ServicesCheckerTest extends \MailPoetTest {
|
|||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
Bridge::PREMIUM_KEY_STATE_SETTING_NAME,
|
||||||
array(
|
array(
|
||||||
'state' => Bridge::PREMIUM_KEY_EXPIRING,
|
'state' => Bridge::KEY_EXPIRING,
|
||||||
'data' => array('expire_at' => date('c'))
|
'data' => array('expire_at' => date('c'))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -19,7 +19,7 @@ class PremiumKeyCheckTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksPremiumKey() {
|
function testItChecksPremiumKey() {
|
||||||
$response = array('code' => Bridge::PREMIUM_KEY_VALID);
|
$response = array('code' => Bridge::KEY_VALID);
|
||||||
$this->worker->bridge = Stub::make(
|
$this->worker->bridge = Stub::make(
|
||||||
new Bridge,
|
new Bridge,
|
||||||
array(
|
array(
|
||||||
|
@ -20,7 +20,7 @@ class SendingServiceKeyCheckTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksMSSKey() {
|
function testItChecksMSSKey() {
|
||||||
$response = array('code' => Bridge::PREMIUM_KEY_VALID);
|
$response = array('code' => Bridge::KEY_VALID);
|
||||||
$this->worker->bridge = Stub::make(
|
$this->worker->bridge = Stub::make(
|
||||||
new Bridge,
|
new Bridge,
|
||||||
array(
|
array(
|
||||||
|
@ -53,32 +53,32 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
function testItChecksValidMSSKey() {
|
function testItChecksValidMSSKey() {
|
||||||
$result = $this->bridge->checkMSSKey($this->valid_key);
|
$result = $this->bridge->checkMSSKey($this->valid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_VALID);
|
expect($result['state'])->equals(Bridge::KEY_VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksInvalidMSSKey() {
|
function testItChecksInvalidMSSKey() {
|
||||||
$result = $this->bridge->checkMSSKey($this->invalid_key);
|
$result = $this->bridge->checkMSSKey($this->invalid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_INVALID);
|
expect($result['state'])->equals(Bridge::KEY_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksExpiringMSSKey() {
|
function testItChecksExpiringMSSKey() {
|
||||||
$result = $this->bridge->checkMSSKey($this->expiring_key);
|
$result = $this->bridge->checkMSSKey($this->expiring_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_EXPIRING);
|
expect($result['state'])->equals(Bridge::KEY_EXPIRING);
|
||||||
expect($result['data']['expire_at'])->notEmpty();
|
expect($result['data']['expire_at'])->notEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksAlreadyUsed() {
|
function testItChecksAlreadyUsed() {
|
||||||
$result = $this->bridge->checkMSSKey($this->used_key);
|
$result = $this->bridge->checkMSSKey($this->used_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_ALREADY_USED);
|
expect($result['state'])->equals(Bridge::KEY_ALREADY_USED);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksForbiddenEndpointMSSKey() {
|
function testItChecksForbiddenEndpointMSSKey() {
|
||||||
$result = $this->bridge->checkMSSKey($this->forbidden_endpoint_key);
|
$result = $this->bridge->checkMSSKey($this->forbidden_endpoint_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_INVALID);
|
expect($result['state'])->equals(Bridge::KEY_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItReturnsErrorStateOnEmptyAPIResponseCodeDuringMSSCheck() {
|
function testItReturnsErrorStateOnEmptyAPIResponseCodeDuringMSSCheck() {
|
||||||
@ -86,14 +86,14 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
$this->bridge->api = $api;
|
$this->bridge->api = $api;
|
||||||
$result = $this->bridge->checkMSSKey($this->valid_key);
|
$result = $this->bridge->checkMSSKey($this->valid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_CHECK_ERROR);
|
expect($result['state'])->equals(Bridge::KEY_CHECK_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItStoresExpectedMSSKeyStates() {
|
function testItStoresExpectedMSSKeyStates() {
|
||||||
$states = array(
|
$states = array(
|
||||||
Bridge::PREMIUM_KEY_VALID => $this->valid_key,
|
Bridge::KEY_VALID => $this->valid_key,
|
||||||
Bridge::PREMIUM_KEY_INVALID => $this->invalid_key,
|
Bridge::KEY_INVALID => $this->invalid_key,
|
||||||
Bridge::PREMIUM_KEY_EXPIRING => $this->expiring_key
|
Bridge::KEY_EXPIRING => $this->expiring_key
|
||||||
);
|
);
|
||||||
foreach($states as $state => $key) {
|
foreach($states as $state => $key) {
|
||||||
$state = array('state' => $state);
|
$state = array('state' => $state);
|
||||||
@ -105,7 +105,7 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
|
|
||||||
function testItDoesNotStoreErroneousOrUnexpectedMSSKeyStates() {
|
function testItDoesNotStoreErroneousOrUnexpectedMSSKeyStates() {
|
||||||
$states = array(
|
$states = array(
|
||||||
array('state' => Bridge::PREMIUM_KEY_CHECK_ERROR),
|
array('state' => Bridge::KEY_CHECK_ERROR),
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
foreach($states as $state) {
|
foreach($states as $state) {
|
||||||
@ -118,31 +118,31 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
function testItChecksValidPremiumKey() {
|
function testItChecksValidPremiumKey() {
|
||||||
$result = $this->bridge->checkPremiumKey($this->valid_key);
|
$result = $this->bridge->checkPremiumKey($this->valid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_VALID);
|
expect($result['state'])->equals(Bridge::KEY_VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksInvalidPremiumKey() {
|
function testItChecksInvalidPremiumKey() {
|
||||||
$result = $this->bridge->checkPremiumKey($this->invalid_key);
|
$result = $this->bridge->checkPremiumKey($this->invalid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_INVALID);
|
expect($result['state'])->equals(Bridge::KEY_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksAlreadyUsedPremiumKey() {
|
function testItChecksAlreadyUsedPremiumKey() {
|
||||||
$result = $this->bridge->checkPremiumKey($this->used_premium_key);
|
$result = $this->bridge->checkPremiumKey($this->used_premium_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_ALREADY_USED);
|
expect($result['state'])->equals(Bridge::KEY_ALREADY_USED);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksForbiddenEndpointPremiumKey() {
|
function testItChecksForbiddenEndpointPremiumKey() {
|
||||||
$result = $this->bridge->checkPremiumKey($this->forbidden_endpoint_key);
|
$result = $this->bridge->checkPremiumKey($this->forbidden_endpoint_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_INVALID);
|
expect($result['state'])->equals(Bridge::KEY_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksExpiringPremiumKey() {
|
function testItChecksExpiringPremiumKey() {
|
||||||
$result = $this->bridge->checkPremiumKey($this->expiring_premium_key);
|
$result = $this->bridge->checkPremiumKey($this->expiring_premium_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_EXPIRING);
|
expect($result['state'])->equals(Bridge::KEY_EXPIRING);
|
||||||
expect($result['data']['expire_at'])->notEmpty();
|
expect($result['data']['expire_at'])->notEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,15 +151,15 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
$this->bridge->api = $api;
|
$this->bridge->api = $api;
|
||||||
$result = $this->bridge->checkPremiumKey($this->valid_key);
|
$result = $this->bridge->checkPremiumKey($this->valid_key);
|
||||||
expect($result)->notEmpty();
|
expect($result)->notEmpty();
|
||||||
expect($result['state'])->equals(Bridge::PREMIUM_KEY_CHECK_ERROR);
|
expect($result['state'])->equals(Bridge::KEY_CHECK_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItStoresExpectedPremiumKeyStates() {
|
function testItStoresExpectedPremiumKeyStates() {
|
||||||
$states = array(
|
$states = array(
|
||||||
Bridge::PREMIUM_KEY_VALID => $this->valid_key,
|
Bridge::KEY_VALID => $this->valid_key,
|
||||||
Bridge::PREMIUM_KEY_INVALID => $this->invalid_key,
|
Bridge::KEY_INVALID => $this->invalid_key,
|
||||||
Bridge::PREMIUM_KEY_ALREADY_USED => $this->used_premium_key,
|
Bridge::KEY_ALREADY_USED => $this->used_premium_key,
|
||||||
Bridge::PREMIUM_KEY_EXPIRING => $this->expiring_key
|
Bridge::KEY_EXPIRING => $this->expiring_key
|
||||||
);
|
);
|
||||||
foreach($states as $state => $key) {
|
foreach($states as $state => $key) {
|
||||||
$state = array('state' => $state);
|
$state = array('state' => $state);
|
||||||
@ -171,7 +171,7 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
|
|
||||||
function testItDoesNotStoreErroneousOrUnexpectedPremiumKeyStates() {
|
function testItDoesNotStoreErroneousOrUnexpectedPremiumKeyStates() {
|
||||||
$states = array(
|
$states = array(
|
||||||
array('state' => Bridge::PREMIUM_KEY_CHECK_ERROR),
|
array('state' => Bridge::KEY_CHECK_ERROR),
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
foreach($states as $state) {
|
foreach($states as $state) {
|
||||||
@ -184,14 +184,14 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
function testItUpdatesSubscriberCount() {
|
function testItUpdatesSubscriberCount() {
|
||||||
// it performs update if the key is valid or expiring
|
// it performs update if the key is valid or expiring
|
||||||
$result = array();
|
$result = array();
|
||||||
$result['state'] = Bridge::PREMIUM_KEY_VALID;
|
$result['state'] = Bridge::KEY_VALID;
|
||||||
$updated = $this->bridge->updateSubscriberCount($result);
|
$updated = $this->bridge->updateSubscriberCount($result);
|
||||||
expect($updated)->true();
|
expect($updated)->true();
|
||||||
$result['state'] = Bridge::PREMIUM_KEY_EXPIRING;
|
$result['state'] = Bridge::KEY_EXPIRING;
|
||||||
$updated = $this->bridge->updateSubscriberCount($result);
|
$updated = $this->bridge->updateSubscriberCount($result);
|
||||||
expect($updated)->true();
|
expect($updated)->true();
|
||||||
// it does not perform update if the key is invalid
|
// it does not perform update if the key is invalid
|
||||||
$result['state'] = Bridge::PREMIUM_KEY_INVALID;
|
$result['state'] = Bridge::KEY_INVALID;
|
||||||
$updated = $this->bridge->updateSubscriberCount($result);
|
$updated = $this->bridge->updateSubscriberCount($result);
|
||||||
expect($updated)->null();
|
expect($updated)->null();
|
||||||
}
|
}
|
||||||
@ -199,10 +199,10 @@ class BridgeTest extends \MailPoetTest {
|
|||||||
function testItInvalidatesMSSKey() {
|
function testItInvalidatesMSSKey() {
|
||||||
Setting::setValue(
|
Setting::setValue(
|
||||||
Bridge::API_KEY_STATE_SETTING_NAME,
|
Bridge::API_KEY_STATE_SETTING_NAME,
|
||||||
array('state' => Bridge::PREMIUM_KEY_VALID)
|
array('state' => Bridge::KEY_VALID)
|
||||||
);
|
);
|
||||||
Bridge::invalidateKey();
|
Bridge::invalidateKey();
|
||||||
expect($this->getMSSKeyState())->equals(array('state' => Bridge::PREMIUM_KEY_INVALID));
|
expect($this->getMSSKeyState())->equals(array('state' => Bridge::KEY_INVALID));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItChecksAndStoresKeysOnSettingsSave() {
|
function testItChecksAndStoresKeysOnSettingsSave() {
|
||||||
|
Reference in New Issue
Block a user