mirror of
https://github.com/elyby/accounts.git
synced 2024-12-25 06:39:46 +05:30
Реализован и оттестирован CleanupController
This commit is contained in:
parent
5c8bd20761
commit
7c9e856453
22
console/controllers/CleanupController.php
Normal file
22
console/controllers/CleanupController.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace console\controllers;
|
||||
|
||||
use common\models\OauthAccessToken;
|
||||
use yii\console\Controller;
|
||||
|
||||
class CleanupController extends Controller {
|
||||
|
||||
public function actionAccessTokens() {
|
||||
$accessTokens = OauthAccessToken::find()
|
||||
->andWhere(['<', 'expire_time', time()])
|
||||
->each(1000);
|
||||
|
||||
foreach($accessTokens as $token) {
|
||||
/** @var OauthAccessToken $token */
|
||||
$token->delete();
|
||||
}
|
||||
|
||||
return self::EXIT_CODE_NORMAL;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace tests\codeception\common\fixtures;
|
||||
|
||||
use common\models\OauthAccessToken;
|
||||
use yii\test\ActiveFixture;
|
||||
|
||||
class OauthAccessTokenFixture extends ActiveFixture {
|
||||
|
||||
public $modelClass = OauthAccessToken::class;
|
||||
|
||||
public $dataFile = '@tests/codeception/common/fixtures/data/oauth-access-tokens.php';
|
||||
|
||||
public $depends = [
|
||||
OauthSessionFixture::class,
|
||||
];
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
return [
|
||||
'admin-ely' => [
|
||||
'access_token' => '07541285-831e-1e47-e314-b950309a6fca',
|
||||
'session_id' => 1,
|
||||
'expire_time' => time() + 3600,
|
||||
],
|
||||
'admin-ely-expired' => [
|
||||
'access_token' => '2977ec21-3022-96f8-544db-2e1df936908',
|
||||
'session_id' => 1,
|
||||
'expire_time' => time() - 3600,
|
||||
],
|
||||
];
|
@ -6,7 +6,7 @@ return [
|
||||
'name' => 'Ely.by',
|
||||
'description' => 'Всем знакомое елуби',
|
||||
'redirect_uri' => 'http://ely.by',
|
||||
'account_id' => NULL,
|
||||
'account_id' => null,
|
||||
'is_trusted' => 0,
|
||||
'created_at' => 1455309271,
|
||||
],
|
||||
@ -16,7 +16,7 @@ return [
|
||||
'name' => 'TLauncher',
|
||||
'description' => 'Лучший альтернативный лаунчер для Minecraft с большим количеством версий и их модификаций, а также возмоностью входа как с лицензионным аккаунтом, так и без него.',
|
||||
'redirect_uri' => '',
|
||||
'account_id' => NULL,
|
||||
'account_id' => null,
|
||||
'is_trusted' => 0,
|
||||
'created_at' => 1455318468,
|
||||
],
|
||||
|
@ -1,3 +1,10 @@
|
||||
<?php
|
||||
return [
|
||||
'admin-ely' => [
|
||||
'id' => 1,
|
||||
'owner_type' => 'user',
|
||||
'owner_id' => 1,
|
||||
'client_id' => 'ely',
|
||||
'client_redirect_uri' => 'http://ely.by/authorization/oauth',
|
||||
],
|
||||
];
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace codeception\console\unit\controllers;
|
||||
|
||||
use common\models\OauthAccessToken;
|
||||
use console\controllers\CleanupController;
|
||||
use tests\codeception\common\fixtures\OauthAccessTokenFixture;
|
||||
use tests\codeception\console\unit\TestCase;
|
||||
use Yii;
|
||||
|
||||
class CleanupControllerTest extends TestCase {
|
||||
|
||||
public function _fixtures() {
|
||||
return [
|
||||
'accessTokens' => OauthAccessTokenFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function testActionAccessTokens() {
|
||||
/** @var OauthAccessToken $validAccessToken */
|
||||
$validAccessToken = $this->tester->grabFixture('accessTokens', 'admin-ely');
|
||||
/** @var OauthAccessToken $expiredAccessToken */
|
||||
$expiredAccessToken = $this->tester->grabFixture('accessTokens', 'admin-ely-expired');
|
||||
|
||||
$controller = new CleanupController('cleanup', Yii::$app);
|
||||
$this->assertEquals(0, $controller->actionAccessTokens());
|
||||
|
||||
$this->tester->canSeeRecord(OauthAccessToken::class, ['access_token' => $validAccessToken->access_token]);
|
||||
$this->tester->cantSeeRecord(OauthAccessToken::class, ['access_token' => $expiredAccessToken->access_token]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user