You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

8 months ago
  1. <?php
  2. namespace tests\unit\models;
  3. use app\models\ContactForm;
  4. use yii\mail\MessageInterface;
  5. class ContactFormTest extends \Codeception\Test\Unit
  6. {
  7. /**
  8. * @var \UnitTester
  9. */
  10. public $tester;
  11. public function testEmailIsSentOnContact()
  12. {
  13. $model = new ContactForm();
  14. $model->attributes = [
  15. 'name' => 'Tester',
  16. 'email' => 'tester@example.com',
  17. 'subject' => 'very important letter subject',
  18. 'body' => 'body of current message',
  19. 'verifyCode' => 'testme',
  20. ];
  21. verify($model->contact('admin@example.com'))->notEmpty();
  22. // using Yii2 module actions to check email was sent
  23. $this->tester->seeEmailIsSent();
  24. /** @var MessageInterface $emailMessage */
  25. $emailMessage = $this->tester->grabLastSentEmail();
  26. verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
  27. verify($emailMessage->getTo())->arrayHasKey('admin@example.com');
  28. verify($emailMessage->getFrom())->arrayHasKey('noreply@example.com');
  29. verify($emailMessage->getReplyTo())->arrayHasKey('tester@example.com');
  30. verify($emailMessage->getSubject())->equals('very important letter subject');
  31. verify($emailMessage->toString())->stringContainsString('body of current message');
  32. }
  33. }