You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
<?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'); |
|
} |
|
|
|
}
|
|
|