51 $this->messageFactoryMock =
52 $this->createPartialMock(\
Magento\GiftMessage\Model\MessageFactory::class, [
'create',
'__wakeup']);
54 $this->quoteMock = $this->createPartialMock(
55 \
Magento\Quote\Model\Quote::class,
68 $this->quoteItemMock = $this->createPartialMock(
69 \
Magento\Quote\Model\Quote\Item::class,
78 $this->quoteAddressMock = $this->createPartialMock(
79 \
Magento\Quote\Model\Quote\Address::class,
89 $this->quoteAddressItemMock = $this->createPartialMock(
90 \
Magento\Quote\Model\Quote\Address\Item::class,
99 $this->giftMessageMock = $this->createPartialMock(
100 \
Magento\GiftMessage\Model\Message::class,
117 $this->model = new \Magento\GiftMessage\Model\GiftMessageManager($this->messageFactoryMock);
123 $this->messageFactoryMock->expects($this->never())->method(
'create');
124 $this->model->add($giftMessages, $this->quoteMock);
139 $this->messageFactoryMock->expects($this->once())
141 ->will($this->returnValue($this->giftMessageMock));
142 $this->quoteMock->expects($this->once())->method(
'getGiftMessageId')->will($this->returnValue(
null));
143 $this->giftMessageMock->expects($this->never())->method(
'load');
144 $this->giftMessageMock->expects($this->once())->method(
'getId')->will($this->returnValue(1));
145 $this->giftMessageMock->expects($this->once())->method(
'delete');
146 $this->quoteMock->expects($this->once())
147 ->method(
'setGiftMessageId')
149 ->will($this->returnValue($this->quoteMock));
150 $exception = new \Exception();
151 $this->quoteMock->expects($this->once())->method(
'save')->will($this->throwException($exception));
153 $this->model->add($giftMessages, $this->quoteMock);
164 'message' =>
'message',
170 $this->messageFactoryMock->expects($this->once())
172 ->will($this->returnValue($this->giftMessageMock));
173 $this->quoteMock->expects($this->once())
174 ->method(
'getItemById')
176 ->will($this->returnValue($this->quoteItemMock));
177 $this->quoteItemMock->expects($this->once())->method(
'getGiftMessageId')->will($this->returnValue(
null));
178 $this->giftMessageMock->expects($this->once())
179 ->method(
'setSender')
181 ->will($this->returnValue($this->giftMessageMock));
182 $this->giftMessageMock->expects($this->once())
183 ->method(
'setRecipient')
185 ->will($this->returnValue($this->giftMessageMock));
186 $this->quoteMock->expects($this->once())->method(
'getCustomerId')->willReturn(
$customerId);
187 $this->giftMessageMock->expects($this->once())
188 ->method(
'setCustomerId')
190 ->will($this->returnValue($this->giftMessageMock));
191 $this->giftMessageMock->expects($this->once())
192 ->method(
'setMessage')
194 ->will($this->returnValue($this->giftMessageMock));
195 $this->giftMessageMock->expects($this->once())->method(
'save');
196 $this->giftMessageMock->expects($this->once())->method(
'getId')->will($this->returnValue(33));
197 $this->quoteItemMock->expects($this->once())
198 ->method(
'setGiftMessageId')
200 ->will($this->returnValue($this->quoteItemMock));
201 $exception = new \Exception();
202 $this->quoteItemMock->expects($this->once())->method(
'save')->will($this->throwException($exception));
204 $this->model->add($giftMessages, $this->quoteMock);
215 'message' =>
'message',
221 $this->messageFactoryMock->expects($this->once())
223 ->will($this->returnValue($this->giftMessageMock));
224 $this->quoteMock->expects($this->once())
225 ->method(
'getAddressById')
227 ->will($this->returnValue($this->quoteAddressMock));
228 $this->quoteAddressMock->expects($this->once())->method(
'getGiftMessageId')->will($this->returnValue(
null));
229 $this->giftMessageMock->expects($this->once())
230 ->method(
'setSender')
232 ->will($this->returnValue($this->giftMessageMock));
233 $this->giftMessageMock->expects($this->once())
234 ->method(
'setRecipient')
236 ->will($this->returnValue($this->giftMessageMock));
237 $this->giftMessageMock->expects($this->once())
238 ->method(
'setMessage')
240 ->will($this->returnValue($this->giftMessageMock));
241 $this->quoteMock->expects($this->once())->method(
'getCustomerId')->willReturn(
$customerId);
242 $this->giftMessageMock->expects($this->once())
243 ->method(
'setCustomerId')
245 ->will($this->returnValue($this->giftMessageMock));
246 $this->giftMessageMock->expects($this->once())->method(
'save');
247 $this->giftMessageMock->expects($this->once())->method(
'getId')->will($this->returnValue(33));
248 $this->quoteAddressMock->expects($this->once())
249 ->method(
'setGiftMessageId')
251 ->will($this->returnValue($this->quoteAddressMock));
252 $this->quoteAddressMock->expects($this->once())->method(
'save');
253 $this->model->add($giftMessages, $this->quoteMock);
260 'quote_address_item' => [
264 'message' =>
'message',
265 'address' =>
'address',
271 $this->messageFactoryMock->expects($this->once())
273 ->will($this->returnValue($this->giftMessageMock));
274 $this->quoteMock->expects($this->once())
275 ->method(
'getAddressById')
277 ->will($this->returnValue($this->quoteAddressMock));
278 $this->quoteAddressMock->expects($this->once())
279 ->method(
'getItemById')
281 ->will($this->returnValue($this->quoteAddressItemMock));
282 $this->quoteAddressItemMock->expects($this->once())->method(
'getGiftMessageId')->will($this->returnValue(0));
283 $this->giftMessageMock->expects($this->once())
284 ->method(
'setSender')
286 ->will($this->returnValue($this->giftMessageMock));
287 $this->giftMessageMock->expects($this->once())
288 ->method(
'setRecipient')
290 ->will($this->returnValue($this->giftMessageMock));
291 $this->giftMessageMock->expects($this->once())
292 ->method(
'setMessage')
294 ->will($this->returnValue($this->giftMessageMock));
295 $this->quoteMock->expects($this->once())->method(
'getCustomerId')->willReturn(
$customerId);
296 $this->giftMessageMock->expects($this->once())
297 ->method(
'setCustomerId')
299 ->will($this->returnValue($this->giftMessageMock));
300 $this->giftMessageMock->expects($this->once())->method(
'save');
301 $this->giftMessageMock->expects($this->once())->method(
'getId')->will($this->returnValue(33));
302 $this->quoteAddressItemMock->expects($this->once())
303 ->method(
'setGiftMessageId')
305 ->will($this->returnValue($this->quoteAddressItemMock));
306 $this->quoteAddressItemMock->expects($this->once())
308 ->will($this->returnValue($this->quoteAddressItemMock));
310 $this->model->add($giftMessages, $this->quoteMock);
319 $this->giftMessageMock->expects($this->once())->method(
'getSender')->will($this->returnValue(
'sender'));
320 $this->giftMessageMock->expects($this->once())->method(
'getRecipient')->will($this->returnValue(
'recipient'));
321 $this->giftMessageMock->expects($this->once())->method(
'getMessage')->will($this->returnValue(
'Message'));
323 $this->messageFactoryMock->expects($this->once())
325 ->willThrowException(
new \Exception());
327 $this->model->setMessage($this->quoteMock,
'item', $this->giftMessageMock);
testSetMessageCouldNotAddGiftMessageException()
testAddWhenGiftMessagesIsNoArray()
testAddWithSaveMessageIdAndEmptyMessageException()
testAddWithQuoteAddressItem()
testAddWithQuoteAddress()
testAddWithSaveMessageIdException()