72 $objectManagerHelper =
new ObjectManagerHelper($this);
73 $this->shipmentLoader = $this->getMockBuilder(
74 \
Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::class
76 ->disableOriginalConstructor()
77 ->setMethods([
'setShipmentId',
'setOrderId',
'setShipment',
'setTracking',
'load'])
79 $this->context = $this->createPartialMock(
90 $this->response = $this->createPartialMock(
91 \
Magento\Framework\
App\ResponseInterface::class,
92 [
'setRedirect',
'sendResponse',
'setBody']
94 $this->request = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
95 ->disableOriginalConstructor()->getMock();
96 $this->objectManager = $this->createPartialMock(
100 $this->view = $this->createMock(\
Magento\Framework\
App\ViewInterface::class);
101 $this->resultPageMock = $this->getMockBuilder(\
Magento\Framework\View\Result\Page::class)
102 ->disableOriginalConstructor()
104 $this->pageConfigMock = $this->getMockBuilder(\
Magento\Framework\View\Page\Config::class)
105 ->disableOriginalConstructor()
107 $this->pageTitleMock = $this->getMockBuilder(\
Magento\Framework\View\Page\Title::class)
108 ->disableOriginalConstructor()
110 $this->context->expects($this->once())
111 ->method(
'getRequest')
112 ->will($this->returnValue($this->request));
113 $this->context->expects($this->once())
114 ->method(
'getResponse')
115 ->will($this->returnValue($this->response));
116 $this->context->expects($this->once())
117 ->method(
'getObjectManager')
118 ->will($this->returnValue($this->objectManager));
119 $this->context->expects($this->once())
121 ->will($this->returnValue($this->view));
122 $this->controller = $objectManagerHelper->getObject(
123 \
Magento\Shipping\Controller\Adminhtml\Order\Shipment\AddTrack::class,
125 'context' => $this->context,
126 'shipmentLoader' => $this->shipmentLoader,
127 'request' => $this->request,
128 'response' => $this->response,
129 'view' => $this->view
139 $carrier =
'carrier';
142 $shipmentId = 1000012;
145 $shipmentData = [
'items' => [],
'send_email' =>
''];
147 \
Magento\Sales\Model\Order\Shipment::class,
148 [
'addTrack',
'__wakeup',
'save']
150 $this->request->expects($this->any())
153 $this->returnValueMap(
155 [
'order_id',
null, $orderId], [
'shipment_id',
null, $shipmentId],
156 [
'shipment',
null, $shipmentData], [
'tracking',
null, $tracking],
160 $this->request->expects($this->any())
163 $this->returnValueMap(
165 [
'carrier',
null, $carrier],
171 $this->shipmentLoader->expects($this->any())
172 ->method(
'setShipmentId')
174 $this->shipmentLoader->expects($this->any())
175 ->method(
'setOrderId')
177 $this->shipmentLoader->expects($this->any())
178 ->method(
'setShipment')
179 ->with($shipmentData);
180 $this->shipmentLoader->expects($this->any())
181 ->method(
'setTracking')
183 $this->shipmentLoader->expects($this->once())
186 $track = $this->getMockBuilder(\
Magento\Sales\Model\Order\Shipment\Track::class)
187 ->disableOriginalConstructor()
188 ->setMethods([
'__wakeup',
'setNumber',
'setCarrierCode',
'setTitle'])
190 $this->objectManager->expects($this->atLeastOnce())
192 ->with(\
Magento\Sales\Model\Order\Shipment\Track::class)
193 ->will($this->returnValue(
$track));
194 $track->expects($this->once())
195 ->method(
'setNumber')
197 ->will($this->returnSelf());
198 $track->expects($this->once())
199 ->method(
'setCarrierCode')
201 ->will($this->returnSelf());
202 $track->expects($this->once())
205 ->will($this->returnSelf());
206 $this->view->expects($this->once())
207 ->method(
'loadLayout')
208 ->will($this->returnSelf());
209 $layout = $this->createMock(\
Magento\Framework\View\LayoutInterface::class);
210 $menuBlock = $this->createPartialMock(\
Magento\Framework\View\Element\BlockInterface::class, [
'toHtml']);
211 $html =
'html string';
212 $this->view->expects($this->once())
213 ->method(
'getLayout')
214 ->will($this->returnValue($layout));
215 $layout->expects($this->once())
217 ->with(
'shipment_tracking')
218 ->will($this->returnValue($menuBlock));
219 $menuBlock->expects($this->once())
221 ->will($this->returnValue($html));
224 ->with($this->equalTo(
$track))
225 ->will($this->returnSelf());
228 ->will($this->returnSelf());
229 $this->view->expects($this->any())
231 ->willReturn($this->resultPageMock);
232 $this->resultPageMock->expects($this->any())
233 ->method(
'getConfig')
234 ->willReturn($this->pageConfigMock);
235 $this->pageConfigMock->expects($this->any())
237 ->willReturn($this->pageTitleMock);
238 $this->response->expects($this->once())
241 $this->assertNull($this->controller->execute());
foreach($order->getItems() as $orderItem) $shipment