public function testSave()
 {
     $cartId = 'jIUggbo76';
     $quoteId = 123;
     $itemId = 234;
     /** @var QuoteIdMask|\PHPUnit_Framework_MockObject_MockObject $quoteIdMaskMock */
     $quoteIdMaskMock = $this->getMockBuilder('Magento\\Quote\\Model\\QuoteIdMask')->setMethods(['getQuoteId', 'load'])->disableOriginalConstructor()->getMock();
     $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($quoteIdMaskMock);
     $quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf();
     $quoteIdMaskMock->expects($this->once())->method('getQuoteId')->willReturn($quoteId);
     /** @var MessageInterface|\PHPUnit_Framework_MockObject_MockObject $messageMock */
     $messageMock = $this->getMockBuilder('Magento\\GiftMessage\\Api\\Data\\MessageInterface')->getMockForAbstractClass();
     $this->repositoryMock->expects($this->once())->method('save')->with($quoteId, $messageMock, $itemId)->willReturn(true);
     $this->assertTrue($this->model->save($cartId, $messageMock, $itemId));
 }
Exemplo n.º 2
0
 public function testSave()
 {
     $itemId = 1;
     $quoteItem = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', ['getIsVirtual', '__wakeup'], [], '', false);
     $this->quoteMock->expects($this->once())->method('getItemById')->with($itemId)->will($this->returnValue($quoteItem));
     $quoteItem->expects($this->once())->method('getIsVirtual')->will($this->returnValue(0));
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->helperMock->expects($this->once())->method('isMessagesAllowed')->with('items', $this->quoteMock, $this->storeMock)->will($this->returnValue(true));
     $this->giftMessageManagerMock->expects($this->once())->method('setMessage')->with($this->quoteMock, 'quote_item', $this->messageMock, $itemId)->will($this->returnValue($this->giftMessageManagerMock));
     $this->assertTrue($this->itemRepository->save($this->cartId, $this->messageMock, $itemId));
 }
 /**
  * {@inheritDoc}
  */
 public function save($cartId, MessageInterface $giftMessage, $itemId)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->repository->save($quoteIdMask->getQuoteId(), $giftMessage, $itemId);
 }