69 $this->shipmentLoaderMock = $this->createPartialMock(
70 \
Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::class,
71 [
'setOrderId',
'setShipmentId',
'setShipment',
'setTracking',
'load']
73 $this->requestMock = $this->createPartialMock(\
Magento\Framework\
App\Request\Http::class, [
'getParam']);
74 $this->objectManagerMock = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
76 $this->sessionMock = $this->createPartialMock(\
Magento\Backend\Model\Session::class, [
'setIsUrlNotice']);
77 $this->actionFlag = $this->createPartialMock(\
Magento\Framework\
App\ActionFlag::class, [
'get']);
78 $this->shipmentMock = $this->createPartialMock(\
Magento\Sales\Model\Order\Shipment::class, [
'__wakeup']);
79 $this->fileFactoryMock = $this->createPartialMock(
84 $contextMock = $this->createPartialMock(
86 [
'getRequest',
'getObjectManager',
'getResponse',
'getSession',
'getActionFlag']
89 $contextMock->expects($this->any())->method(
'getRequest')->will($this->returnValue($this->requestMock));
90 $contextMock->expects($this->any())
91 ->method(
'getObjectManager')
92 ->will($this->returnValue($this->objectManagerMock));
93 $contextMock->expects($this->any())->method(
'getResponse')->will($this->returnValue($this->responseMock));
94 $contextMock->expects($this->any())->method(
'getSession')->will($this->returnValue($this->sessionMock));
95 $contextMock->expects($this->any())->method(
'getActionFlag')->will($this->returnValue($this->actionFlag));
97 $this->requestMock->expects($this->at(0))
100 ->will($this->returnValue($orderId));
101 $this->requestMock->expects($this->at(1))
103 ->with(
'shipment_id')
104 ->will($this->returnValue($shipmentId));
105 $this->requestMock->expects($this->at(2))
109 $this->requestMock->expects($this->at(3))
112 ->will($this->returnValue($tracking));
113 $this->shipmentLoaderMock->expects($this->once())
114 ->method(
'setOrderId')
116 $this->shipmentLoaderMock->expects($this->once())
117 ->method(
'setShipmentId')
119 $this->shipmentLoaderMock->expects($this->once())
120 ->method(
'setShipment')
122 $this->shipmentLoaderMock->expects($this->once())
123 ->method(
'setTracking')
126 $this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\PrintPackage(
128 $this->shipmentLoaderMock,
129 $this->fileFactoryMock
138 $date =
'9999-99-99_77-77-77';
141 $packagingMock = $this->createPartialMock(\
Magento\Shipping\Model\Order\Pdf\Packaging::class, [
'getPdf']);
142 $pdfMock = $this->createPartialMock(\Zend_Pdf::class, [
'render']);
143 $dateTimeMock = $this->createPartialMock(\
Magento\Framework\Stdlib\DateTime\DateTime::class, [
'date']);
145 $this->shipmentLoaderMock->expects($this->once())
147 ->will($this->returnValue($this->shipmentMock));
148 $this->objectManagerMock->expects($this->once())
150 ->with(\
Magento\Shipping\Model\Order\Pdf\Packaging::class)
151 ->will($this->returnValue($packagingMock));
152 $packagingMock->expects($this->once())
154 ->with($this->shipmentMock)
155 ->will($this->returnValue($pdfMock));
156 $this->objectManagerMock->expects($this->once())
158 ->with(\
Magento\Framework\Stdlib\DateTime\DateTime::class)
159 ->will($this->returnValue($dateTimeMock));
160 $dateTimeMock->expects($this->once())->method(
'date')->with(
'Y-m-d_H-i-s')->will($this->returnValue($date));
161 $pdfMock->expects($this->once())->method(
'render')->will($this->returnValue(
$content));
162 $this->fileFactoryMock->expects($this->once())
165 'packingslip' . $date .
'.pdf',
169 )->will($this->returnValue(
'result-pdf-content'));
171 $this->assertEquals(
'result-pdf-content', $this->controller->execute());
179 $this->shipmentLoaderMock->expects($this->once())
181 ->will($this->returnValue(
false));
182 $this->shipmentLoaderMock->expects($this->once())
184 ->will($this->returnValue(
false));
185 $this->actionFlag->expects($this->once())
187 ->with(
'', \
Magento\Backend\
App\AbstractAction::FLAG_IS_URLS_CHECKED)
188 ->will($this->returnValue(
true));
189 $this->sessionMock->expects($this->once())
190 ->method(
'setIsUrlNotice')
193 $this->assertNull($this->controller->execute());
foreach($order->getItems() as $orderItem) $shipment