2016-05-31 03:33:30 +05:30
|
|
|
<?php
|
|
|
|
namespace codeception\api\unit\models\authentication;
|
|
|
|
|
|
|
|
use api\components\User\RenewResult;
|
|
|
|
use api\models\authentication\RefreshTokenForm;
|
|
|
|
use Codeception\Specify;
|
|
|
|
use common\models\AccountSession;
|
2016-10-29 03:17:31 +05:30
|
|
|
use tests\codeception\api\unit\TestCase;
|
2016-05-31 03:33:30 +05:30
|
|
|
use tests\codeception\common\fixtures\AccountSessionFixture;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class RefreshTokenFormTest extends TestCase {
|
2016-05-31 03:33:30 +05:30
|
|
|
use Specify;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
public function _fixtures() {
|
2016-05-31 03:33:30 +05:30
|
|
|
return [
|
|
|
|
'sessions' => AccountSessionFixture::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidateRefreshToken() {
|
|
|
|
$this->specify('error.refresh_token_not_exist if passed token not exists', function() {
|
|
|
|
/** @var RefreshTokenForm $model */
|
|
|
|
$model = new class extends RefreshTokenForm {
|
|
|
|
public function getSession() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$model->validateRefreshToken();
|
|
|
|
expect($model->getErrors('refresh_token'))->equals(['error.refresh_token_not_exist']);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('no errors if token exists', function() {
|
|
|
|
/** @var RefreshTokenForm $model */
|
|
|
|
$model = new class extends RefreshTokenForm {
|
|
|
|
public function getSession() {
|
|
|
|
return new AccountSession();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$model->validateRefreshToken();
|
|
|
|
expect($model->getErrors('refresh_token'))->isEmpty();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenew() {
|
2016-10-29 03:17:31 +05:30
|
|
|
$model = new RefreshTokenForm();
|
|
|
|
$model->refresh_token = $this->tester->grabFixture('sessions', 'admin')['refresh_token'];
|
|
|
|
$this->assertInstanceOf(RenewResult::class, $model->renew());
|
2016-05-31 03:33:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|