2016-07-17 22:08:04 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\_support\models\authentication;
|
2016-07-17 22:08:04 +05:30
|
|
|
|
|
|
|
use api\components\User\Component;
|
2019-08-01 14:47:12 +05:30
|
|
|
use api\components\User\IdentityFactory;
|
2016-07-17 22:08:04 +05:30
|
|
|
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 Codeception\Specify;
|
|
|
|
use common\models\AccountSession;
|
|
|
|
use Yii;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class LogoutFormTest extends TestCase {
|
2016-07-17 22:08:04 +05:30
|
|
|
use Specify;
|
|
|
|
|
|
|
|
public function testValidateLogout() {
|
2018-04-18 02:17:25 +05:30
|
|
|
$this->specify('No actions if active session is not exists', function() {
|
2016-07-17 22:08:04 +05:30
|
|
|
$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();
|
2019-05-14 04:28:29 +05:30
|
|
|
$this->assertTrue($model->logout());
|
2016-07-17 22:08:04 +05:30
|
|
|
});
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
$this->specify('if active session is presented, then delete should be called', function() {
|
2016-07-17 22:08:04 +05:30
|
|
|
$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 [
|
2019-08-01 14:47:12 +05:30
|
|
|
'identityClass' => IdentityFactory::class,
|
2016-07-17 22:08:04 +05:30
|
|
|
'enableSession' => false,
|
|
|
|
'loginUrl' => null,
|
|
|
|
'secret' => 'secret',
|
2019-07-26 13:41:09 +05:30
|
|
|
'publicKeyPath' => 'data/certs/public.crt',
|
|
|
|
'privateKeyPath' => 'data/certs/private.key',
|
2016-07-17 22:08:04 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|