Skip to content

Commit 56bf55e

Browse files
committed
[Contact] covered Model Config by Unit Test
1 parent e8c2526 commit 56bf55e

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\Contact\Test\Unit\Model;
11+
12+
use Magento\Contact\Model\Config;
13+
use PHPUnit\Framework\TestCase;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
16+
use Magento\Store\Model\ScopeInterface;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
18+
19+
/**
20+
* Unit test for Magento\Contact\Model\Config
21+
*/
22+
class ConfigTest extends TestCase
23+
{
24+
/**
25+
* @var Config
26+
*/
27+
private $model;
28+
29+
/**
30+
* @var ScopeConfigInterface|MockObject
31+
*/
32+
private $scopeConfigMock;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp(): void
38+
{
39+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
40+
->setMethods(['getValue', 'isSetFlag'])
41+
->disableOriginalConstructor()
42+
->getMockForAbstractClass();
43+
44+
$objectManager = new ObjectManagerHelper($this);
45+
$this->model = $objectManager->getObject(
46+
Config::class,
47+
[
48+
'scopeConfig' => $this->scopeConfigMock
49+
]
50+
);
51+
}
52+
53+
/**
54+
* Test isEnabled()
55+
*
56+
* @return void
57+
*/
58+
public function testIsEnabled(): void
59+
{
60+
$this->scopeConfigMock->expects($this->once())
61+
->method('isSetFlag')
62+
->with(config::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE)
63+
->willReturn(true);
64+
65+
$this->assertTrue(true, $this->model->isEnabled());
66+
}
67+
68+
/**
69+
* Test isNotEnabled()
70+
*
71+
* @return void
72+
*/
73+
public function testIsNotEnabled(): void
74+
{
75+
$this->scopeConfigMock->expects($this->once())
76+
->method('isSetFlag')
77+
->with(config::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE)
78+
->willReturn(false);
79+
80+
$this->assertFalse(false, $this->model->isEnabled());
81+
}
82+
83+
/**
84+
* Test emailTemplate()
85+
*
86+
* @return void
87+
*/
88+
public function testEmailTemplate(): void
89+
{
90+
$this->scopeConfigMock->expects($this->once())
91+
->method('getValue')
92+
->with(config::XML_PATH_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE)
93+
->willReturn('contact_email_email_template');
94+
95+
$this->assertEquals('contact_email_email_template', $this->model->emailTemplate());
96+
}
97+
98+
/**
99+
* Test emailSender()
100+
*
101+
* @return void
102+
*/
103+
public function testEmailSender(): void
104+
{
105+
$this->scopeConfigMock->expects($this->once())
106+
->method('getValue')
107+
->with(config::XML_PATH_EMAIL_SENDER, ScopeInterface::SCOPE_STORE)
108+
->willReturn('custom2');
109+
110+
$this->assertEquals('custom2', $this->model->emailSender());
111+
}
112+
113+
/**
114+
* Test emailRecipient()
115+
*
116+
* @return void
117+
*/
118+
public function testEmailRecipient(): void
119+
{
120+
$this->scopeConfigMock->expects($this->once())
121+
->method('getValue')
122+
->with(config::XML_PATH_EMAIL_RECIPIENT, ScopeInterface::SCOPE_STORE)
123+
->willReturn('[email protected]');
124+
125+
$this->assertEquals('[email protected]', $this->model->emailRecipient());
126+
}
127+
}

0 commit comments

Comments
 (0)