ResendVerificationEmailCest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace frontend\tests\functional;
  3. use common\fixtures\UserFixture;
  4. use frontend\tests\FunctionalTester;
  5. class ResendVerificationEmailCest
  6. {
  7. protected $formId = '#resend-verification-email-form';
  8. /**
  9. * Load fixtures before db transaction begin
  10. * Called in _before()
  11. * @see \Codeception\Module\Yii2::_before()
  12. * @see \Codeception\Module\Yii2::loadFixtures()
  13. * @return array
  14. */
  15. public function _fixtures()
  16. {
  17. return [
  18. 'user' => [
  19. 'class' => UserFixture::className(),
  20. 'dataFile' => codecept_data_dir() . 'user.php',
  21. ],
  22. ];
  23. }
  24. public function _before(FunctionalTester $I)
  25. {
  26. $I->amOnRoute('/site/resend-verification-email');
  27. }
  28. protected function formParams($email)
  29. {
  30. return [
  31. 'ResendVerificationEmailForm[email]' => $email
  32. ];
  33. }
  34. public function checkPage(FunctionalTester $I)
  35. {
  36. $I->see('Resend verification email', 'h1');
  37. $I->see('Please fill out your email. A verification email will be sent there.');
  38. }
  39. public function checkEmptyField(FunctionalTester $I)
  40. {
  41. $I->submitForm($this->formId, $this->formParams(''));
  42. $I->seeValidationError('Email cannot be blank.');
  43. }
  44. public function checkWrongEmailFormat(FunctionalTester $I)
  45. {
  46. $I->submitForm($this->formId, $this->formParams('abcd.com'));
  47. $I->seeValidationError('Email is not a valid email address.');
  48. }
  49. public function checkWrongEmail(FunctionalTester $I)
  50. {
  51. $I->submitForm($this->formId, $this->formParams('wrong@email.com'));
  52. $I->seeValidationError('There is no user with this email address.');
  53. }
  54. public function checkAlreadyVerifiedEmail(FunctionalTester $I)
  55. {
  56. $I->submitForm($this->formId, $this->formParams('test2@mail.com'));
  57. $I->seeValidationError('There is no user with this email address.');
  58. }
  59. public function checkSendSuccessfully(FunctionalTester $I)
  60. {
  61. $I->submitForm($this->formId, $this->formParams('test@mail.com'));
  62. $I->canSeeEmailIsSent();
  63. $I->seeRecord('common\models\User', [
  64. 'email' => 'test@mail.com',
  65. 'username' => 'test.test',
  66. 'status' => \common\models\User::STATUS_INACTIVE
  67. ]);
  68. $I->see('Check your email for further instructions.');
  69. }
  70. }