SignupCest.php 2.3 KB

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