yii2-netdisk/tests/unit/models/LoginFormTest.php
Luke English 94bfe89845
Update to PHP 7.4 and codeception/verify 2.2 (#260)
Co-authored-by: Luke English <luke.english@ec2i.biz>
2022-02-25 17:58:50 +03:00

52 lines
1.2 KiB
PHP

<?php
namespace tests\unit\models;
use app\models\LoginForm;
class LoginFormTest extends \Codeception\Test\Unit
{
private $model;
protected function _after()
{
\Yii::$app->user->logout();
}
public function testLoginNoUser()
{
$this->model = new LoginForm([
'username' => 'not_existing_username',
'password' => 'not_existing_password',
]);
verify($this->model->login())->false();
verify(\Yii::$app->user->isGuest)->true();
}
public function testLoginWrongPassword()
{
$this->model = new LoginForm([
'username' => 'demo',
'password' => 'wrong_password',
]);
verify($this->model->login())->false();
verify(\Yii::$app->user->isGuest)->true();
verify($this->model->errors)->arrayHasKey('password');
}
public function testLoginCorrect()
{
$this->model = new LoginForm([
'username' => 'demo',
'password' => 'demo',
]);
verify($this->model->login())->true();
verify(\Yii::$app->user->isGuest)->false();
verify($this->model->errors)->arrayHasNotKey('password');
}
}