Esempio n. 1
0
 public function testGetStoreFromOrder()
 {
     $resultStore = 1;
     $this->model->setOrder($this->order);
     $this->order->expects($this->once())->method('getStore')->willReturn($resultStore);
     $this->assertEquals($resultStore, $this->model->getStore());
 }
Esempio n. 2
0
 /**
  * @param History $history
  * @return array
  */
 public function validate(History $history)
 {
     $warnings = [];
     foreach ($this->requiredFields as $code => $label) {
         if (!$history->hasData($code)) {
             $warnings[] = sprintf('%s is a required field', $label);
         }
     }
     return $warnings;
 }
 public function testAddComment()
 {
     $clearComment = "Comment text here...";
     $this->orderRepositoryMock->expects($this->once())->method('get')->with(123)->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('addStatusHistory')->with($this->orderStatusHistoryMock)->willReturn($this->orderMock);
     $this->orderStatusHistoryMock->expects($this->once())->method('getComment')->willReturn("<h1>" . $clearComment);
     $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturn([]);
     $this->orderCommentSender->expects($this->once())->method('send')->with($this->orderMock, false, $clearComment);
     $this->assertTrue($this->orderService->addComment(123, $this->orderStatusHistoryMock));
 }
Esempio n. 4
0
 public function setUp()
 {
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->selectMock = $this->getMock('Zend_Db_Select', [], [], '', false);
     $this->historyItemMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History', ['__wakeup', 'addData'], [], '', false);
     $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['getReadConnection', 'getMainTable', 'getTable', '__wakeup']);
     $this->fetchStrategyMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->entityFactoryMock = $this->getMock('Magento\\Core\\Model\\EntityFactory', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->atLeastOnce())->method('select')->will($this->returnValue($this->selectMock));
     $data = [['data']];
     $this->historyItemMock->expects($this->once())->method('addData')->with($this->equalTo($data[0]))->will($this->returnValue($this->historyItemMock));
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->will($this->returnValue($data));
     $this->entityFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->historyItemMock));
     $logger = $this->getMock('Magento\\Framework\\Logger', [], [], '', false);
     $this->collection = new \Magento\Sales\Model\Resource\Order\Status\History\Collection($this->entityFactoryMock, $logger, $this->fetchStrategyMock, $this->eventManagerMock, $this->connectionMock, $this->resourceMock);
 }
Esempio n. 5
0
 public function testProcessRelation()
 {
     $this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->orderMock)->willReturnSelf();
     $this->addressHandlerMock->expects($this->once())->method('process')->with($this->orderMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn('order-id-value');
     $this->orderItemMock->expects($this->once())->method('setOrderId')->with('order-id-value')->willReturnSelf();
     $this->orderItemMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderItemRepositoryMock->expects($this->once())->method('save')->with($this->orderItemMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getPayment')->willReturn($this->orderPaymentMock);
     $this->orderPaymentMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
     $this->orderPaymentMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderPaymentResourceMock->expects($this->once())->method('save')->with($this->orderPaymentMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getStatusHistories')->willReturn([$this->orderStatusHistoryMock]);
     $this->orderStatusHistoryMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
     $this->orderStatusHistoryMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->statusHistoryResource->expects($this->once())->method('save')->with($this->orderStatusHistoryMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getRelatedObjects')->willReturn([$this->orderInvoiceMock]);
     $this->orderInvoiceMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderInvoiceMock->expects($this->once())->method('save')->willReturnSelf();
     $this->relationProcessor->processRelation($this->orderMock);
 }
Esempio n. 6
0
 /**
  * Set the order status history object and the order object to each other
  * Adds the object to the status history collection, which is automatically saved when the order is saved.
  * See the entity_id attribute backend model.
  * Or the history record can be saved standalone after this.
  *
  * @param \Magento\Sales\Model\Order\Status\History $history
  * @return $this
  */
 public function addStatusHistory(\Magento\Sales\Model\Order\Status\History $history)
 {
     $history->setOrder($this);
     $this->setStatus($history->getStatus());
     if (!$history->getId()) {
         $this->setStatusHistories(array_merge($this->getStatusHistories(), [$history]));
         $this->setDataChanges(true);
     }
     return $this;
 }
Esempio n. 7
0
 /**
  * Customer Notification Applicable check method
  *
  * @param  \Magento\Sales\Model\Order\Status\History $history
  * @return bool
  */
 public function isCustomerNotificationNotApplicable(\Magento\Sales\Model\Order\Status\History $history)
 {
     return $history->isCustomerNotificationNotApplicable();
 }
Esempio n. 8
0
 /**
  * Set the order status history object and the order object to each other
  * Adds the object to the status history collection, which is automatically saved when the order is saved.
  * See the entity_id attribute backend model.
  * Or the history record can be saved standalone after this.
  *
  * @param \Magento\Sales\Model\Order\Status\History $history
  * @return $this
  */
 public function addStatusHistory(\Magento\Sales\Model\Order\Status\History $history)
 {
     $history->setOrder($this);
     $this->setStatus($history->getStatus());
     if (!$history->getId()) {
         $this->getStatusHistoryCollection()->addItem($history);
         $this->setDataChanges(true);
     }
     return $this;
 }