accounts/api/tests/unit/models/authentication/LogoutFormTest.php

72 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace api\tests\_support\models\authentication;
use api\components\User\Component;
use api\components\User\Identity;
use api\models\authentication\LogoutForm;
2019-02-23 04:41:57 +05:30
use api\tests\unit\TestCase;
use Codeception\Specify;
use common\models\AccountSession;
use Yii;
class LogoutFormTest extends TestCase {
use Specify;
public function testValidateLogout() {
2018-04-18 02:17:25 +05:30
$this->specify('No actions if active session is not exists', function() {
$userComp = $this
->getMockBuilder(Component::class)
->setConstructorArgs([$this->getComponentArgs()])
->setMethods(['getActiveSession'])
->getMock();
$userComp
->expects($this->any())
->method('getActiveSession')
->will($this->returnValue(null));
Yii::$app->set('user', $userComp);
$model = new LogoutForm();
$this->assertTrue($model->logout());
});
2018-04-18 02:17:25 +05:30
$this->specify('if active session is presented, then delete should be called', function() {
$session = $this
->getMockBuilder(AccountSession::class)
->setMethods(['delete'])
->getMock();
$session
->expects($this->once())
->method('delete')
->willReturn(true);
$userComp = $this
->getMockBuilder(Component::class)
->setConstructorArgs([$this->getComponentArgs()])
->setMethods(['getActiveSession'])
->getMock();
$userComp
->expects($this->any())
->method('getActiveSession')
->will($this->returnValue($session));
Yii::$app->set('user', $userComp);
$model = new LogoutForm();
$model->logout();
});
}
private function getComponentArgs() {
return [
'identityClass' => Identity::class,
'enableSession' => false,
'loginUrl' => null,
'secret' => 'secret',
'publicKey' => 'data/certs/public.crt',
'privateKey' => 'data/certs/private.key',
];
}
}