Skip to content

Commit 5eed9d3

Browse files
ENGCOM-6484: [Contact] covered Model Config by Unit Test #26057
2 parents a6f4271 + b031485 commit 5eed9d3

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
* @dataProvider isEnabledDataProvider
58+
*/
59+
public function testIsEnabled($isSetFlag, $result): void
60+
{
61+
$this->scopeConfigMock->expects($this->once())
62+
->method('isSetFlag')
63+
->with(config::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE)
64+
->willReturn($isSetFlag);
65+
66+
$this->assertEquals($result, $this->model->isEnabled());
67+
}
68+
69+
/**
70+
* Data provider for isEnabled()
71+
*
72+
* @return array
73+
*/
74+
public function isEnabledDataProvider(): array
75+
{
76+
return [
77+
[true, true],
78+
[false, false]
79+
];
80+
}
81+
82+
/**
83+
* Test emailTemplate()
84+
*
85+
* @return void
86+
*/
87+
public function testEmailTemplate(): void
88+
{
89+
$this->scopeConfigMock->expects($this->once())
90+
->method('getValue')
91+
->with(config::XML_PATH_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE)
92+
->willReturn('contact_email_email_template');
93+
94+
$this->assertEquals('contact_email_email_template', $this->model->emailTemplate());
95+
}
96+
97+
/**
98+
* Test emailSender()
99+
*
100+
* @return void
101+
*/
102+
public function testEmailSender(): void
103+
{
104+
$this->scopeConfigMock->expects($this->once())
105+
->method('getValue')
106+
->with(config::XML_PATH_EMAIL_SENDER, ScopeInterface::SCOPE_STORE)
107+
->willReturn('custom2');
108+
109+
$this->assertEquals('custom2', $this->model->emailSender());
110+
}
111+
112+
/**
113+
* Test emailRecipient()
114+
*
115+
* @return void
116+
*/
117+
public function testEmailRecipient(): void
118+
{
119+
$this->scopeConfigMock->expects($this->once())
120+
->method('getValue')
121+
->with(config::XML_PATH_EMAIL_RECIPIENT, ScopeInterface::SCOPE_STORE)
122+
->willReturn('hello@example.com');
123+
124+
$this->assertEquals('hello@example.com', $this->model->emailRecipient());
125+
}
126+
}

0 commit comments

Comments
 (0)