2016-06-16 02:24:13 +05:30
|
|
|
<?php
|
|
|
|
namespace codeception\api\unit\models;
|
|
|
|
|
|
|
|
use api\models\FeedbackForm;
|
|
|
|
use common\models\Account;
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-10-29 03:17:31 +05:30
|
|
|
use yii\swiftmailer\Message;
|
2016-06-16 02:24:13 +05:30
|
|
|
|
|
|
|
class FeedbackFormTest extends TestCase {
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
public function testSendMessage() {
|
|
|
|
$model = new FeedbackForm([
|
|
|
|
'subject' => 'Тема обращения',
|
|
|
|
'email' => 'erickskrauch@ely.by',
|
|
|
|
'message' => 'Привет мир!',
|
|
|
|
]);
|
|
|
|
$this->assertTrue($model->sendMessage());
|
|
|
|
$this->tester->seeEmailIsSent(1, 'message file exists');
|
2016-06-16 02:24:13 +05:30
|
|
|
}
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
public function testSendMessageWithEmail() {
|
|
|
|
/** @var FeedbackForm|\PHPUnit_Framework_MockObject_MockObject $model */
|
|
|
|
$model = $this->getMockBuilder(FeedbackForm::class)
|
|
|
|
->setMethods(['getAccount'])
|
|
|
|
->setConstructorArgs([[
|
2016-06-16 02:24:13 +05:30
|
|
|
'subject' => 'Тема обращения',
|
|
|
|
'email' => 'erickskrauch@ely.by',
|
|
|
|
'message' => 'Привет мир!',
|
2016-10-29 03:17:31 +05:30
|
|
|
]])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$model
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getAccount')
|
|
|
|
->will($this->returnValue(new Account([
|
|
|
|
'id' => '123',
|
|
|
|
'username' => 'Erick',
|
|
|
|
'email' => 'find-this@email.net',
|
|
|
|
'created_at' => time() - 86400,
|
|
|
|
])));
|
|
|
|
$this->assertTrue($model->sendMessage());
|
|
|
|
/** @var Message $message */
|
|
|
|
$message = $this->tester->grabLastSentEmail();
|
|
|
|
$this->assertInstanceOf(Message::class, $message);
|
|
|
|
$data = (string)$message;
|
|
|
|
$this->assertContains('find-this@email.net', $data);
|
2016-06-16 02:24:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|