Skip to content

Commit dabbd3c

Browse files
committed
Added test and minor fix
1 parent cea930b commit dabbd3c

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

app/code/Magento/QuoteGraphQl/Model/CartItem/DataProvider/UpdateCartItems.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ public function __construct(
6464
*
6565
* @param Quote $cart
6666
* @param array $items
67+
*
6768
* @throws GraphQlInputException
6869
* @throws LocalizedException
70+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
71+
* @SuppressWarnings(PHPMD.NPathComplexity)
6972
*/
7073
public function processCartItems(Quote $cart, array $items): void
7174
{

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/UpdateCartItemsTest.php

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\GraphQl\Quote\Guest;
99

10-
use Magento\Quote\Model\QuoteFactory;
10+
use Exception;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Quote\Model\QuoteFactory;
1213
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1314
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1415
use Magento\TestFramework\Helper\Bootstrap;
@@ -273,6 +274,81 @@ private function getCartQuery(string $maskedQuoteId)
273274
}
274275
}
275276
}
277+
QUERY;
278+
}
279+
280+
/**
281+
* @magentoConfigFixture default_store sales/gift_options/allow_items 1
282+
* @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php
283+
* @throws Exception
284+
*/
285+
public function testUpdateGiftMessageCartForItem()
286+
{
287+
$query = $this->getUpdateGiftMessageQuery();
288+
foreach ($this->graphQlMutation($query)['updateCartItems']['cart']['items'] as $item) {
289+
self::assertArrayHasKey('gift_message', $item);
290+
self::assertSame('Alex', $item['gift_message']['to']);
291+
self::assertSame('Mike', $item['gift_message']['from']);
292+
self::assertSame('Best regards.', $item['gift_message']['message']);
293+
}
294+
}
295+
296+
/**
297+
* @magentoConfigFixture default_store sales/gift_options/allow_items 0
298+
* @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php
299+
* @throws Exception
300+
*/
301+
public function testUpdateGiftMessageCartForItemNotAllow()
302+
{
303+
$query = $this->getUpdateGiftMessageQuery();
304+
foreach ($this->graphQlMutation($query)['updateCartItems']['cart']['items'] as $item) {
305+
self::assertNull($item['gift_message']);
306+
}
307+
}
308+
309+
private function getUpdateGiftMessageQuery()
310+
{
311+
$quote = $this->quoteFactory->create();
312+
$this->quoteResource->load($quote, 'test_guest_order_with_gift_message', 'reserved_order_id');
313+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
314+
$itemId = (int)$quote->getItemByProduct($this->productRepository->get('simple'))->getId();
315+
316+
return <<<QUERY
317+
mutation {
318+
updateCartItems(
319+
input: {
320+
cart_id: "$maskedQuoteId",
321+
cart_items: [
322+
{
323+
cart_item_id: $itemId
324+
quantity: 3
325+
gift_message: {
326+
to: "Alex"
327+
from: "Mike"
328+
message: "Best regards."
329+
}
330+
}
331+
]
332+
}
333+
) {
334+
cart {
335+
items {
336+
id
337+
product {
338+
name
339+
}
340+
quantity
341+
... on SimpleCartItem {
342+
gift_message {
343+
to
344+
from
345+
message
346+
}
347+
}
348+
}
349+
}
350+
}
351+
}
276352
QUERY;
277353
}
278354
}

0 commit comments

Comments
 (0)