1
0

ContactFormTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace frontend\tests\unit\models;
  3. use Yii;
  4. use frontend\models\ContactForm;
  5. class ContactFormTest extends \Codeception\Test\Unit
  6. {
  7. public function testSendEmail()
  8. {
  9. $model = new ContactForm();
  10. $model->attributes = [
  11. 'name' => 'Tester',
  12. 'email' => 'tester@example.com',
  13. 'subject' => 'very important letter subject',
  14. 'body' => 'body of current message',
  15. ];
  16. expect_that($model->sendEmail('admin@example.com'));
  17. // using Yii2 module actions to check email was sent
  18. $this->tester->seeEmailIsSent();
  19. $emailMessage = $this->tester->grabLastSentEmail();
  20. expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
  21. expect($emailMessage->getTo())->hasKey('admin@example.com');
  22. expect($emailMessage->getFrom())->hasKey('tester@example.com');
  23. expect($emailMessage->getSubject())->equals('very important letter subject');
  24. expect($emailMessage->toString())->contains('body of current message');
  25. }
  26. }