@@ -40,39 +40,30 @@ public function tearDown()
40
40
*/
41
41
public function testGetAmount ()
42
42
{
43
- $ amount = 10 ;
44
- $ fullAmount = $ amount ;
45
- $ newAmount = 15 ;
46
- $ taxAdjustmentCode = 'tax ' ;
43
+ $ amountInclTax = 10 ;
44
+ $ taxAdjustment = 2 ;
45
+ $ weeeAdjustment = 5 ;
46
+ $ totalAmount = $ amountInclTax + $ weeeAdjustment ;
47
+
47
48
$ weeeAdjustmentCode = 'weee ' ;
48
- $ adjustment = 5 ;
49
+ $ taxAdjustmentCode = ' tax ' ;
49
50
$ expectedAdjustments = [
50
- $ taxAdjustmentCode => $ adjustment ,
51
- $ weeeAdjustmentCode => $ adjustment ,
51
+ $ weeeAdjustmentCode => $ weeeAdjustment ,
52
+ $ taxAdjustmentCode => $ taxAdjustment ,
52
53
];
53
54
54
- $ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
55
+ $ amountBaseMock = $ this ->getMockBuilder ('Magento\Framework\Pricing\Amount\Base ' )
55
56
->disableOriginalConstructor ()
56
- ->setMethods (['getPriceInfo ' , '__wakeup ' ])
57
57
->getMock ();
58
+ $ this ->amountFactoryMock ->expects ($ this ->once ())
59
+ ->method ('create ' )
60
+ ->with ($ this ->equalTo ($ totalAmount ), $ this ->equalTo ($ expectedAdjustments ))
61
+ ->will ($ this ->returnValue ($ amountBaseMock ));
58
62
59
- $ taxAdjustmentMock = $ this ->getMockBuilder ('Magento\Tax\Pricing\Adjustment ' )
63
+ $ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
60
64
->disableOriginalConstructor ()
65
+ ->setMethods (['getPriceInfo ' , '__wakeup ' ])
61
66
->getMock ();
62
- $ taxAdjustmentMock ->expects ($ this ->once ())
63
- ->method ('getAdjustmentCode ' )
64
- ->will ($ this ->returnValue ($ taxAdjustmentCode ));
65
- $ taxAdjustmentMock ->expects ($ this ->once ())
66
- ->method ('isIncludedInBasePrice ' )
67
- ->will ($ this ->returnValue (true ));
68
- $ taxAdjustmentMock ->expects ($ this ->once ())
69
- ->method ('extractAdjustment ' )
70
- ->with ($ this ->equalTo ($ amount ), $ this ->equalTo ($ productMock ))
71
- ->will ($ this ->returnValue ($ adjustment ));
72
- $ taxAdjustmentMock ->expects ($ this ->once ())
73
- ->method ('applyAdjustment ' )
74
- ->with ($ this ->equalTo ($ fullAmount ), $ this ->equalTo ($ productMock ))
75
- ->will ($ this ->returnValue ($ amount ));
76
67
77
68
$ weeeAdjustmentMock = $ this ->getMockBuilder ('Magento\Weee\Pricing\Adjustment ' )
78
69
->disableOriginalConstructor ()
@@ -85,15 +76,33 @@ public function testGetAmount()
85
76
->will ($ this ->returnValue (false ));
86
77
$ weeeAdjustmentMock ->expects ($ this ->once ())
87
78
->method ('isIncludedInDisplayPrice ' )
88
- ->with ($ this ->equalTo ($ productMock ))
89
79
->will ($ this ->returnValue (true ));
90
80
$ weeeAdjustmentMock ->expects ($ this ->once ())
91
81
->method ('applyAdjustment ' )
92
- ->with ($ this ->equalTo ($ fullAmount ), $ this ->equalTo ($ productMock ))
93
- ->will ($ this ->returnValue ($ newAmount ));
82
+ ->with ($ this ->equalTo ($ amountInclTax ), $ this ->equalTo ($ productMock ))
83
+ ->will ($ this ->returnValue ($ weeeAdjustment + $ amountInclTax ));
94
84
95
- $ adjustments = [$ taxAdjustmentMock , $ weeeAdjustmentMock ];
85
+ $ taxAdjustmentMock = $ this ->getMockBuilder ('Magento\Tax\Pricing\Adjustment ' )
86
+ ->disableOriginalConstructor ()
87
+ ->getMock ();
88
+ $ taxAdjustmentMock ->expects ($ this ->once ())
89
+ ->method ('getAdjustmentCode ' )
90
+ ->will ($ this ->returnValue ($ taxAdjustmentCode ));
91
+ $ taxAdjustmentMock ->expects ($ this ->once ())
92
+ ->method ('isIncludedInBasePrice ' )
93
+ ->will ($ this ->returnValue (true ));
94
+ $ taxAdjustmentMock ->expects ($ this ->once ())
95
+ ->method ('extractAdjustment ' )
96
+ ->with ($ this ->equalTo ($ amountInclTax ), $ this ->equalTo ($ productMock ))
97
+ ->will ($ this ->returnValue ($ taxAdjustment ));
98
+ $ taxAdjustmentMock ->expects ($ this ->once ())
99
+ ->method ('applyAdjustment ' )
100
+ ->with ($ this ->equalTo ($ totalAmount ), $ this ->equalTo ($ productMock ))
101
+ ->will ($ this ->returnValue ($ totalAmount ));
102
+ $ taxAdjustmentMock ->expects ($ this ->never ())
103
+ ->method ('isIncludedInDisplayPrice ' );
96
104
105
+ $ adjustments = [$ weeeAdjustmentMock , $ taxAdjustmentMock ];
97
106
$ priceInfoMock = $ this ->getMockBuilder ('\Magento\Framework\Pricing\PriceInfo\Base ' )
98
107
->disableOriginalConstructor ()
99
108
->getMock ();
@@ -105,15 +114,7 @@ public function testGetAmount()
105
114
->method ('getPriceInfo ' )
106
115
->will ($ this ->returnValue ($ priceInfoMock ));
107
116
108
- $ amountBaseMock = $ this ->getMockBuilder ('Magento\Framework\Pricing\Amount\Base ' )
109
- ->disableOriginalConstructor ()
110
- ->getMock ();
111
-
112
- $ this ->amountFactoryMock ->expects ($ this ->once ())
113
- ->method ('create ' )
114
- ->with ($ this ->equalTo ($ newAmount ), $ this ->equalTo ($ expectedAdjustments ))
115
- ->will ($ this ->returnValue ($ amountBaseMock ));
116
- $ result = $ this ->model ->getAmount ($ amount , $ productMock );
117
+ $ result = $ this ->model ->getAmount ($ amountInclTax , $ productMock );
117
118
$ this ->assertInstanceOf ('Magento\Framework\Pricing\Amount\AmountInterface ' , $ result );
118
119
}
119
120
0 commit comments