/** * @expectedException \Magento\Framework\Exception\CouldNotSaveException * @expectedExceptionMessage Could not add gift message to shopping cart */ public function testSetMessageCouldNotAddGiftMessageException() { $this->quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($this->billingAddressMock)); $this->billingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(12)); $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(13)); $this->giftMessageMock->expects($this->once())->method('getSender')->will($this->returnValue('sender')); $this->giftMessageMock->expects($this->once())->method('getRecipient')->will($this->returnValue('recipient')); $this->giftMessageMock->expects($this->once())->method('getMessage')->will($this->returnValue('Message')); $this->messageFactoryMock->expects($this->once())->method('create')->willThrowException(new \Exception()); $this->model->setMessage($this->quoteMock, 'item', $this->giftMessageMock); }
public function testAddWithQuoteAddressItem() { $entityId = 1; $giftMessages = array('quote_address_item' => array(1 => array('from' => 'sender', 'to' => 'recipient', 'message' => 'message', 'address' => 'address'))); $this->messageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->giftMessageMock)); $this->quoteMock->expects($this->once())->method('getAddressById')->with('address')->will($this->returnValue($this->quoteAddressMock)); $this->quoteAddressMock->expects($this->once())->method('getItemById')->with($entityId)->will($this->returnValue($this->quoteAddressItemMock)); $this->quoteAddressItemMock->expects($this->once())->method('getGiftMessageId')->will($this->returnValue(0)); $this->giftMessageMock->expects($this->once())->method('setSender')->with('sender')->will($this->returnValue($this->giftMessageMock)); $this->giftMessageMock->expects($this->once())->method('setRecipient')->with('recipient')->will($this->returnValue($this->giftMessageMock)); $this->giftMessageMock->expects($this->once())->method('setMessage')->with('message')->will($this->returnValue($this->giftMessageMock)); $this->giftMessageMock->expects($this->once())->method('save'); $this->giftMessageMock->expects($this->once())->method('getId')->will($this->returnValue(33)); $this->quoteAddressItemMock->expects($this->once())->method('setGiftMessageId')->with(33)->will($this->returnValue($this->quoteAddressItemMock)); $this->quoteAddressItemMock->expects($this->once())->method('save')->will($this->returnValue($this->quoteAddressItemMock)); $this->model->add($giftMessages, $this->quoteMock); }