2013-12-02 19:25:21 +08:00
|
|
|
<?php
|
|
|
|
|
2019-01-28 04:30:35 +08:00
|
|
|
namespace tests\unit\models;
|
2013-12-02 19:25:21 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
class ContactFormTest extends \Codeception\Test\Unit
|
2013-12-17 07:27:33 +08:00
|
|
|
{
|
2016-07-16 09:13:51 +08:00
|
|
|
private $model;
|
2016-07-19 08:43:26 +08:00
|
|
|
/**
|
|
|
|
* @var \UnitTester
|
|
|
|
*/
|
|
|
|
public $tester;
|
2014-03-16 12:46:16 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
public function testEmailIsSentOnContact()
|
2014-03-16 12:46:16 +08:00
|
|
|
{
|
2016-07-03 01:13:40 +08:00
|
|
|
/** @var ContactForm $model */
|
2016-07-16 09:13:51 +08:00
|
|
|
$this->model = $this->getMockBuilder('app\models\ContactForm')
|
2016-07-03 01:13:40 +08:00
|
|
|
->setMethods(['validate'])
|
|
|
|
->getMock();
|
2014-03-16 12:46:16 +08:00
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
$this->model->expects($this->once())
|
|
|
|
->method('validate')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$this->model->attributes = [
|
2014-03-16 12:46:16 +08:00
|
|
|
'name' => 'Tester',
|
|
|
|
'email' => 'tester@example.com',
|
|
|
|
'subject' => 'very important letter subject',
|
|
|
|
'body' => 'body of current message',
|
|
|
|
];
|
|
|
|
|
2016-07-16 09:13:51 +08:00
|
|
|
expect_that($this->model->contact('admin@example.com'));
|
2014-03-16 12:46:16 +08:00
|
|
|
|
2016-07-19 08:43:26 +08:00
|
|
|
// using Yii2 module actions to check email was sent
|
|
|
|
$this->tester->seeEmailIsSent();
|
2014-03-16 12:46:16 +08:00
|
|
|
|
2016-07-19 08:43:26 +08:00
|
|
|
$emailMessage = $this->tester->grabLastSentEmail();
|
|
|
|
expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
|
|
|
|
expect($emailMessage->getTo())->hasKey('admin@example.com');
|
|
|
|
expect($emailMessage->getFrom())->hasKey('tester@example.com');
|
|
|
|
expect($emailMessage->getSubject())->equals('very important letter subject');
|
|
|
|
expect($emailMessage->toString())->contains('body of current message');
|
2014-03-16 12:46:16 +08:00
|
|
|
}
|
2013-12-02 19:25:21 +08:00
|
|
|
}
|