Drupal investigation

LoginFormTest.php 1.2KB

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