Esempio n. 1
0
 /**
  * @param int $configValue
  * @param bool|null $forceSyncMode
  * @param bool|null $customerNoteNotify
  * @param bool|null $emailSendingResult
  * @dataProvider sendDataProvider
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $emailSendingResult)
 {
     $comment = 'comment_test';
     $address = 'address_test';
     $configPath = 'sales_email/general/async_sending';
     $this->shipmentMock->expects($this->once())->method('setSendEmail')->with(true);
     $this->globalConfig->expects($this->once())->method('getValue')->with($configPath)->willReturn($configValue);
     if (!$configValue || $forceSyncMode) {
         $addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
         $this->addressRenderer->expects($this->any())->method('format')->with($addressMock, 'html')->willReturn($address);
         $this->orderMock->expects($this->any())->method('getBillingAddress')->willReturn($addressMock);
         $this->orderMock->expects($this->any())->method('getShippingAddress')->willReturn($addressMock);
         $this->shipmentMock->expects($this->once())->method('getCustomerNoteNotify')->willReturn($customerNoteNotify);
         $this->shipmentMock->expects($this->any())->method('getCustomerNote')->willReturn($comment);
         $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'shipment' => $this->shipmentMock, 'comment' => $customerNoteNotify ? $comment : '', 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $address, 'formattedBillingAddress' => $address]);
         $this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn($emailSendingResult);
         if ($emailSendingResult) {
             $this->senderBuilderFactoryMock->expects($this->once())->method('create')->willReturn($this->senderMock);
             $this->senderMock->expects($this->once())->method('send');
             $this->senderMock->expects($this->once())->method('sendCopyTo');
             $this->shipmentMock->expects($this->once())->method('setEmailSent')->with(true);
             $this->shipmentResourceMock->expects($this->once())->method('saveAttribute')->with($this->shipmentMock, ['send_email', 'email_sent']);
             $this->assertTrue($this->sender->send($this->shipmentMock));
         } else {
             $this->shipmentResourceMock->expects($this->once())->method('saveAttribute')->with($this->shipmentMock, 'send_email');
             $this->assertFalse($this->sender->send($this->shipmentMock));
         }
     } else {
         $this->shipmentResourceMock->expects($this->once())->method('saveAttribute')->with($this->shipmentMock, 'send_email');
         $this->assertFalse($this->sender->send($this->shipmentMock));
     }
 }
Esempio n. 2
0
 public function testProcessRelations()
 {
     $this->shipmentMock->expects($this->once())->method('getId')->willReturn('shipment-id-value');
     $this->shipmentMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->itemMock]);
     $this->shipmentMock->expects($this->exactly(2))->method('getComments')->willReturn([$this->commentMock]);
     $this->shipmentMock->expects($this->exactly(2))->method('getTracks')->willReturn([$this->trackMock]);
     $this->itemMock->expects($this->once())->method('setParentId')->with('shipment-id-value')->willReturnSelf();
     $this->itemResourceMock->expects($this->once())->method('save')->with($this->itemMock)->willReturnSelf();
     $this->commentResourceMock->expects($this->once())->method('save')->with($this->commentMock)->willReturnSelf();
     $this->trackResourceMock->expects($this->once())->method('save')->with($this->trackMock)->willReturnSelf();
     $this->relationProcessor->processRelation($this->shipmentMock);
 }
Esempio n. 3
0
 /**
  * Run shipment mapper test
  *
  * @return void
  */
 public function testInvoke()
 {
     $this->shipmentMock->expects($this->once())->method('getData')->will($this->returnValue(['field-1' => 'value-1']));
     $this->shipmentBuilderMock->expects($this->once())->method('populateWithArray')->with($this->equalTo(['field-1' => 'value-1']))->will($this->returnSelf());
     $this->shipmentMock->expects($this->once())->method('getPackages')->will($this->returnValue([[], []]));
     $this->shipmentBuilderMock->expects($this->once())->method('setPackages')->with($this->equalTo(serialize([[], []])))->will($this->returnSelf());
     $this->shipmentMock->expects($this->once())->method('getItemsCollection')->will($this->returnValue([$this->shipmentItemMock]));
     $this->shipmentItemMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->shipmentItemMock))->will($this->returnValue('item-1'));
     $this->shipmentBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo(['item-1']))->will($this->returnSelf());
     $this->shipmentMock->expects($this->once())->method('getTracksCollection')->will($this->returnValue([$this->shipmentTrackMock]));
     $this->shipmentTrackMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->shipmentTrackMock))->will($this->returnValue('track-1'));
     $this->shipmentBuilderMock->expects($this->once())->method('setTracks')->with($this->equalTo(['track-1']))->will($this->returnSelf());
     $this->shipmentBuilderMock->expects($this->once())->method('create')->will($this->returnValue('data-object-with-shipment'));
     $this->assertEquals('data-object-with-shipment', $this->shipmentMapper->extractDto($this->shipmentMock));
 }
Esempio n. 4
0
 /**
  * Run test execute method
  */
 public function testExecute()
 {
     $orderId = 1;
     $shipmentId = 1;
     $shipment = [];
     $tracking = [];
     $incrementId = '10000001';
     $comeFrom = true;
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
     $this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
     $this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
     $this->requestMock->expects($this->at(4))->method('getParam')->with('come_from')->will($this->returnValue($comeFrom));
     $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
     $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
     $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock));
     $this->shipmentMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($incrementId));
     $menuBlockMock = $this->getMock('Magento\\Backend\\Block\\Menu', ['getParentItems', 'getMenuModel'], [], '', false);
     $menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf());
     $menuBlockMock->expects($this->any())->method('getParentItems')->with('Magento_Sales::sales_order')->will($this->returnValue([]));
     $shipmentBlockMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\View', ['updateBackButtonUrl'], [], '', false);
     $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false);
     $shipmentBlockMock->expects($this->once())->method('updateBackButtonUrl')->with($comeFrom)->will($this->returnSelf());
     $layoutMock->expects($this->at(0))->method('getBlock')->with('sales_shipment_view')->will($this->returnValue($shipmentBlockMock));
     $layoutMock->expects($this->at(1))->method('getBlock')->with('menu')->will($this->returnValue($menuBlockMock));
     $this->viewMock->expects($this->once())->method('loadLayout')->will($this->returnSelf());
     $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock));
     $this->viewMock->expects($this->once())->method('renderLayout')->will($this->returnSelf());
     $this->assertNull($this->controller->execute());
 }
Esempio n. 5
0
 /**
  * Run test execute method (exception save shipment)
  */
 public function testExecuteSaveException()
 {
     $logerMock = $this->getMock('Magento\\Framework\\Logger', ['logException'], [], '', false);
     $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->returnValue(true));
     $this->shipmentMock->expects($this->once())->method('save')->will($this->throwException(new \Exception()));
     $logerMock->expects($this->once())->method('logException');
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Logger')->will($this->returnValue($logerMock));
     $this->responseMock->expects($this->once())->method('representJson');
     $this->assertNull($this->controller->execute());
 }
 /**
  * @param bool $isVirtualOrder
  * @param int $formatCallCount
  * @param string|null $expectedShippingAddress
  * @dataProvider sendVirtualOrderDataProvider
  */
 public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
 {
     $address = 'address_test';
     $this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
     $this->shipmentMock->expects($this->once())->method('setSendEmail')->with(true);
     $this->globalConfig->expects($this->once())->method('getValue')->with('sales_email/general/async_sending')->willReturn(false);
     $addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
     $this->addressRenderer->expects($this->exactly($formatCallCount))->method('format')->with($addressMock, 'html')->willReturn($address);
     $this->stepAddressFormat($addressMock, $isVirtualOrder);
     $this->shipmentMock->expects($this->once())->method('getCustomerNoteNotify')->willReturn(false);
     $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'shipment' => $this->shipmentMock, 'comment' => '', 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $expectedShippingAddress, 'formattedBillingAddress' => $address]);
     $this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn(false);
     $this->shipmentResourceMock->expects($this->once())->method('saveAttribute')->with($this->shipmentMock, 'send_email');
     $this->assertFalse($this->sender->send($this->shipmentMock));
 }
Esempio n. 7
0
    /**
     * Run test execute method
     */
    public function testExecute()
    {
        $orderId = 1;
        $shipmentId = 1;
        $shipment = [];
        $tracking = [];
        $incrementId = '10000001';
        $comeFrom = true;

        $this->loadShipment($orderId, $shipmentId, $shipment, $tracking, $comeFrom, $this->shipmentMock);
        $this->shipmentMock->expects($this->once())->method('getIncrementId')->willReturn($incrementId);
        $this->resultPageFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->resultPageMock);

        $layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock', '__wakeup'], [], '', false);
        $this->resultPageMock->expects($this->once())
            ->method('getLayout')
            ->willReturn($layoutMock);
        $layoutMock->expects($this->once())
            ->method('getBlock')
            ->with('sales_shipment_view')
            ->willReturn($this->blockMock);
        $this->blockMock->expects($this->once())
            ->method('updateBackButtonUrl')
            ->with($comeFrom)
            ->willReturnSelf();

        $this->resultPageMock->expects($this->once())
            ->method('setActiveMenu')
            ->with('Magento_Sales::sales_shipment')
            ->willReturnSelf();
        $this->resultPageMock->expects($this->atLeastOnce())
            ->method('getConfig')
            ->willReturn($this->pageConfigMock);
        $this->pageConfigMock->expects($this->atLeastOnce())
            ->method('getTitle')
            ->willReturn($this->pageTitleMock);
        $this->pageTitleMock->expects($this->exactly(2))
            ->method('prepend')
            ->withConsecutive(
                ['Shipments'],
                ["#" . $incrementId]
            )
            ->willReturnSelf();

        $this->assertEquals($this->resultPageMock, $this->controller->executeInternal());
    }
 /**
  * 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());
 }
 /**
  * Run test execute method (save exception)
  */
 public function testExecuteExceptionSave()
 {
     $data = ['comment' => 'comment'];
     $orderId = 1;
     $shipmentId = 1;
     $shipment = [];
     $tracking = [];
     $this->requestMock->expects($this->once())->method('setParam')->with('shipment_id', $shipmentId);
     $this->requestMock->expects($this->once())->method('getPost')->with('comment')->will($this->returnValue($data));
     $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([['id', null, $shipmentId], ['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]]));
     $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
     $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
     $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock));
     $this->shipmentMock->expects($this->once())->method('addComment');
     $this->shipmentCommentSenderMock->expects($this->once())->method('send');
     $this->shipmentMock->expects($this->once())->method('save')->will($this->throwException(new \Exception()));
     $this->exceptionResponse();
     $this->assertNull($this->controller->execute());
 }
Esempio n. 10
0
    /**
     * Run test execute method (exception save shipment)
     */
    public function testExecuteSaveException()
    {
        $logerMock = $this->getMock('Psr\Log\LoggerInterface');

        $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->returnValue(true));
        $this->shipmentMock->expects($this->once())->method('save')->will($this->throwException(new \Exception()));
        $logerMock->expects($this->once())->method('critical');
        $this->objectManagerMock->expects($this->once())
            ->method('get')
            ->with('Psr\Log\LoggerInterface')
            ->will($this->returnValue($logerMock));
        $this->responseMock->expects($this->once())->method('representJson');

        $this->assertNull($this->controller->executeInternal());
    }
Esempio n. 11
0
 /**
  * test shipment label get service
  */
 public function testInvoke()
 {
     $this->shipmentRepositoryMock->expects($this->once())->method('get')->with($this->equalTo(1))->will($this->returnValue($this->shipmentMock));
     $this->shipmentMock->expects($this->once())->method('getShippingLabel')->will($this->returnValue('shipping_label'));
     $this->assertEquals('shipping_label', $this->shipmentLabelGet->invoke(1));
 }