yii2-netdisk/tests/unit/models/LoginFormTest.php

53 lines
1.2 KiB
PHP
Raw Normal View History

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
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
{
2016-07-16 09:13:51 +08:00
private $model;
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([
'username' => 'not_existing_username',
'password' => 'not_existing_password',
]);
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
}
2014-03-16 12:46:16 +08:00
public function testLoginWrongPassword()
{
2016-07-16 09:13:51 +08:00
$this->model = new LoginForm([
'username' => 'demo',
'password' => 'wrong_password',
]);
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
}
2014-03-16 12:46:16 +08:00
public function testLoginCorrect()
{
2016-07-16 09:13:51 +08:00
$this->model = new LoginForm([
'username' => 'demo',
'password' => 'demo',
]);
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
}
2014-01-20 00:35:36 +08:00
}