Drupal investigation

LoginFormCest.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }