2013-12-02 19:25:21 +08:00
|
|
|
<?php
|
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
namespace tests\models;
|
2013-12-02 19:25:21 +08:00
|
|
|
|
2014-06-09 20:10:16 +08:00
|
|
|
use app\models\LoginForm;
|
|
|
|
use Codeception\Specify;
|
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
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
expect_not($this->model->login());
|
|
|
|
expect_that(\Yii::$app->user->isGuest);
|
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
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
expect_not($this->model->login());
|
|
|
|
expect_that(\Yii::$app->user->isGuest);
|
|
|
|
expect($this->model->errors)->hasKey('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
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
expect_that($this->model->login());
|
|
|
|
expect_not(\Yii::$app->user->isGuest);
|
|
|
|
expect($this->model->errors)->hasntKey('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
|
|
|
}
|