mirror of
https://github.com/elyby/accounts.git
synced 2024-11-26 16:52:02 +05:30
Добавлены тесты для новоявленного компонента
This commit is contained in:
parent
8c6921ff0e
commit
f3259c9c0e
@ -40,7 +40,7 @@ abstract class TemplateWithRenderer extends Template {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getTemplateName(): string;
|
||||
abstract public function getTemplateName(): string;
|
||||
|
||||
protected final function getView() {
|
||||
return $this->getTemplateName();
|
||||
|
@ -19,7 +19,7 @@ class ForgotPasswordEmail extends TemplateWithRenderer {
|
||||
return 'Ely.by Account forgot password';
|
||||
}
|
||||
|
||||
protected function getTemplateName(): string {
|
||||
public function getTemplateName(): string {
|
||||
return 'forgotPassword';
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class RegistrationEmail extends TemplateWithRenderer {
|
||||
return 'Ely.by Account registration';
|
||||
}
|
||||
|
||||
protected function getTemplateName(): string {
|
||||
public function getTemplateName(): string {
|
||||
return 'register';
|
||||
}
|
||||
|
||||
|
18
tests/codeception/common/unit/emails/EmailHelperTest.php
Normal file
18
tests/codeception/common/unit/emails/EmailHelperTest.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace tests\codeception\common\unit\emails;
|
||||
|
||||
use common\emails\EmailHelper;
|
||||
use common\models\Account;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
|
||||
class EmailHelperTest extends TestCase {
|
||||
|
||||
public function testBuildTo() {
|
||||
/** @var Account|\Mockery\MockInterface $account */
|
||||
$account = mock(Account::class)->makePartial();
|
||||
$account->username = 'mock-username';
|
||||
$account->email = 'mock@ely.by';
|
||||
$this->assertEquals(['mock@ely.by' => 'mock-username'], EmailHelper::buildTo($account));
|
||||
}
|
||||
|
||||
}
|
47
tests/codeception/common/unit/emails/TemplateTest.php
Normal file
47
tests/codeception/common/unit/emails/TemplateTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace tests\codeception\common\unit\emails;
|
||||
|
||||
use common\emails\Template;
|
||||
use tests\codeception\common\_support\ProtectedCaller;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
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();
|
||||
$this->assertEquals('find-me', $template->getTo());
|
||||
$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();
|
||||
$this->assertEquals(['find-me' => 'Ely.by Accounts'], $template->getFrom());
|
||||
}
|
||||
|
||||
public function testGetParams() {
|
||||
/** @var Template|\Mockery\MockInterface $template */
|
||||
$template = mock(Template::class)->makePartial();
|
||||
$this->assertEquals([], $template->getParams());
|
||||
}
|
||||
|
||||
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);
|
||||
$this->assertEquals(['to@ely.by' => 'To'], $message->getTo());
|
||||
$this->assertEquals(['from@ely.by' => 'Ely.by Accounts'], $message->getFrom());
|
||||
$this->assertEquals('mock-subject', $message->getSubject());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace tests\codeception\common\unit\emails;
|
||||
|
||||
use common\components\EmailRenderer;
|
||||
use common\emails\TemplateWithRenderer;
|
||||
use Ely\Email\TemplateBuilder;
|
||||
use tests\codeception\common\_support\ProtectedCaller;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
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();
|
||||
$this->assertEquals('mock-to', $template->getTo());
|
||||
$this->assertEquals('mock-locale', $template->getLocale());
|
||||
$this->assertInstanceOf(MailerInterface::class, $template->getMailer());
|
||||
$this->assertInstanceOf(EmailRenderer::class, $template->getEmailRenderer());
|
||||
}
|
||||
|
||||
public function testCreateMessage() {
|
||||
/** @var TemplateBuilder|\Mockery\MockInterface $templateBuilder */
|
||||
$templateBuilder = mock(TemplateBuilder::class)->makePartial();
|
||||
$templateBuilder->shouldReceive('render')->andReturn('mock-html');
|
||||
|
||||
/** @var EmailRenderer|\Mockery\MockInterface $renderer */
|
||||
$renderer = mock(EmailRenderer::class)->makePartial();
|
||||
$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);
|
||||
$this->assertEquals(['to@ely.by' => 'To'], $message->getTo());
|
||||
$this->assertEquals(['from@ely.by' => 'From'], $message->getFrom());
|
||||
$this->assertEquals('mock-subject', $message->getSubject());
|
||||
$this->assertEquals('mock-html', $message->getSwiftMessage()->getBody());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user