2016-06-16 02:24:13 +05:30
|
|
|
<?php
|
2024-12-02 15:40:55 +05:30
|
|
|
namespace api\tests\unit\models;
|
2016-06-16 02:24:13 +05:30
|
|
|
|
|
|
|
use api\models\FeedbackForm;
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2019-02-23 04:41:57 +05:30
|
|
|
use common\models\Account;
|
2024-12-02 15:40:55 +05:30
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use yii\symfonymailer\Message;
|
2016-06-16 02:24:13 +05:30
|
|
|
|
|
|
|
class FeedbackFormTest extends TestCase {
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testSendMessage(): void {
|
2016-10-29 03:17:31 +05:30
|
|
|
$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
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testSendMessageWithEmail(): void {
|
|
|
|
/** @var FeedbackForm|MockObject $model */
|
2016-10-29 03:17:31 +05:30
|
|
|
$model = $this->getMockBuilder(FeedbackForm::class)
|
2024-12-02 15:40:55 +05:30
|
|
|
->onlyMethods(['getAccount'])
|
2016-10-29 03:17:31 +05:30
|
|
|
->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
|
|
|
|
->method('getAccount')
|
2019-08-02 18:27:17 +05:30
|
|
|
->willReturn(new Account([
|
2024-12-02 15:40:55 +05:30
|
|
|
'id' => 123,
|
2016-10-29 03:17:31 +05:30
|
|
|
'username' => 'Erick',
|
|
|
|
'email' => 'find-this@email.net',
|
|
|
|
'created_at' => time() - 86400,
|
2019-08-02 18:27:17 +05:30
|
|
|
]));
|
2016-10-29 03:17:31 +05:30
|
|
|
$this->assertTrue($model->sendMessage());
|
|
|
|
/** @var Message $message */
|
|
|
|
$message = $this->tester->grabLastSentEmail();
|
|
|
|
$this->assertInstanceOf(Message::class, $message);
|
2024-12-02 15:40:55 +05:30
|
|
|
$data = $message;
|
2019-08-02 18:27:17 +05:30
|
|
|
$this->assertStringContainsString('find-this@email.net', $data);
|
2016-06-16 02:24:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|