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

52 lines
1.2 KiB
PHP
Raw Normal View History

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
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
{
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',
]);
verify($this->model->login())->false();
verify(\Yii::$app->user->isGuest)->true();
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',
]);
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
}
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',
]);
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
}
2014-01-20 00:35:36 +08:00
}