mirror of
https://github.com/elyby/accounts.git
synced 2024-12-29 00:20:22 +05:30
51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
namespace codeception\api\unit\models\authentication;
|
|
|
|
use api\components\User\AuthenticationResult;
|
|
use api\models\authentication\RefreshTokenForm;
|
|
use api\tests\unit\TestCase;
|
|
use Codeception\Specify;
|
|
use common\models\AccountSession;
|
|
use common\tests\fixtures\AccountSessionFixture;
|
|
|
|
class RefreshTokenFormTest extends TestCase {
|
|
use Specify;
|
|
|
|
public function _fixtures() {
|
|
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();
|
|
$this->assertEquals(['error.refresh_token_not_exist'], $model->getErrors('refresh_token'));
|
|
});
|
|
|
|
$this->specify('no errors if token exists', function() {
|
|
/** @var RefreshTokenForm $model */
|
|
$model = new class extends RefreshTokenForm {
|
|
public function getSession() {
|
|
return new AccountSession();
|
|
}
|
|
};
|
|
$model->validateRefreshToken();
|
|
$this->assertEmpty($model->getErrors('refresh_token'));
|
|
});
|
|
}
|
|
|
|
public function testRenew() {
|
|
$model = new RefreshTokenForm();
|
|
$model->refresh_token = $this->tester->grabFixture('sessions', 'admin')['refresh_token'];
|
|
$this->assertInstanceOf(AuthenticationResult::class, $model->renew());
|
|
}
|
|
|
|
}
|