2017-04-25 04:39:59 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace common\tests\unit\emails;
|
2017-04-25 04:39:59 +05:30
|
|
|
|
2019-06-07 04:46:13 +05:30
|
|
|
use common\components\EmailsRenderer\Component;
|
2017-04-25 04:39:59 +05:30
|
|
|
use common\emails\TemplateWithRenderer;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\_support\ProtectedCaller;
|
|
|
|
use common\tests\unit\TestCase;
|
2019-02-23 04:41:57 +05:30
|
|
|
use Ely\Email\TemplateBuilder;
|
2017-04-25 04:39:59 +05:30
|
|
|
use yii\mail\MailerInterface;
|
|
|
|
use yii\mail\MessageInterface;
|
|
|
|
|
|
|
|
class TemplateWithRendererTest extends TestCase {
|
|
|
|
use ProtectedCaller;
|
|
|
|
|
|
|
|
public function testConstructor() {
|
|
|
|
/** @var TemplateWithRenderer|\Mockery\MockInterface $template */
|
|
|
|
$template = mock(TemplateWithRenderer::class, ['mock-to', 'mock-locale'])->makePartial();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame('mock-to', $template->getTo());
|
|
|
|
$this->assertSame('mock-locale', $template->getLocale());
|
2017-04-25 04:39:59 +05:30
|
|
|
$this->assertInstanceOf(MailerInterface::class, $template->getMailer());
|
2019-06-07 04:46:13 +05:30
|
|
|
$this->assertInstanceOf(Component::class, $template->getRenderer());
|
2017-04-25 04:39:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateMessage() {
|
|
|
|
/** @var TemplateBuilder|\Mockery\MockInterface $templateBuilder */
|
|
|
|
$templateBuilder = mock(TemplateBuilder::class)->makePartial();
|
|
|
|
$templateBuilder->shouldReceive('render')->andReturn('mock-html');
|
|
|
|
|
2019-06-07 04:46:13 +05:30
|
|
|
/** @var Component|\Mockery\MockInterface $renderer */
|
|
|
|
$renderer = mock(Component::class)->makePartial();
|
2017-04-25 04:39:59 +05:30
|
|
|
$renderer->shouldReceive('getTemplate')->with('mock-template')->andReturn($templateBuilder);
|
|
|
|
|
|
|
|
/** @var TemplateWithRenderer|\Mockery\MockInterface $template */
|
|
|
|
$template = mock(TemplateWithRenderer::class, [['to@ely.by' => 'To'], 'mock-locale']);
|
|
|
|
$template->makePartial();
|
|
|
|
$template->shouldReceive('getEmailRenderer')->andReturn($renderer);
|
|
|
|
$template->shouldReceive('getFrom')->andReturn(['from@ely.by' => 'From']);
|
|
|
|
$template->shouldReceive('getSubject')->andReturn('mock-subject');
|
|
|
|
$template->shouldReceive('getTemplateName')->andReturn('mock-template');
|
|
|
|
/** @var \yii\swiftmailer\Message $message */
|
|
|
|
$message = $this->callProtected($template, 'createMessage');
|
|
|
|
$this->assertInstanceOf(MessageInterface::class, $message);
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame(['to@ely.by' => 'To'], $message->getTo());
|
|
|
|
$this->assertSame(['from@ely.by' => 'From'], $message->getFrom());
|
|
|
|
$this->assertSame('mock-subject', $message->getSubject());
|
|
|
|
$this->assertSame('mock-html', $message->getSwiftMessage()->getBody());
|
2017-04-25 04:39:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|