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
|
|
|
|
|
|
|
use common\emails\Template;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\_support\ProtectedCaller;
|
|
|
|
use common\tests\unit\TestCase;
|
2017-04-25 04:39:59 +05:30
|
|
|
use Yii;
|
|
|
|
use yii\mail\MailerInterface;
|
|
|
|
use yii\mail\MessageInterface;
|
|
|
|
|
|
|
|
class TemplateTest extends TestCase {
|
|
|
|
use ProtectedCaller;
|
|
|
|
|
|
|
|
public function testConstructor() {
|
|
|
|
/** @var Template|\Mockery\MockInterface $template */
|
|
|
|
$template = mock(Template::class, ['find-me'])->makePartial();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame('find-me', $template->getTo());
|
2017-04-25 04:39:59 +05:30
|
|
|
$this->assertInstanceOf(MailerInterface::class, $template->getMailer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFrom() {
|
|
|
|
Yii::$app->params['fromEmail'] = 'find-me';
|
|
|
|
/** @var Template|\Mockery\MockInterface $template */
|
|
|
|
$template = mock(Template::class)->makePartial();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame(['find-me' => 'Ely.by Accounts'], $template->getFrom());
|
2017-04-25 04:39:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetParams() {
|
|
|
|
/** @var Template|\Mockery\MockInterface $template */
|
|
|
|
$template = mock(Template::class)->makePartial();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame([], $template->getParams());
|
2017-04-25 04:39:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateMessage() {
|
|
|
|
Yii::$app->params['fromEmail'] = 'from@ely.by';
|
|
|
|
/** @var Template|\Mockery\MockInterface $template */
|
|
|
|
$template = mock(Template::class, [['to@ely.by' => 'To']])->makePartial();
|
|
|
|
$template->shouldReceive('getSubject')->andReturn('mock-subject');
|
|
|
|
/** @var MessageInterface $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' => 'Ely.by Accounts'], $message->getFrom());
|
|
|
|
$this->assertSame('mock-subject', $message->getSubject());
|
2017-04-25 04:39:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|