ResendVerificationEmailFormTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace frontend\tests\unit\models;
  3. use Codeception\Test\Unit;
  4. use common\fixtures\UserFixture;
  5. use frontend\models\ResendVerificationEmailForm;
  6. class ResendVerificationEmailFormTest extends Unit
  7. {
  8. /**
  9. * @var \frontend\tests\UnitTester
  10. */
  11. protected $tester;
  12. public function _before()
  13. {
  14. $this->tester->haveFixtures([
  15. 'user' => [
  16. 'class' => UserFixture::className(),
  17. 'dataFile' => codecept_data_dir() . 'user.php'
  18. ]
  19. ]);
  20. }
  21. public function testWrongEmailAddress()
  22. {
  23. $model = new ResendVerificationEmailForm();
  24. $model->attributes = [
  25. 'email' => 'aaa@bbb.cc'
  26. ];
  27. expect($model->validate())->false();
  28. expect($model->hasErrors())->true();
  29. expect($model->getFirstError('email'))->equals('There is no user with this email address.');
  30. }
  31. public function testEmptyEmailAddress()
  32. {
  33. $model = new ResendVerificationEmailForm();
  34. $model->attributes = [
  35. 'email' => ''
  36. ];
  37. expect($model->validate())->false();
  38. expect($model->hasErrors())->true();
  39. expect($model->getFirstError('email'))->equals('Email cannot be blank.');
  40. }
  41. public function testResendToActiveUser()
  42. {
  43. $model = new ResendVerificationEmailForm();
  44. $model->attributes = [
  45. 'email' => 'test2@mail.com'
  46. ];
  47. expect($model->validate())->false();
  48. expect($model->hasErrors())->true();
  49. expect($model->getFirstError('email'))->equals('There is no user with this email address.');
  50. }
  51. public function testSuccessfullyResend()
  52. {
  53. $model = new ResendVerificationEmailForm();
  54. $model->attributes = [
  55. 'email' => 'test@mail.com'
  56. ];
  57. expect($model->validate())->true();
  58. expect($model->hasErrors())->false();
  59. expect($model->sendEmail())->true();
  60. $this->tester->seeEmailIsSent();
  61. $mail = $this->tester->grabLastSentEmail();
  62. expect('valid email is sent', $mail)->isInstanceOf('yii\mail\MessageInterface');
  63. expect($mail->getTo())->hasKey('test@mail.com');
  64. expect($mail->getFrom())->hasKey(\Yii::$app->params['supportEmail']);
  65. expect($mail->getSubject())->equals('Account registration at ' . \Yii::$app->name);
  66. expect($mail->toString())->stringContainsString('4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330');
  67. }
  68. }