@@ -12,10 +12,124 @@ class ShippingTest extends \PHPUnit_Framework_TestCase
12
12
*/
13
13
protected $ shippingModel ;
14
14
15
+ /** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject */
16
+ protected $ quote ;
17
+
18
+ /** @var \Magento\Quote\Model\Quote\Address\Total|\PHPUnit_Framework_MockObject_MockObject */
19
+ protected $ total ;
20
+
21
+ /** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface|\PHPUnit_Framework_MockObject_MockObject */
22
+ protected $ shippingAssignment ;
23
+
24
+ /** @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject */
25
+ protected $ address ;
26
+
27
+ /** @var \Magento\Quote\Api\Data\ShippingInterface|\PHPUnit_Framework_MockObject_MockObject */
28
+ protected $ shipping ;
29
+
30
+ /** @var \Magento\Quote\Model\Quote\Address\FreeShippingInterface|\PHPUnit_Framework_MockObject_MockObject */
31
+ protected $ freeShipping ;
32
+
33
+ /** @var \Magento\Quote\Api\Data\CartItemInterface|\PHPUnit_Framework_MockObject_MockObject */
34
+ protected $ cartItem ;
35
+
36
+ /** @var \Magento\Quote\Model\Quote\Address\Rate|\PHPUnit_Framework_MockObject_MockObject */
37
+ protected $ rate ;
38
+
39
+ /** @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */
40
+ protected $ store ;
41
+
42
+ /** @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject */
43
+ protected $ priceCurrency ;
44
+
15
45
protected function setUp ()
16
46
{
47
+ $ this ->freeShipping = $ this ->getMockForAbstractClass (
48
+ 'Magento\Quote\Model\Quote\Address\FreeShippingInterface ' ,
49
+ [],
50
+ '' ,
51
+ false
52
+ );
53
+ $ this ->priceCurrency = $ this ->getMockForAbstractClass (
54
+ 'Magento\Framework\Pricing\PriceCurrencyInterface ' ,
55
+ [],
56
+ '' ,
57
+ false
58
+ );
17
59
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
18
- $ this ->shippingModel = $ objectManager ->getObject ('Magento\Quote\Model\Quote\Address\Total\Shipping ' );
60
+ $ this ->shippingModel = $ objectManager ->getObject (
61
+ 'Magento\Quote\Model\Quote\Address\Total\Shipping ' ,
62
+ [
63
+ 'freeShipping ' => $ this ->freeShipping ,
64
+ 'priceCurrency ' => $ this ->priceCurrency ,
65
+ ]
66
+ );
67
+
68
+ $ this ->quote = $ this ->getMock ('Magento\Quote\Model\Quote ' , [], [], '' , false );
69
+ $ this ->total = $ this ->getMock (
70
+ 'Magento\Quote\Model\Quote\Address\Total ' ,
71
+ [
72
+ 'setShippingAmount ' ,
73
+ 'setBaseTotalAmount ' ,
74
+ 'setTotalAmount ' ,
75
+ 'setShippingDescription ' ,
76
+ ],
77
+ [],
78
+ '' ,
79
+ false
80
+ );
81
+ $ this ->shippingAssignment = $ this ->getMockForAbstractClass (
82
+ 'Magento\Quote\Api\Data\ShippingAssignmentInterface ' ,
83
+ [],
84
+ '' ,
85
+ false
86
+ );
87
+ $ this ->address = $ this ->getMock (
88
+ 'Magento\Quote\Model\Quote\Address ' ,
89
+ [
90
+ 'setWeight ' ,
91
+ 'setFreeMethodWeight ' ,
92
+ 'getWeight ' ,
93
+ 'getFreeMethodWeight ' ,
94
+ 'setFreeShipping ' ,
95
+ 'setItemQty ' ,
96
+ 'collectShippingRates ' ,
97
+ 'getAllShippingRates ' ,
98
+ 'setShippingDescription ' ,
99
+ 'getShippingDescription ' ,
100
+ 'getFreeShipping ' ,
101
+ ],
102
+ [],
103
+ '' ,
104
+ false
105
+ );
106
+ $ this ->shipping = $ this ->getMockForAbstractClass ('Magento\Quote\Api\Data\ShippingInterface ' , [], '' , false );
107
+ $ this ->cartItem = $ this ->getMockForAbstractClass (
108
+ 'Magento\Quote\Api\Data\CartItemInterface ' ,
109
+ [],
110
+ '' ,
111
+ false ,
112
+ false ,
113
+ true ,
114
+ [
115
+ 'getFreeShipping ' ,
116
+ 'getProduct ' ,
117
+ 'getParentItem ' ,
118
+ 'getHasChildren ' ,
119
+ 'isVirtual ' ,
120
+ 'getWeight ' ,
121
+ 'getQty ' ,
122
+ 'setRowWeight ' ,
123
+ ]
124
+ );
125
+ $ this ->rate = $ this ->getMock (
126
+ 'Magento\Quote\Model\Quote\Address\Rate ' ,
127
+ ['getPrice ' , 'getCode ' , 'getCarrierTitle ' , 'getMethodTitle ' ],
128
+ [],
129
+ '' ,
130
+ false
131
+ );
132
+ $ this ->store = $ this ->getMock ('Magento\Store\Model\Store ' , [], [], '' , false );
19
133
}
20
134
21
135
public function testFetch ()
@@ -41,4 +155,100 @@ public function testFetch()
41
155
$ totalMock ->expects ($ this ->once ())->method ('getShippingDescription ' )->willReturn ($ shippingDescription );
42
156
$ this ->assertEquals ($ expectedResult , $ this ->shippingModel ->fetch ($ quoteMock , $ totalMock ));
43
157
}
158
+
159
+ public function testCollect ()
160
+ {
161
+ $ this ->shippingAssignment ->expects ($ this ->exactly (3 ))
162
+ ->method ('getShipping ' )
163
+ ->willReturn ($ this ->shipping );
164
+ $ this ->shipping ->expects ($ this ->exactly (2 ))
165
+ ->method ('getAddress ' )
166
+ ->willReturn ($ this ->address );
167
+ $ this ->shipping ->expects ($ this ->once ())
168
+ ->method ('getMethod ' )
169
+ ->willReturn ('flatrate ' );
170
+ $ this ->shippingAssignment ->expects ($ this ->atLeastOnce ())
171
+ ->method ('getItems ' )
172
+ ->willReturn ([$ this ->cartItem ]);
173
+ $ this ->freeShipping ->expects ($ this ->once ())
174
+ ->method ('isFreeShipping ' )
175
+ ->with ($ this ->quote , [$ this ->cartItem ])
176
+ ->willReturn (true );
177
+ $ this ->address ->expects ($ this ->once ())
178
+ ->method ('setFreeShipping ' )
179
+ ->with (true );
180
+ $ this ->total ->expects ($ this ->atLeastOnce ())
181
+ ->method ('setTotalAmount ' );
182
+ $ this ->total ->expects ($ this ->atLeastOnce ())
183
+ ->method ('setBaseTotalAmount ' );
184
+ $ this ->cartItem ->expects ($ this ->atLeastOnce ())
185
+ ->method ('getProduct ' )
186
+ ->willReturnSelf ();
187
+ $ this ->cartItem ->expects ($ this ->atLeastOnce ())
188
+ ->method ('isVirtual ' )
189
+ ->willReturn (false );
190
+ $ this ->cartItem ->expects ($ this ->once ())
191
+ ->method ('getParentItem ' )
192
+ ->willReturn (false );
193
+ $ this ->cartItem ->expects ($ this ->once ())
194
+ ->method ('getHasChildren ' )
195
+ ->willReturn (false );
196
+ $ this ->cartItem ->expects ($ this ->once ())
197
+ ->method ('getWeight ' )
198
+ ->willReturn (2 );
199
+ $ this ->cartItem ->expects ($ this ->atLeastOnce ())
200
+ ->method ('getQty ' )
201
+ ->willReturn (2 );
202
+ $ this ->address ->expects ($ this ->once ())
203
+ ->method ('getFreeShipping ' )
204
+ ->willReturn (true );
205
+ $ this ->cartItem ->expects ($ this ->once ())
206
+ ->method ('setRowWeight ' )
207
+ ->with (0 );
208
+ $ this ->address ->expects ($ this ->once ())
209
+ ->method ('setItemQty ' )
210
+ ->with (2 );
211
+ $ this ->address ->expects ($ this ->atLeastOnce ())
212
+ ->method ('setWeight ' );
213
+ $ this ->address ->expects ($ this ->atLeastOnce ())
214
+ ->method ('setFreeMethodWeight ' );
215
+ $ this ->address ->expects ($ this ->once ())
216
+ ->method ('collectShippingRates ' );
217
+ $ this ->address ->expects ($ this ->once ())
218
+ ->method ('getAllShippingRates ' )
219
+ ->willReturn ([$ this ->rate ]);
220
+ $ this ->rate ->expects ($ this ->once ())
221
+ ->method ('getCode ' )
222
+ ->willReturn ('flatrate ' );
223
+ $ this ->quote ->expects ($ this ->once ())
224
+ ->method ('getStore ' )
225
+ ->willReturn ($ this ->store );
226
+ $ this ->rate ->expects ($ this ->atLeastOnce ())
227
+ ->method ('getPrice ' )
228
+ ->willReturn (5 );
229
+ $ this ->priceCurrency ->expects ($ this ->once ())
230
+ ->method ('convert ' )
231
+ ->with (5 , $ this ->store )
232
+ ->willReturn (5 );
233
+ $ this ->total ->expects ($ this ->once ())
234
+ ->method ('setShippingAmount ' )
235
+ ->with (5 );
236
+ $ this ->rate ->expects ($ this ->once ())
237
+ ->method ('getCarrierTitle ' )
238
+ ->willReturn ('Carrier title ' );
239
+ $ this ->rate ->expects ($ this ->once ())
240
+ ->method ('getMethodTitle ' )
241
+ ->willReturn ('Method title ' );
242
+ $ this ->address ->expects ($ this ->once ())
243
+ ->method ('setShippingDescription ' )
244
+ ->with ('Carrier title - Method title ' );
245
+ $ this ->address ->expects ($ this ->once ())
246
+ ->method ('getShippingDescription ' )
247
+ ->willReturn ('Carrier title - Method title ' );
248
+ $ this ->total ->expects ($ this ->once ())
249
+ ->method ('setShippingDescription ' )
250
+ ->with ('Carrier title - Method title ' );
251
+
252
+ $ this ->shippingModel ->collect ($ this ->quote , $ this ->shippingAssignment , $ this ->total );
253
+ }
44
254
}
0 commit comments