72 $this->requestMock = $this->createPartialMock(\
Magento\Framework\
App\Request\Http::class, [
'getParam']);
73 $this->objectManagerMock = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
74 $this->shipmentTrackMock = $this->createPartialMock(
75 \
Magento\Sales\Model\Order\Shipment\Track::class,
76 [
'load',
'getId',
'delete',
'__wakeup']
78 $this->shipmentMock = $this->createPartialMock(
79 \
Magento\Sales\Model\Order\Shipment::class,
80 [
'getIncrementId',
'__wakeup']
82 $this->viewMock = $this->createPartialMock(
84 [
'loadLayout',
'getLayout',
'getPage']
87 $this->shipmentLoaderMock = $this->createPartialMock(
88 \
Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::class,
89 [
'setOrderId',
'setShipmentId',
'setShipment',
'setTracking',
'load']
91 $this->resultPageMock = $this->getMockBuilder(\
Magento\Framework\View\Result\Page::class)
92 ->disableOriginalConstructor()
94 $this->pageConfigMock = $this->getMockBuilder(\
Magento\Framework\View\Page\Config::class)
95 ->disableOriginalConstructor()
97 $this->pageTitleMock = $this->getMockBuilder(\
Magento\Framework\View\Page\Title::class)
98 ->disableOriginalConstructor()
101 $contextMock = $this->createPartialMock(
103 [
'getRequest',
'getObjectManager',
'getTitle',
'getView',
'getResponse']
106 $this->objectManagerMock->expects($this->once())
108 ->with(\
Magento\Sales\Model\Order\Shipment\Track::class)
109 ->will($this->returnValue($this->shipmentTrackMock));
111 $contextMock->expects($this->any())->method(
'getRequest')->will($this->returnValue($this->requestMock));
112 $contextMock->expects($this->any())
113 ->method(
'getObjectManager')
114 ->will($this->returnValue($this->objectManagerMock));
115 $contextMock->expects($this->any())->method(
'getView')->will($this->returnValue($this->viewMock));
116 $contextMock->expects($this->any())->method(
'getResponse')->will($this->returnValue($this->responseMock));
118 $this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\RemoveTrack(
120 $this->shipmentLoaderMock
123 $this->viewMock->expects($this->any())
125 ->willReturn($this->resultPageMock);
126 $this->resultPageMock->expects($this->any())
127 ->method(
'getConfig')
128 ->willReturn($this->pageConfigMock);
129 $this->pageConfigMock->expects($this->any())
131 ->willReturn($this->pageTitleMock);
147 $this->shipmentTrackMock->expects($this->once())
150 ->will($this->returnSelf());
151 $this->shipmentTrackMock->expects($this->once())
153 ->will($this->returnValue($trackId));
154 $this->requestMock->expects($this->at(0))
157 ->will($this->returnValue($trackId));
158 $this->requestMock->expects($this->at(1))
161 ->will($this->returnValue($orderId));
162 $this->requestMock->expects($this->at(2))
164 ->with(
'shipment_id')
165 ->will($this->returnValue($shipmentId));
166 $this->requestMock->expects($this->at(3))
170 $this->requestMock->expects($this->at(4))
173 ->will($this->returnValue($tracking));
174 $this->shipmentLoaderMock->expects($this->once())->method(
'setOrderId')->with($orderId);
175 $this->shipmentLoaderMock->expects($this->once())->method(
'setShipmentId')->with($shipmentId);
176 $this->shipmentLoaderMock->expects($this->once())->method(
'setShipment')->with(
$shipment);
177 $this->shipmentLoaderMock->expects($this->once())->method(
'setTracking')->with($tracking);
188 $jsonHelper = $this->createPartialMock(\
Magento\Framework\Json\Helper\Data::class, [
'jsonEncode']);
190 ->method(
'jsonEncode')
192 ->will($this->returnValue(
'{json}'));
193 $this->objectManagerMock->expects($this->once())
195 ->with(\
Magento\Framework\Json\Helper\Data::class)
197 $this->responseMock->expects($this->once())
198 ->method(
'representJson')
210 $this->shipmentLoaderMock->expects($this->once())
212 ->will($this->returnValue($this->shipmentMock));
213 $this->shipmentTrackMock->expects($this->once())
215 ->will($this->returnSelf());
217 $layoutMock = $this->createPartialMock(\
Magento\Framework\View\Layout::class, [
'getBlock']);
218 $trackingBlockMock = $this->createPartialMock(
219 \
Magento\Shipping\Block\Adminhtml\Order\Tracking::class,
223 $trackingBlockMock->expects($this->once())
226 $layoutMock->expects($this->once())
228 ->with(
'shipment_tracking')
229 ->will($this->returnValue($trackingBlockMock));
230 $this->viewMock->expects($this->once())->method(
'loadLayout')->will($this->returnSelf());
231 $this->viewMock->expects($this->any())->method(
'getLayout')->will($this->returnValue($layoutMock));
232 $this->responseMock->expects($this->once())
236 $this->assertNull($this->controller->execute());
245 $errors = [
'error' =>
true,
'message' =>
'We can\'t load track with retrieving identifier right now.'];
247 $this->shipmentTrackMock->expects($this->once())
250 ->will($this->returnSelf());
251 $this->shipmentTrackMock->expects($this->once())
253 ->will($this->returnValue($trackId));
256 $this->assertNull($this->controller->execute());
266 'message' =>
'We can\'t initialize shipment for delete tracking number.',
270 $this->shipmentLoaderMock->expects($this->once())
272 ->will($this->returnValue(
null));
275 $this->assertNull($this->controller->execute());
283 $errors = [
'error' =>
true,
'message' =>
'We can\'t delete tracking number.'];
286 $this->shipmentLoaderMock->expects($this->once())
288 ->will($this->returnValue($this->shipmentMock));
289 $this->shipmentTrackMock->expects($this->once())
291 ->will($this->throwException(
new \Exception()));
294 $this->assertNull($this->controller->execute());
testExecuteShipmentLoadFail()
representJson(array $errors)
foreach($order->getItems() as $orderItem) $shipment