PasswordResetRequestFormTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace frontend\tests\unit\models;
  3. use Yii;
  4. use frontend\models\PasswordResetRequestForm;
  5. use common\fixtures\UserFixture as UserFixture;
  6. use common\models\User;
  7. class PasswordResetRequestFormTest extends \Codeception\Test\Unit
  8. {
  9. /**
  10. * @var \frontend\tests\UnitTester
  11. */
  12. protected $tester;
  13. public function _before()
  14. {
  15. $this->tester->haveFixtures([
  16. 'user' => [
  17. 'class' => UserFixture::className(),
  18. 'dataFile' => codecept_data_dir() . 'user.php'
  19. ]
  20. ]);
  21. }
  22. public function testSendMessageWithWrongEmailAddress()
  23. {
  24. $model = new PasswordResetRequestForm();
  25. $model->email = 'not-existing-email@example.com';
  26. expect_not($model->sendEmail());
  27. }
  28. public function testNotSendEmailsToInactiveUser()
  29. {
  30. $user = $this->tester->grabFixture('user', 1);
  31. $model = new PasswordResetRequestForm();
  32. $model->email = $user['email'];
  33. expect_not($model->sendEmail());
  34. }
  35. public function testSendEmailSuccessfully()
  36. {
  37. $userFixture = $this->tester->grabFixture('user', 0);
  38. $model = new PasswordResetRequestForm();
  39. $model->email = $userFixture['email'];
  40. $user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
  41. expect_that($model->sendEmail());
  42. expect_that($user->password_reset_token);
  43. $emailMessage = $this->tester->grabLastSentEmail();
  44. expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
  45. expect($emailMessage->getTo())->hasKey($model->email);
  46. expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']);
  47. }
  48. }