2016-07-17 19:38:04 +03:00
|
|
|
<?php
|
2019-08-02 03:29:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-02-20 22:58:52 +03:00
|
|
|
namespace api\tests\_support\models\authentication;
|
2016-07-17 19:38:04 +03:00
|
|
|
|
|
|
|
use api\components\User\Component;
|
|
|
|
use api\models\authentication\LogoutForm;
|
2019-02-23 02:11:57 +03:00
|
|
|
use api\tests\unit\TestCase;
|
2016-07-17 19:38:04 +03:00
|
|
|
use common\models\AccountSession;
|
|
|
|
use Yii;
|
|
|
|
|
2016-10-29 00:47:31 +03:00
|
|
|
class LogoutFormTest extends TestCase {
|
2019-12-21 02:26:06 +03:00
|
|
|
|
|
|
|
public function testNoActionWhenThereIsNoActiveSession() {
|
|
|
|
$userComp = $this->createPartialMock(Component::class, ['getActiveSession']);
|
|
|
|
$userComp->method('getActiveSession')->willReturn(null);
|
|
|
|
|
|
|
|
Yii::$app->set('user', $userComp);
|
|
|
|
|
|
|
|
$model = new LogoutForm();
|
|
|
|
$this->assertTrue($model->logout());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testActiveSessionShouldBeDeleted() {
|
|
|
|
$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 19:38:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|