Skip to content

Commit 3ff6de7

Browse files
ENGCOM-6206: [Email] Unit Test to cover Sender and Template Type Renderer #25361
2 parents 537960e + d4fe2a4 commit 3ff6de7

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Email\Test\Unit\Block\Adminhtml\Template\Render;
10+
11+
use Magento\Email\Block\Adminhtml\Template\Grid\Renderer\Sender;
12+
use Magento\Framework\DataObject;
13+
14+
/**
15+
* Class \Magento\Email\Test\Unit\Block\Adminhtml\Template\Render\SenderTest
16+
*/
17+
class SenderTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var \PHPUnit_Framework_MockObject_MockObject|Sender
21+
*/
22+
protected $block;
23+
24+
/**
25+
* Setup environment
26+
*/
27+
protected function setUp()
28+
{
29+
$this->block = $this->getMockBuilder(Sender::class)
30+
->disableOriginalConstructor()
31+
->setMethods(['escapeHtml'])
32+
->getMock();
33+
}
34+
35+
/**
36+
* Test render() with sender name and sender email are not empty
37+
*/
38+
public function testRenderWithSenderNameAndEmail()
39+
{
40+
$templateSenderEmail = 'test';
41+
$this->block->expects($this->any())->method('escapeHtml')->with($templateSenderEmail)
42+
->willReturn('test');
43+
$actualResult = $this->block->render(
44+
new DataObject(
45+
[
46+
'template_sender_name' => 'test',
47+
'template_sender_email' => '[email protected]'
48+
]
49+
)
50+
);
51+
$this->assertEquals('test [[email protected]]', $actualResult);
52+
}
53+
54+
/**
55+
* Test render() with sender name and sender email are empty
56+
*/
57+
public function testRenderWithNoSenderNameAndEmail()
58+
{
59+
$templateSenderEmail = '';
60+
$this->block->expects($this->any())->method('escapeHtml')->with($templateSenderEmail)
61+
->willReturn('');
62+
$actualResult = $this->block->render(
63+
new DataObject(
64+
[
65+
'template_sender_name' => '',
66+
'template_sender_email' => ''
67+
]
68+
)
69+
);
70+
$this->assertEquals('---', $actualResult);
71+
}
72+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Email\Test\Unit\Block\Adminhtml\Template\Render;
10+
11+
use Magento\Email\Block\Adminhtml\Template\Grid\Renderer\Type;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\Phrase;
14+
15+
/**
16+
* Class \Magento\Email\Test\Unit\Block\Adminhtml\Template\Render\TypeTest
17+
*/
18+
class TypeTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject|Type
22+
*/
23+
protected $block;
24+
25+
/**
26+
* Setup environment
27+
*/
28+
protected function setUp()
29+
{
30+
$this->block = $this->getMockBuilder(Type::class)
31+
->disableOriginalConstructor()
32+
->setMethods(['__'])
33+
->getMock();
34+
}
35+
36+
/**
37+
* Test render() with supported template Text type
38+
*/
39+
public function testRenderWithSupportedTemplateTextType()
40+
{
41+
$testCase = [
42+
'dataset' => [
43+
'template_type' => '1'
44+
],
45+
'expectedResult' => 'Text'
46+
];
47+
$this->executeTestCase($testCase);
48+
}
49+
50+
/**
51+
* Test render() with supported template HTML type
52+
*/
53+
public function testRenderWithSupportedTemplateHtmlType()
54+
{
55+
$testCase = [
56+
'dataset' => [
57+
'template_type' => '2'
58+
],
59+
'expectedResult' => 'HTML'
60+
];
61+
$this->executeTestCase($testCase);
62+
}
63+
64+
/**
65+
* Test render() with unsupported template type
66+
*/
67+
public function testRenderWithUnsupportedTemplateType()
68+
{
69+
$testCase = [
70+
'dataset' => [
71+
'template_type' => '5'
72+
],
73+
'expectedResult' => 'Unknown'
74+
];
75+
$this->executeTestCase($testCase);
76+
}
77+
78+
/**
79+
* Execute Test case
80+
*
81+
* @param array $testCase
82+
*/
83+
public function executeTestCase($testCase)
84+
{
85+
$actualResult = $this->block->render(
86+
new DataObject(
87+
[
88+
'template_type' => $testCase['dataset']['template_type'],
89+
]
90+
)
91+
);
92+
$this->assertEquals(new Phrase($testCase['expectedResult']), $actualResult);
93+
}
94+
}

0 commit comments

Comments
 (0)