7
7
8
8
namespace Magento \Sales \Test \Unit \Block \Adminhtml \Items \Column ;
9
9
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
10
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
11
12
use Magento \Sales \Block \Adminhtml \Items \Column \DefaultColumn ;
12
13
use Magento \Sales \Model \Order \Item ;
@@ -28,43 +29,114 @@ class DefaultColumnTest extends TestCase
28
29
*/
29
30
protected $ itemMock ;
30
31
32
+ /**
33
+ * @var ScopeConfigInterface|MockObject
34
+ */
35
+ protected $ scopeConfigMock ;
36
+
31
37
protected function setUp (): void
32
38
{
33
39
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
40
+ $ this ->scopeConfigMock = $ this ->getMockBuilder (ScopeConfigInterface::class)
41
+ ->disableOriginalConstructor ()
42
+ ->getMockForAbstractClass ();
34
43
$ this ->defaultColumn = $ this ->objectManagerHelper ->getObject (
35
- DefaultColumn::class
44
+ DefaultColumn::class,
45
+ [
46
+ 'scopeConfig ' => $ this ->scopeConfigMock
47
+ ]
36
48
);
37
49
$ this ->itemMock = $ this ->getMockBuilder (Item::class)
38
50
->disableOriginalConstructor ()
39
- ->onlyMethods (['getRowTotal ' , 'getDiscountAmount ' , 'getBaseRowTotal ' , 'getBaseDiscountAmount ' ])
40
51
->getMock ();
41
52
}
42
53
43
- public function testGetTotalAmount ()
54
+ /**
55
+ * Verify the total amount based on the price including tax flag
56
+ *
57
+ * @dataProvider getScopeConfigSalesPriceDataProvider
58
+ * @param string $taxIncl
59
+ * @param float|null $basePriceInclTax
60
+ * @param float $basePrice
61
+ * @param float $expectedResult
62
+ * @return void
63
+ * @throws \ReflectionException
64
+ */
65
+ public function testGetTotalAmount (string $ taxIncl , $ priceInclTax , float $ price , float $ expectedResult ): void
44
66
{
45
- $ rowTotal = 10 ;
46
- $ discountAmount = 2 ;
47
- $ expectedResult = 8 ;
67
+ $ storeId = 1 ;
68
+ $ discountAmount = 15.21 ;
69
+ $ taxAmount = 0.34 ;
48
70
$ this ->itemMock ->expects ($ this ->once ())
49
- ->method ('getRowTotal ' )
50
- ->willReturn ($ rowTotal );
71
+ ->method ('getStoreId ' )
72
+ ->willReturn ($ storeId );
73
+ $ this ->itemMock ->expects ($ this ->any ())
74
+ ->method ('getPriceInclTax ' )
75
+ ->willReturn ($ priceInclTax );
76
+ $ this ->itemMock ->expects ($ this ->any ())
77
+ ->method ('getPrice ' )
78
+ ->willReturn ($ price );
51
79
$ this ->itemMock ->expects ($ this ->once ())
52
80
->method ('getDiscountAmount ' )
53
81
->willReturn ($ discountAmount );
54
- $ this ->assertEquals ($ expectedResult , $ this ->defaultColumn ->getTotalAmount ($ this ->itemMock ));
82
+ $ this ->itemMock ->expects ($ this ->any ())
83
+ ->method ('getTaxAmount ' )
84
+ ->willReturn ($ taxAmount );
85
+ $ this ->scopeConfigMock ->expects ($ this ->atLeastOnce ())
86
+ ->method ('getValue ' )
87
+ ->willReturn ($ taxIncl );
88
+ $ this ->assertEquals ($ expectedResult , round ($ this ->defaultColumn ->getTotalAmount ($ this ->itemMock ), 2 ));
55
89
}
56
90
57
- public function testGetBaseTotalAmount ()
58
- {
59
- $ baseRowTotal = 10 ;
60
- $ baseDiscountAmount = 2 ;
61
- $ expectedResult = 8 ;
91
+ /**
92
+ * Verify the total base amount based on the price including tax flag
93
+ *
94
+ * @dataProvider getScopeConfigSalesPriceDataProvider
95
+ * @param string $taxIncl
96
+ * @param float|null $basePriceInclTax
97
+ * @param float $basePrice
98
+ * @param float $expectedResult
99
+ * @return void
100
+ * @throws \ReflectionException
101
+ */
102
+ public function testGetBaseTotalAmount (
103
+ string $ taxIncl ,
104
+ $ basePriceInclTax ,
105
+ float $ basePrice ,
106
+ float $ expectedResult
107
+ ): void {
108
+ $ storeId = 1 ;
109
+ $ baseDiscountAmount = 15.21 ;
110
+ $ baseTaxAmount = 0.34 ;
62
111
$ this ->itemMock ->expects ($ this ->once ())
63
- ->method ('getBaseRowTotal ' )
64
- ->willReturn ($ baseRowTotal );
112
+ ->method ('getStoreId ' )
113
+ ->willReturn ($ storeId );
114
+ $ this ->itemMock ->expects ($ this ->any ())
115
+ ->method ('getBasePriceInclTax ' )
116
+ ->willReturn ($ basePriceInclTax );
117
+ $ this ->itemMock ->expects ($ this ->any ())
118
+ ->method ('getBasePrice ' )
119
+ ->willReturn ($ basePrice );
65
120
$ this ->itemMock ->expects ($ this ->once ())
66
121
->method ('getBaseDiscountAmount ' )
67
122
->willReturn ($ baseDiscountAmount );
68
- $ this ->assertEquals ($ expectedResult , $ this ->defaultColumn ->getBaseTotalAmount ($ this ->itemMock ));
123
+ $ this ->itemMock ->expects ($ this ->any ())
124
+ ->method ('getBaseTaxAmount ' )
125
+ ->willReturn ($ baseTaxAmount );
126
+ $ this ->scopeConfigMock ->expects ($ this ->atLeastOnce ())
127
+ ->method ('getValue ' )
128
+ ->willReturn ($ taxIncl );
129
+ $ this ->assertEquals ($ expectedResult , round ($ this ->defaultColumn ->getBaseTotalAmount ($ this ->itemMock ), 2 ));
130
+ }
131
+
132
+ /**
133
+ * @return array
134
+ */
135
+ public function getScopeConfigSalesPriceDataProvider (): array
136
+ {
137
+ return [
138
+ ['2 ' , 16.9 , 13.52 , 1.35 ],
139
+ ['1 ' , null , 16.9 , 1.69 ],
140
+ ];
69
141
}
70
142
}
0 commit comments