2013-12-02 19:25:21 +08:00
|
|
|
<?php
|
|
|
|
|
2019-01-28 04:30:35 +08:00
|
|
|
namespace tests\unit\models;
|
2013-12-02 19:25:21 +08:00
|
|
|
|
2014-06-09 20:10:16 +08:00
|
|
|
use app\models\LoginForm;
|
2013-12-02 19:25:21 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
class LoginFormTest extends \Codeception\Test\Unit
|
2013-12-17 07:27:33 +08:00
|
|
|
{
|
2016-07-16 09:13:51 +08:00
|
|
|
private $model;
|
2013-12-31 04:17:36 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
protected function _after()
|
2014-03-16 12:46:16 +08:00
|
|
|
{
|
2016-07-16 09:13:51 +08:00
|
|
|
\Yii::$app->user->logout();
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
2014-02-14 22:05:56 +08:00
|
|
|
|
2014-03-16 12:46:16 +08:00
|
|
|
public function testLoginNoUser()
|
|
|
|
{
|
2016-07-16 09:13:51 +08:00
|
|
|
$this->model = new LoginForm([
|
2014-06-09 20:10:16 +08:00
|
|
|
'username' => 'not_existing_username',
|
|
|
|
'password' => 'not_existing_password',
|
|
|
|
]);
|
2013-12-31 04:17:36 +08:00
|
|
|
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($this->model->login())->false();
|
|
|
|
verify(\Yii::$app->user->isGuest)->true();
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
2013-12-31 04:17:36 +08:00
|
|
|
|
2014-03-16 12:46:16 +08:00
|
|
|
public function testLoginWrongPassword()
|
|
|
|
{
|
2016-07-16 09:13:51 +08:00
|
|
|
$this->model = new LoginForm([
|
2014-06-09 20:10:16 +08:00
|
|
|
'username' => 'demo',
|
|
|
|
'password' => 'wrong_password',
|
|
|
|
]);
|
2013-12-31 04:17:36 +08:00
|
|
|
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($this->model->login())->false();
|
|
|
|
verify(\Yii::$app->user->isGuest)->true();
|
|
|
|
verify($this->model->errors)->arrayHasKey('password');
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
2013-12-31 04:17:36 +08:00
|
|
|
|
2014-03-16 12:46:16 +08:00
|
|
|
public function testLoginCorrect()
|
|
|
|
{
|
2016-07-16 09:13:51 +08:00
|
|
|
$this->model = new LoginForm([
|
2014-06-09 20:10:16 +08:00
|
|
|
'username' => 'demo',
|
|
|
|
'password' => 'demo',
|
|
|
|
]);
|
2013-12-31 04:17:36 +08:00
|
|
|
|
2022-02-25 22:58:50 +08:00
|
|
|
verify($this->model->login())->true();
|
|
|
|
verify(\Yii::$app->user->isGuest)->false();
|
|
|
|
verify($this->model->errors)->arrayHasNotKey('password');
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
2013-12-31 04:17:36 +08:00
|
|
|
|
2014-01-20 00:35:36 +08:00
|
|
|
}
|