Blame view

tests/unit/models/LoginFormTest.php 1.14 KB
2049c43e   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  <?php
  
  namespace tests\models;
  
  use app\models\LoginForm;
  
  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');
      }
  
  }