LoginFormTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace tests\unit\models;
  3. use app\models\LoginForm;
  4. class LoginFormTest extends \Codeception\Test\Unit
  5. {
  6. private $model;
  7. protected function _after()
  8. {
  9. \Yii::$app->user->logout();
  10. }
  11. public function testLoginNoUser()
  12. {
  13. $this->model = new LoginForm([
  14. 'username' => 'not_existing_username',
  15. 'password' => 'not_existing_password',
  16. ]);
  17. expect_not($this->model->login());
  18. expect_that(\Yii::$app->user->isGuest);
  19. }
  20. public function testLoginWrongPassword()
  21. {
  22. $this->model = new LoginForm([
  23. 'username' => 'demo',
  24. 'password' => 'wrong_password',
  25. ]);
  26. expect_not($this->model->login());
  27. expect_that(\Yii::$app->user->isGuest);
  28. expect($this->model->errors)->hasKey('password');
  29. }
  30. public function testLoginCorrect()
  31. {
  32. $this->model = new LoginForm([
  33. 'username' => 'demo',
  34. 'password' => 'demo',
  35. ]);
  36. expect_that($this->model->login());
  37. expect_not(\Yii::$app->user->isGuest);
  38. expect($this->model->errors)->hasntKey('password');
  39. }
  40. }