Exemplo n.º 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute()
 {
     $carrier = 'carrier';
     $number = 'number';
     $title = 'title';
     $shipmentId = 1000012;
     $orderId = 10003;
     $tracking = [];
     $shipmentData = ['items' => [], 'send_email' => ''];
     $shipment = $this->getMock(
         'Magento\Sales\Model\Order\Shipment',
         ['addTrack', '__wakeup', 'save'],
         [],
         '',
         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->request->expects($this->any())
         ->method('getPost')
         ->will(
             $this->returnValueMap(
                 [
                     ['carrier', null, $carrier],
                     ['number', null, $number],
                     ['title', null, $title],
                 ]
             )
         );
     $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));
     $track = $this->getMockBuilder('Magento\Sales\Model\Order\Shipment\Track')
         ->disableOriginalConstructor()
         ->setMethods(['__wakeup', 'setNumber', 'setCarrierCode', 'setTitle'])
         ->getMock();
     $this->objectManager->expects($this->atLeastOnce())
         ->method('create')
         ->with('Magento\Sales\Model\Order\Shipment\Track')
         ->will($this->returnValue($track));
     $track->expects($this->once())
         ->method('setNumber')
         ->with($number)
         ->will($this->returnSelf());
     $track->expects($this->once())
         ->method('setCarrierCode')
         ->with($carrier)
         ->will($this->returnSelf());
     $track->expects($this->once())
         ->method('setTitle')
         ->with($title)
         ->will($this->returnSelf());
     $this->view->expects($this->once())
         ->method('loadLayout')
         ->will($this->returnSelf());
     $layout = $this->getMock('Magento\Framework\View\Layout\Element\Layout', ['getBlock'], [], '', false);
     $menuBlock = $this->getMock('Magento\Framework\View\Element\BlockInterface', ['toHtml'], [], '', false);
     $html = 'html string';
     $this->view->expects($this->once())
         ->method('getLayout')
         ->will($this->returnValue($layout));
     $layout->expects($this->once())
         ->method('getBlock')
         ->with('shipment_tracking')
         ->will($this->returnValue($menuBlock));
     $menuBlock->expects($this->once())
         ->method('toHtml')
         ->will($this->returnValue($html));
     $shipment->expects($this->once())
         ->method('addTrack')
         ->with($this->equalTo($track))
         ->will($this->returnSelf());
     $shipment->expects($this->any())
         ->method('save')
         ->will($this->returnSelf());
     $this->view->expects($this->any())
         ->method('getPage')
         ->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->any())
         ->method('getConfig')
         ->willReturn($this->pageConfigMock);
     $this->pageConfigMock->expects($this->any())
         ->method('getTitle')
         ->willReturn($this->pageTitleMock);
     $this->response->expects($this->once())
         ->method('setBody')
         ->with($html);
     $this->assertNull($this->controller->executeInternal());
 }