0
0

PasswordResetRequestFormTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }