You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

8 months ago
  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. verify($this->model->login())->false();
  18. verify(\Yii::$app->user->isGuest)->true();
  19. }
  20. public function testLoginWrongPassword()
  21. {
  22. $this->model = new LoginForm([
  23. 'username' => 'demo',
  24. 'password' => 'wrong_password',
  25. ]);
  26. verify($this->model->login())->false();
  27. verify(\Yii::$app->user->isGuest)->true();
  28. verify($this->model->errors)->arrayHasKey('password');
  29. }
  30. public function testLoginCorrect()
  31. {
  32. $this->model = new LoginForm([
  33. 'username' => 'demo',
  34. 'password' => 'demo',
  35. ]);
  36. verify($this->model->login())->true();
  37. verify(\Yii::$app->user->isGuest)->false();
  38. verify($this->model->errors)->arrayHasNotKey('password');
  39. }
  40. }