2013-12-02 15:25:21 +04:00
|
|
|
<?php
|
|
|
|
|
2019-01-27 21:30:35 +01:00
|
|
|
namespace tests\unit\models;
|
2013-12-02 15:25:21 +04:00
|
|
|
|
2019-04-23 15:31:43 +03:00
|
|
|
use app\models\ContactForm;
|
|
|
|
use yii\mail\MessageInterface;
|
|
|
|
|
2016-07-16 04:13:51 +03:00
|
|
|
class ContactFormTest extends \Codeception\Test\Unit
|
2013-12-17 00:27:33 +01:00
|
|
|
{
|
2016-07-19 03:43:26 +03:00
|
|
|
/**
|
|
|
|
* @var \UnitTester
|
|
|
|
*/
|
|
|
|
public $tester;
|
2014-03-16 10:46:16 +06:00
|
|
|
|
2016-07-16 04:13:51 +03:00
|
|
|
public function testEmailIsSentOnContact()
|
2014-03-16 10:46:16 +06:00
|
|
|
{
|
2020-11-16 16:22:10 +03:00
|
|
|
$model = new ContactForm();
|
2014-03-16 10:46:16 +06:00
|
|
|
|
2020-11-16 16:22:10 +03:00
|
|
|
$model->attributes = [
|
2014-03-16 10:46:16 +06:00
|
|
|
'name' => 'Tester',
|
|
|
|
'email' => 'tester@example.com',
|
|
|
|
'subject' => 'very important letter subject',
|
|
|
|
'body' => 'body of current message',
|
2020-11-16 16:22:10 +03:00
|
|
|
'verifyCode' => 'testme',
|
2014-03-16 10:46:16 +06:00
|
|
|
];
|
|
|
|
|
2022-02-25 14:58:50 +00:00
|
|
|
verify($model->contact('admin@example.com'))->notEmpty();
|
2014-03-16 10:46:16 +06:00
|
|
|
|
2016-07-19 03:43:26 +03:00
|
|
|
// using Yii2 module actions to check email was sent
|
|
|
|
$this->tester->seeEmailIsSent();
|
2014-03-16 10:46:16 +06:00
|
|
|
|
2019-04-23 15:31:43 +03:00
|
|
|
/** @var MessageInterface $emailMessage */
|
2016-07-19 03:43:26 +03:00
|
|
|
$emailMessage = $this->tester->grabLastSentEmail();
|
2022-02-25 14:58:50 +00:00
|
|
|
verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
|
|
|
|
verify($emailMessage->getTo())->arrayHasKey('admin@example.com');
|
|
|
|
verify($emailMessage->getFrom())->arrayHasKey('noreply@example.com');
|
|
|
|
verify($emailMessage->getReplyTo())->arrayHasKey('tester@example.com');
|
|
|
|
verify($emailMessage->getSubject())->equals('very important letter subject');
|
|
|
|
verify($emailMessage->toString())->stringContainsString('body of current message');
|
2014-03-16 10:46:16 +06:00
|
|
|
}
|
2013-12-02 15:25:21 +04:00
|
|
|
}
|