LoginCest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace frontend\tests\functional;
  3. use frontend\tests\FunctionalTester;
  4. use common\fixtures\UserFixture;
  5. class LoginCest
  6. {
  7. /**
  8. * Load fixtures before db transaction begin
  9. * Called in _before()
  10. * @see \Codeception\Module\Yii2::_before()
  11. * @see \Codeception\Module\Yii2::loadFixtures()
  12. * @return array
  13. */
  14. public function _fixtures()
  15. {
  16. return [
  17. 'user' => [
  18. 'class' => UserFixture::className(),
  19. 'dataFile' => codecept_data_dir() . 'login_data.php'
  20. ]
  21. ];
  22. }
  23. public function _before(FunctionalTester $I)
  24. {
  25. $I->amOnRoute('site/login');
  26. }
  27. protected function formParams($login, $password)
  28. {
  29. return [
  30. 'LoginForm[username]' => $login,
  31. 'LoginForm[password]' => $password,
  32. ];
  33. }
  34. public function checkEmpty(FunctionalTester $I)
  35. {
  36. $I->submitForm('#login-form', $this->formParams('', ''));
  37. $I->seeValidationError('Username cannot be blank.');
  38. $I->seeValidationError('Password cannot be blank.');
  39. }
  40. public function checkWrongPassword(FunctionalTester $I)
  41. {
  42. $I->submitForm('#login-form', $this->formParams('admin', 'wrong'));
  43. $I->seeValidationError('Incorrect username or password.');
  44. }
  45. public function checkValidLogin(FunctionalTester $I)
  46. {
  47. $I->submitForm('#login-form', $this->formParams('erau', 'password_0'));
  48. $I->see('Logout (erau)', 'form button[type=submit]');
  49. $I->dontSeeLink('Login');
  50. $I->dontSeeLink('Signup');
  51. }
  52. }