2016-07-17 22:08:04 +05:30
|
|
|
<?php
|
2019-08-02 05:59:20 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
namespace api\tests\unit\models\authentication;
|
2016-07-17 22:08:04 +05:30
|
|
|
|
|
|
|
use api\components\User\Component;
|
|
|
|
use api\models\authentication\LogoutForm;
|
2019-02-23 04:41:57 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-07-17 22:08:04 +05:30
|
|
|
use common\models\AccountSession;
|
|
|
|
use Yii;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class LogoutFormTest extends TestCase {
|
2019-12-21 04:56:06 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testNoActionWhenThereIsNoActiveSession(): void {
|
2019-12-21 04:56:06 +05:30
|
|
|
$userComp = $this->createPartialMock(Component::class, ['getActiveSession']);
|
|
|
|
$userComp->method('getActiveSession')->willReturn(null);
|
|
|
|
|
|
|
|
Yii::$app->set('user', $userComp);
|
|
|
|
|
|
|
|
$model = new LogoutForm();
|
|
|
|
$this->assertTrue($model->logout());
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testActiveSessionShouldBeDeleted(): void {
|
2019-12-21 04:56:06 +05:30
|
|
|
$session = $this->createPartialMock(AccountSession::class, ['delete']);
|
|
|
|
$session->expects($this->once())->method('delete')->willReturn(true);
|
|
|
|
|
|
|
|
$userComp = $this->createPartialMock(Component::class, ['getActiveSession']);
|
|
|
|
$userComp->method('getActiveSession')->willReturn($session);
|
|
|
|
|
|
|
|
Yii::$app->set('user', $userComp);
|
|
|
|
|
|
|
|
$model = new LogoutForm();
|
|
|
|
$model->logout();
|
2016-07-17 22:08:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|