1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace tests\models;
- use app\models\LoginForm;
- use Codeception\Specify;
- 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',
- ]);
- expect_not($this->model->login());
- expect_that(\Yii::$app->user->isGuest);
- }
- public function testLoginWrongPassword()
- {
- $this->model = new LoginForm([
- 'username' => 'demo',
- 'password' => 'wrong_password',
- ]);
- expect_not($this->model->login());
- expect_that(\Yii::$app->user->isGuest);
- expect($this->model->errors)->hasKey('password');
- }
- public function testLoginCorrect()
- {
- $this->model = new LoginForm([
- 'username' => 'demo',
- 'password' => 'demo',
- ]);
- expect_that($this->model->login());
- expect_not(\Yii::$app->user->isGuest);
- expect($this->model->errors)->hasntKey('password');
- }
- }
|