2016-07-17 22:08:04 +05:30
|
|
|
<?php
|
|
|
|
namespace tests\codeception\api\models\authentication;
|
|
|
|
|
|
|
|
use api\components\User\Component;
|
2017-09-19 22:36:16 +05:30
|
|
|
use api\components\User\Identity;
|
2016-07-17 22:08:04 +05:30
|
|
|
use api\models\authentication\LogoutForm;
|
|
|
|
use Codeception\Specify;
|
|
|
|
use common\models\AccountSession;
|
2016-10-29 03:17:31 +05:30
|
|
|
use tests\codeception\api\unit\TestCase;
|
2016-07-17 22:08:04 +05:30
|
|
|
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() {
|
|
|
|
$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();
|
|
|
|
expect($model->logout())->true();
|
|
|
|
});
|
|
|
|
|
|
|
|
$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 [
|
2017-09-19 22:36:16 +05:30
|
|
|
'identityClass' => Identity::class,
|
2016-07-17 22:08:04 +05:30
|
|
|
'enableSession' => false,
|
|
|
|
'loginUrl' => null,
|
|
|
|
'secret' => 'secret',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|