Skip to content

Commit 94538b9

Browse files
authored
ENGCOM-6868: Unit Test for \Magento\Directory\Block\Adminhtml\Frontend\Currency\Base #26816
2 parents ee5d56a + 757dfeb commit 94538b9

File tree

1 file changed

+110
-0
lines changed
  • app/code/Magento/Directory/Test/Unit/Block/Adminhtml/Frontend/Currency

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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\Directory\Test\Unit\Block\Adminhtml\Frontend\Currency;
10+
11+
use Magento\Directory\Block\Adminhtml\Frontend\Currency\Base;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\Data\Form\Element\AbstractElement;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
16+
use Magento\Store\Model\Store;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Unit test for \Magento\Directory\Block\Adminhtml\Frontend\Currency\Base
22+
*/
23+
class BaseTest extends TestCase
24+
{
25+
const STUB_WEBSITE_PARAM = 'website';
26+
27+
/**
28+
* @var AbstractElement|MockObject
29+
*/
30+
private $elementMock;
31+
32+
/**
33+
* @var RequestInterface|MockObject
34+
*/
35+
private $requestMock;
36+
37+
/**
38+
* @var ScopeConfigInterface|MockObject
39+
*/
40+
private $scopeConfigMock;
41+
42+
/**
43+
* @var Base
44+
*/
45+
private $baseCurrency;
46+
47+
/**
48+
* @inheritDoc
49+
*/
50+
protected function setUp()
51+
{
52+
$this->elementMock = $this->createMock(AbstractElement::class);
53+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
54+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
55+
->disableOriginalConstructor()
56+
->setMethods(['getParam'])
57+
->getMockForAbstractClass();
58+
59+
$this->baseCurrency = (new ObjectManagerHelper($this))->getObject(
60+
Base::class,
61+
['_request' => $this->requestMock, '_scopeConfig' => $this->scopeConfigMock]
62+
);
63+
}
64+
65+
/**
66+
* Test case when no Website param provided
67+
*/
68+
public function testRenderWithoutWebsiteParam()
69+
{
70+
$this->requestMock->expects($this->once())
71+
->method('getParam')
72+
->willReturn('');
73+
$this->scopeConfigMock->expects($this->never())->method('getValue');
74+
75+
$result = $this->baseCurrency->render(($this->elementMock));
76+
$this->assertFalse(empty($result), 'Result should not be empty.');
77+
}
78+
79+
/**
80+
* Test case when Website param is provided and Price Scope is set to Global
81+
*/
82+
public function testRenderWhenWebsiteParamSetAndPriceScopeGlobal()
83+
{
84+
$this->requestMock->expects($this->once())
85+
->method('getParam')
86+
->willReturn(self::STUB_WEBSITE_PARAM);
87+
$this->scopeConfigMock->expects($this->once())
88+
->method('getValue')
89+
->willReturn(Store::PRICE_SCOPE_GLOBAL);
90+
91+
$result = $this->baseCurrency->render(($this->elementMock));
92+
$this->assertEquals('', $result, 'Result should be an empty string.');
93+
}
94+
95+
/**
96+
* Test case when Website param is provided and Price Scope is not Global
97+
*/
98+
public function testRenderWhenWebsiteParamSetAndPriceScopeOther()
99+
{
100+
$this->requestMock->expects($this->once())
101+
->method('getParam')
102+
->willReturn(self::STUB_WEBSITE_PARAM);
103+
$this->scopeConfigMock->expects($this->once())
104+
->method('getValue')
105+
->willReturn(Store::PRICE_SCOPE_WEBSITE);
106+
107+
$result = $this->baseCurrency->render(($this->elementMock));
108+
$this->assertFalse(empty($result), 'Result should not be empty.');
109+
}
110+
}

0 commit comments

Comments
 (0)