SignupCest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace tests\codeception\frontend\functional;
  3. use common\models\User;
  4. use tests\codeception\frontend\_pages\SignupPage;
  5. class SignupCest
  6. {
  7. /**
  8. * This method is called before each cest class test method.
  9. *
  10. * @param \codeception_frontend\FunctionalTester $I
  11. */
  12. public function _before($I)
  13. {
  14. }
  15. /**
  16. * This method is called after each cest class test method, even if test failed.
  17. *
  18. * @param \codeception_frontend\FunctionalTester $I
  19. */
  20. public function _after($I)
  21. {
  22. //reload default fixtures
  23. $I->loadFixtures();
  24. }
  25. /**
  26. * This method is called when test fails.
  27. *
  28. * @param \codeception_frontend\FunctionalTester $I
  29. */
  30. public function _failed($I)
  31. {
  32. }
  33. /**
  34. * @param \codeception_frontend\FunctionalTester $I
  35. * @param \Codeception\Scenario $scenario
  36. */
  37. public function testUserSignup($I, $scenario)
  38. {
  39. $I->wantTo('ensure that signup works');
  40. $signupPage = SignupPage::openBy($I);
  41. $I->see('Signup', 'h1');
  42. $I->see('Please fill out the following fields to signup:');
  43. $I->amGoingTo('submit signup form with no data');
  44. $signupPage->submit([]);
  45. $I->expectTo('see validation errors');
  46. $I->see('Username cannot be blank.', '.help-block');
  47. $I->see('Email cannot be blank.', '.help-block');
  48. $I->see('Password cannot be blank.', '.help-block');
  49. $I->amGoingTo('submit signup form with not correct email');
  50. $signupPage->submit([
  51. 'username' => 'tester',
  52. 'email' => 'tester.email',
  53. 'password' => 'tester_password',
  54. ]);
  55. $I->expectTo('see that email address is wrong');
  56. $I->dontSee('Username cannot be blank.', '.help-block');
  57. $I->dontSee('Password cannot be blank.', '.help-block');
  58. $I->see('Email is not a valid email address.', '.help-block');
  59. $I->amGoingTo('submit signup form with correct email');
  60. $signupPage->submit([
  61. 'username' => 'tester',
  62. 'email' => 'tester.email@example.com',
  63. 'password' => 'tester_password',
  64. ]);
  65. $I->expectTo('see that user is created');
  66. $I->seeRecord('common\models\User', [
  67. 'username' => 'tester',
  68. 'email' => 'tester.email@example.com',
  69. ]);
  70. $I->expectTo('see that user logged in');
  71. $I->see('Logout (tester)', 'form button[type=submit]');
  72. }
  73. }