2018-02-28 03:57:35 +05:30
|
|
|
<?php
|
2020-06-12 02:57:02 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace common\tests\unit\tasks;
|
2018-02-28 03:57:35 +05:30
|
|
|
|
|
|
|
use common\models\OauthClient;
|
|
|
|
use common\models\OauthSession;
|
|
|
|
use common\tasks\ClearOauthSessions;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\fixtures;
|
|
|
|
use common\tests\unit\TestCase;
|
2018-02-28 03:57:35 +05:30
|
|
|
use yii\queue\Queue;
|
|
|
|
|
|
|
|
class ClearOauthSessionsTest extends TestCase {
|
|
|
|
|
2019-05-14 04:28:29 +05:30
|
|
|
public function _fixtures(): array {
|
2018-02-28 03:57:35 +05:30
|
|
|
return [
|
|
|
|
'oauthClients' => fixtures\OauthClientFixture::class,
|
|
|
|
'oauthSessions' => fixtures\OauthSessionFixture::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testCreateFromClient(): void {
|
2018-02-28 03:57:35 +05:30
|
|
|
$client = new OauthClient();
|
|
|
|
$client->id = 'mocked-id';
|
|
|
|
|
|
|
|
$result = ClearOauthSessions::createFromOauthClient($client);
|
|
|
|
$this->assertInstanceOf(ClearOauthSessions::class, $result);
|
|
|
|
$this->assertSame('mocked-id', $result->clientId);
|
|
|
|
$this->assertNull($result->notSince);
|
|
|
|
|
|
|
|
$result = ClearOauthSessions::createFromOauthClient($client, time());
|
|
|
|
$this->assertInstanceOf(ClearOauthSessions::class, $result);
|
|
|
|
$this->assertSame('mocked-id', $result->clientId);
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertEqualsWithDelta(time(), $result->notSince, 1);
|
2018-02-28 03:57:35 +05:30
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testExecute(): void {
|
2020-06-12 02:57:02 +05:30
|
|
|
$task = new ClearOauthSessions('deleted-oauth-client-with-sessions', 1519510065);
|
2019-12-14 02:46:05 +05:30
|
|
|
$task->execute($this->createMock(Queue::class));
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2019-09-23 03:33:36 +05:30
|
|
|
$this->assertFalse(OauthSession::find()->andWhere(['legacy_id' => 3])->exists());
|
|
|
|
$this->assertTrue(OauthSession::find()->andWhere(['legacy_id' => 4])->exists());
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2020-06-12 02:57:02 +05:30
|
|
|
$task = new ClearOauthSessions('deleted-oauth-client-with-sessions');
|
2019-12-14 02:46:05 +05:30
|
|
|
$task->execute($this->createMock(Queue::class));
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2019-09-23 03:33:36 +05:30
|
|
|
$this->assertFalse(OauthSession::find()->andWhere(['legacy_id' => 4])->exists());
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2020-06-12 02:57:02 +05:30
|
|
|
$task = new ClearOauthSessions('some-not-exists-client-id');
|
2019-12-14 02:46:05 +05:30
|
|
|
$task->execute($this->createMock(Queue::class));
|
2018-02-28 03:57:35 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|