2016-05-31 03:33:30 +05:30
|
|
|
<?php
|
2019-08-01 14:47:12 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-31 03:33:30 +05:30
|
|
|
namespace codeception\api\unit\models\authentication;
|
|
|
|
|
|
|
|
use api\models\authentication\RefreshTokenForm;
|
2019-02-23 04:41:57 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-05-31 03:33:30 +05:30
|
|
|
use Codeception\Specify;
|
|
|
|
use common\models\AccountSession;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\fixtures\AccountSessionFixture;
|
2016-05-31 03:33:30 +05:30
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class RefreshTokenFormTest extends TestCase {
|
2016-05-31 03:33:30 +05:30
|
|
|
use Specify;
|
|
|
|
|
2019-05-14 04:28:29 +05:30
|
|
|
public function _fixtures(): array {
|
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();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame(['error.refresh_token_not_exist'], $model->getErrors('refresh_token'));
|
2016-05-31 03:33:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('no errors if token exists', function() {
|
|
|
|
/** @var RefreshTokenForm $model */
|
|
|
|
$model = new class extends RefreshTokenForm {
|
|
|
|
public function getSession() {
|
|
|
|
return new AccountSession();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$model->validateRefreshToken();
|
2017-09-19 22:36:16 +05:30
|
|
|
$this->assertEmpty($model->getErrors('refresh_token'));
|
2016-05-31 03:33:30 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenew() {
|
2016-10-29 03:17:31 +05:30
|
|
|
$model = new RefreshTokenForm();
|
|
|
|
$model->refresh_token = $this->tester->grabFixture('sessions', 'admin')['refresh_token'];
|
2019-08-01 14:47:12 +05:30
|
|
|
$this->assertNotNull($model->renew());
|
2016-05-31 03:33:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|