Skip to content

Commit 3b4dc98

Browse files
ENGCOM-6327: [Tax] Cover Tax CustomerData by Unit Test #25706
2 parents e34c795 + a200b15 commit 3b4dc98

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Tax\Test\Unit\CustomerData;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Tax\CustomerData\CheckoutTotalsJsLayoutDataProvider;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use Magento\Tax\Model\Config as TaxConfig;
14+
15+
/**
16+
* Test class to cover CheckoutTotalsJsLayoutDataProvider
17+
*
18+
* Class \Magento\Tax\Test\Unit\CustomerData\CheckoutTotalsJsLayoutDataProviderTest
19+
*/
20+
class CheckoutTotalsJsLayoutDataProviderTest extends TestCase
21+
{
22+
/**
23+
* @var CheckoutTotalsJsLayoutDataProvider
24+
*/
25+
private $dataProvider;
26+
27+
/**
28+
* @var TaxConfig|PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $taxConfigMock;
31+
32+
/**
33+
* Setup environment for test
34+
*/
35+
protected function setUp()
36+
{
37+
$this->taxConfigMock = $this->createMock(TaxConfig::class);
38+
$objectManager = new ObjectManagerHelper($this);
39+
40+
$this->dataProvider = $objectManager->getObject(
41+
CheckoutTotalsJsLayoutDataProvider::class,
42+
[
43+
'taxConfig' => $this->taxConfigMock
44+
]
45+
);
46+
}
47+
48+
/**
49+
* Test getData() with dataset getDataDataProvider
50+
*
51+
* @param int $displayCartSubtotalInclTax
52+
* @param int $displayCartSubtotalExclTax
53+
* @param array $expected
54+
* @return void
55+
* @dataProvider getDataDataProvider
56+
*/
57+
public function testGetData($displayCartSubtotalInclTax, $displayCartSubtotalExclTax, $expected)
58+
{
59+
$this->taxConfigMock->expects($this->any())->method('displayCartSubtotalInclTax')
60+
->willReturn($displayCartSubtotalInclTax);
61+
$this->taxConfigMock->expects($this->any())->method('displayCartSubtotalExclTax')
62+
->willReturn($displayCartSubtotalExclTax);
63+
64+
$this->assertEquals($expected, $this->dataProvider->getData());
65+
}
66+
67+
/**
68+
* Dataset for test getData()
69+
*
70+
* @return array
71+
*/
72+
public function getDataDataProvider()
73+
{
74+
return [
75+
'Test with settings display cart incl and excl is Yes' => [
76+
'1' ,
77+
'1',
78+
[
79+
'components' => [
80+
'minicart_content' => [
81+
'children' => [
82+
'subtotal.container' => [
83+
'children' => [
84+
'subtotal' => [
85+
'children' => [
86+
'subtotal.totals' => [
87+
'config' => [
88+
'display_cart_subtotal_incl_tax' => 1,
89+
'display_cart_subtotal_excl_tax' => 1
90+
]
91+
],
92+
],
93+
],
94+
],
95+
],
96+
],
97+
],
98+
]
99+
]
100+
],
101+
'Test with settings display cart incl and excl is No' => [
102+
'0' ,
103+
'0',
104+
[
105+
'components' => [
106+
'minicart_content' => [
107+
'children' => [
108+
'subtotal.container' => [
109+
'children' => [
110+
'subtotal' => [
111+
'children' => [
112+
'subtotal.totals' => [
113+
'config' => [
114+
'display_cart_subtotal_incl_tax' => 0,
115+
'display_cart_subtotal_excl_tax' => 0
116+
]
117+
],
118+
],
119+
],
120+
],
121+
],
122+
],
123+
],
124+
]
125+
]
126+
]
127+
];
128+
}
129+
}

0 commit comments

Comments
 (0)