LoginFormCest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class LoginFormCest
  3. {
  4. public function _before(\FunctionalTester $I)
  5. {
  6. $I->amOnRoute('site/login');
  7. }
  8. public function openLoginPage(\FunctionalTester $I)
  9. {
  10. $I->see('Login', 'h1');
  11. }
  12. // demonstrates `amLoggedInAs` method
  13. public function internalLoginById(\FunctionalTester $I)
  14. {
  15. $I->amLoggedInAs(100);
  16. $I->amOnPage('/');
  17. $I->see('Logout (admin)');
  18. }
  19. // demonstrates `amLoggedInAs` method
  20. public function internalLoginByInstance(\FunctionalTester $I)
  21. {
  22. $I->amLoggedInAs(\app\models\User::findByUsername('admin'));
  23. $I->amOnPage('/');
  24. $I->see('Logout (admin)');
  25. }
  26. public function loginWithEmptyCredentials(\FunctionalTester $I)
  27. {
  28. $I->submitForm('#login-form', []);
  29. $I->expectTo('see validations errors');
  30. $I->see('Username cannot be blank.');
  31. $I->see('Password cannot be blank.');
  32. }
  33. public function loginWithWrongCredentials(\FunctionalTester $I)
  34. {
  35. $I->submitForm('#login-form', [
  36. 'LoginForm[username]' => 'admin',
  37. 'LoginForm[password]' => 'wrong',
  38. ]);
  39. $I->expectTo('see validations errors');
  40. $I->see('Incorrect username or password.');
  41. }
  42. public function loginSuccessfully(\FunctionalTester $I)
  43. {
  44. $I->submitForm('#login-form', [
  45. 'LoginForm[username]' => 'admin',
  46. 'LoginForm[password]' => 'admin',
  47. ]);
  48. $I->see('Logout (admin)');
  49. $I->dontSeeElement('form#login-form');
  50. }
  51. }