Skip to content

Commit 1260725

Browse files
author
Oleksandr Karpenko
committed
MAGETWO-44268: Shipping & Handling is not updated during creating order from admin
1 parent 9d2e436 commit 1260725

File tree

1 file changed

+207
-1
lines changed

1 file changed

+207
-1
lines changed

app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/ShippingTest.php

Lines changed: 207 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,123 @@ class ShippingTest extends \PHPUnit_Framework_TestCase
1212
*/
1313
protected $shippingModel;
1414

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+
1545
protected function setUp()
1646
{
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+
);
1759
$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+
],
76+
[],
77+
'',
78+
false
79+
);
80+
$this->shippingAssignment = $this->getMockForAbstractClass(
81+
'Magento\Quote\Api\Data\ShippingAssignmentInterface',
82+
[],
83+
'',
84+
false
85+
);
86+
$this->address = $this->getMock(
87+
'Magento\Quote\Model\Quote\Address',
88+
[
89+
'setWeight',
90+
'setFreeMethodWeight',
91+
'getWeight',
92+
'getFreeMethodWeight',
93+
'setFreeShipping',
94+
'setItemQty',
95+
'collectShippingRates',
96+
'getAllShippingRates',
97+
'getShippingAmount',
98+
'setShippingDescription',
99+
'getFreeShipping',
100+
],
101+
[],
102+
'',
103+
false
104+
);
105+
$this->shipping = $this->getMockForAbstractClass('Magento\Quote\Api\Data\ShippingInterface', [], '', false);
106+
$this->cartItem = $this->getMockForAbstractClass(
107+
'Magento\Quote\Api\Data\CartItemInterface',
108+
[],
109+
'',
110+
false,
111+
false,
112+
true,
113+
[
114+
'getFreeShipping',
115+
'getProduct',
116+
'getParentItem',
117+
'getHasChildren',
118+
'isVirtual',
119+
'getWeight',
120+
'getQty',
121+
'setRowWeight',
122+
]
123+
);
124+
$this->rate = $this->getMock(
125+
'Magento\Quote\Model\Quote\Address\Rate',
126+
['getPrice', 'getCode', 'getCarrierTitle', 'getMethodTitle'],
127+
[],
128+
'',
129+
false
130+
);
131+
$this->store = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
19132
}
20133

21134
public function testFetch()
@@ -41,4 +154,97 @@ public function testFetch()
41154
$totalMock->expects($this->once())->method('getShippingDescription')->willReturn($shippingDescription);
42155
$this->assertEquals($expectedResult, $this->shippingModel->fetch($quoteMock, $totalMock));
43156
}
157+
158+
public function testCollect()
159+
{
160+
$this->shippingAssignment->expects($this->exactly(3))
161+
->method('getShipping')
162+
->willReturn($this->shipping);
163+
$this->shipping->expects($this->exactly(2))
164+
->method('getAddress')
165+
->willReturn($this->address);
166+
$this->shipping->expects($this->once())
167+
->method('getMethod')
168+
->willReturn('flatrate');
169+
$this->shippingAssignment->expects($this->atLeastOnce())
170+
->method('getItems')
171+
->willReturn([$this->cartItem]);
172+
$this->freeShipping->expects($this->once())
173+
->method('isFreeShipping')
174+
->with($this->quote, [$this->cartItem])
175+
->willReturn(true);
176+
$this->address->expects($this->once())
177+
->method('setFreeShipping')
178+
->with(true);
179+
$this->total->expects($this->atLeastOnce())
180+
->method('setTotalAmount');
181+
$this->total->expects($this->atLeastOnce())
182+
->method('setBaseTotalAmount');
183+
$this->cartItem->expects($this->atLeastOnce())
184+
->method('getProduct')
185+
->willReturnSelf();
186+
$this->cartItem->expects($this->atLeastOnce())
187+
->method('isVirtual')
188+
->willReturn(false);
189+
$this->cartItem->expects($this->once())
190+
->method('getParentItem')
191+
->willReturn(false);
192+
$this->cartItem->expects($this->once())
193+
->method('getHasChildren')
194+
->willReturn(false);
195+
$this->cartItem->expects($this->once())
196+
->method('getWeight')
197+
->willReturn(2);
198+
$this->cartItem->expects($this->atLeastOnce())
199+
->method('getQty')
200+
->willReturn(2);
201+
$this->address->expects($this->once())
202+
->method('getFreeShipping')
203+
->willReturn(true);
204+
$this->cartItem->expects($this->once())
205+
->method('setRowWeight')
206+
->with(0);
207+
$this->address->expects($this->once())
208+
->method('setItemQty')
209+
->with(2);
210+
$this->address->expects($this->atLeastOnce())
211+
->method('setWeight');
212+
$this->address->expects($this->atLeastOnce())
213+
->method('setFreeMethodWeight');
214+
$this->address->expects($this->once())
215+
->method('collectShippingRates');
216+
$this->address->expects($this->once())
217+
->method('getAllShippingRates')
218+
->willReturn([$this->rate]);
219+
$this->rate->expects($this->once())
220+
->method('getCode')
221+
->willReturn('flatrate');
222+
$this->quote->expects($this->once())
223+
->method('getStore')
224+
->willReturn($this->store);
225+
$this->rate->expects($this->atLeastOnce())
226+
->method('getPrice')
227+
->willReturn(5);
228+
$this->priceCurrency->expects($this->once())
229+
->method('convert')
230+
->with(5, $this->store)
231+
->willReturn(5);
232+
$this->address->expects($this->once())
233+
->method('getShippingAmount')
234+
->willReturn(5);
235+
$this->total->expects($this->once())
236+
->method('setShippingAmount')
237+
->with(5);
238+
$this->rate->expects($this->once())
239+
->method('getCarrierTitle')
240+
->willReturn('Carrier title');
241+
$this->rate->expects($this->once())
242+
->method('getMethodTitle')
243+
->willReturn('Method title');
244+
$this->address->expects($this->once())
245+
->method('setShippingDescription')
246+
->with('Carrier title - Method title');
247+
248+
$this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total);
249+
}
44250
}

0 commit comments

Comments
 (0)