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