2016-05-15 04:03:21 +05:30
|
|
|
<?php
|
|
|
|
namespace codeception\api\unit\validators;
|
|
|
|
|
|
|
|
use api\validators\EmailActivationKeyValidator;
|
|
|
|
use Codeception\Specify;
|
|
|
|
use common\models\confirmations\ForgotPassword;
|
|
|
|
use common\models\EmailActivation;
|
2016-10-29 03:17:31 +05:30
|
|
|
use tests\codeception\api\unit\TestCase;
|
2016-05-15 04:03:21 +05:30
|
|
|
use tests\codeception\common\_support\ProtectedCaller;
|
|
|
|
use tests\codeception\common\fixtures\EmailActivationFixture;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class EmailActivationKeyValidatorTest extends TestCase {
|
2016-05-15 04:03:21 +05:30
|
|
|
use Specify;
|
|
|
|
use ProtectedCaller;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
public function _fixtures() {
|
2016-05-15 04:03:21 +05:30
|
|
|
return [
|
|
|
|
'emailActivations' => EmailActivationFixture::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindEmailActivationModel() {
|
|
|
|
$this->specify('get EmailActivation model for exists key', function() {
|
2016-10-29 03:17:31 +05:30
|
|
|
$key = $this->tester->grabFixture('emailActivations', 'freshRegistrationConfirmation')['key'];
|
2016-05-15 04:03:21 +05:30
|
|
|
$model = new EmailActivationKeyValidator();
|
|
|
|
/** @var EmailActivation $result */
|
|
|
|
$result = $this->callProtected($model, 'findEmailActivationModel', $key);
|
|
|
|
expect($result)->isInstanceOf(EmailActivation::class);
|
|
|
|
expect($result->key)->equals($key);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('get null model for exists key', function() {
|
|
|
|
$model = new EmailActivationKeyValidator();
|
|
|
|
expect($this->callProtected($model, 'findEmailActivationModel', 'invalid-key'))->null();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidateValue() {
|
|
|
|
$this->specify('get error.key_not_exists with validation wrong key', function () {
|
|
|
|
/** @var EmailActivationKeyValidator $model */
|
|
|
|
$model = new class extends EmailActivationKeyValidator {
|
|
|
|
public function findEmailActivationModel($key) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
expect($this->callProtected($model, 'validateValue', null))->equals([$model->notExist, []]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('get error.key_expire if we use old key', function () {
|
|
|
|
/** @var EmailActivationKeyValidator $model */
|
|
|
|
$model = new class extends EmailActivationKeyValidator {
|
|
|
|
public function findEmailActivationModel($key) {
|
|
|
|
$codeModel = new ForgotPassword();
|
|
|
|
$codeModel->created_at = time() - $codeModel->expirationTimeout - 10;
|
|
|
|
|
|
|
|
return $codeModel;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
expect($this->callProtected($model, 'validateValue', null))->equals([$model->expired, []]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('no errors, if model exists and not expired', function () {
|
|
|
|
/** @var EmailActivationKeyValidator $model */
|
|
|
|
$model = new class extends EmailActivationKeyValidator {
|
|
|
|
public function findEmailActivationModel($key) {
|
|
|
|
return new EmailActivation();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
expect($this->callProtected($model, 'validateValue', null))->null();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|