Exemplo n.º 1
0
 public function testExecute()
 {
     $shipmentId = 1000012;
     $orderId = 10003;
     $tracking = [];
     $shipmentData = ['items' => [], 'send_email' => ''];
     $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup'], [], '', false);
     $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCustomerNoteNotify', '__wakeup'], [], '', false);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]]));
     $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId);
     $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData);
     $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking);
     $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment));
     $shipment->expects($this->once())->method('register')->will($this->returnSelf());
     $shipment->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $order->expects($this->once())->method('setCustomerNoteNotify')->with(false);
     $this->labelGenerator->expects($this->any())->method('create')->with($shipment, $this->request)->will($this->returnValue(true));
     $saveTransaction = $this->getMockBuilder('Magento\\Framework\\DB\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock();
     $saveTransaction->expects($this->at(0))->method('addObject')->with($shipment)->will($this->returnSelf());
     $saveTransaction->expects($this->at(1))->method('addObject')->with($order)->will($this->returnSelf());
     $saveTransaction->expects($this->at(2))->method('save');
     $this->session->expects($this->once())->method('getCommentText')->with(true);
     $this->objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\DB\\Transaction')->will($this->returnValue($saveTransaction));
     $this->objectManager->expects($this->once())->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->session));
     $path = 'sales/order/view';
     $arguments = ['order_id' => $orderId];
     $shipment->expects($this->once())->method('getOrderId')->will($this->returnValue($orderId));
     $this->prepareRedirect($path, $arguments);
     $this->saveAction->execute();
     $this->assertEquals($this->response, $this->saveAction->getResponse());
 }
Exemplo n.º 2
0
 /**
  * Run test execute method (fail generate label)
  */
 public function testExecuteLabelGenerateFail()
 {
     $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock));
     $this->labelGenerator->expects($this->once())->method('create')->with($this->shipmentMock, $this->requestMock)->will($this->throwException(new \Magento\Framework\Model\Exception()));
     $this->responseMock->expects($this->once())->method('representJson');
     $this->assertNull($this->controller->execute());
 }
 /**
  * Run test execute method (fail load page from image string)
  */
 public function testExecuteImageStringFail()
 {
     $labelContent = 'Label-content';
     $incrementId = '1000001';
     $loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock));
     $this->shipmentMock->expects($this->once())->method('getShippingLabel')->will($this->returnValue($labelContent));
     $this->shipmentMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($incrementId));
     $this->labelGenerator->expects($this->once())->method('createPdfPageFromImageString')->with($labelContent)->will($this->returnValue(false));
     $this->messageManagerMock->expects($this->at(0))->method('addError')->with(sprintf('We don\'t recognize or support the file extension in this shipment: %s.', $incrementId))->will($this->throwException(new \Exception()));
     $this->messageManagerMock->expects($this->at(1))->method('addError')->with('An error occurred while creating shipping label.')->will($this->returnSelf());
     $this->objectManagerMock->expects($this->once())->method('get')->with('Psr\\Log\\LoggerInterface')->will($this->returnValue($loggerMock));
     $loggerMock->expects($this->once())->method('critical');
     $this->requestMock->expects($this->at(4))->method('getParam')->with('shipment_id')->will($this->returnValue(1));
     $this->redirectSection();
     $this->assertNull($this->controller->execute());
 }