|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\Quote; |
| 9 | + |
| 10 | +use Magento\TestFramework\Helper\Bootstrap; |
| 11 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 12 | +use Magento\Quote\Model\Quote; |
| 13 | +use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; |
| 14 | +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; |
| 15 | + |
| 16 | +class addConfigurableProductsToCartTest extends GraphQlAbstract |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var QuoteResource |
| 20 | + */ |
| 21 | + private $quoteResource; |
| 22 | + /** |
| 23 | + * @var Quote |
| 24 | + */ |
| 25 | + private $quote; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var QuoteIdToMaskedQuoteIdInterface |
| 29 | + */ |
| 30 | + private $quoteIdToMaskedId; |
| 31 | + |
| 32 | + /** |
| 33 | + * @inheritdoc |
| 34 | + */ |
| 35 | + protected function setUp() |
| 36 | + { |
| 37 | + $objectManager = Bootstrap::getObjectManager(); |
| 38 | + $this->quoteResource = $objectManager->create(QuoteResource::class); |
| 39 | + $this->quote = $objectManager->create(Quote::class); |
| 40 | + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php |
| 45 | + * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php |
| 46 | + */ |
| 47 | + public function testAddConfigurableProductsToCart() |
| 48 | + { |
| 49 | + $variantSku = 'simple_41'; |
| 50 | + $qty = 200; |
| 51 | + $expectedMessage = 'GraphQL response contains errors: The requested qty is not available |
| 52 | +'; |
| 53 | + $this->quoteResource->load( |
| 54 | + $this->quote, |
| 55 | + 'test_order_with_simple_product_without_address', |
| 56 | + 'reserved_order_id' |
| 57 | + ); |
| 58 | + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); |
| 59 | + $query = $this->prepareAddConfigurableProductsToCartQuery($maskedQuoteId, $variantSku, $qty); |
| 60 | + |
| 61 | + try { |
| 62 | + $this->graphQlQuery($query); |
| 63 | + } catch (\Exception $exception) { |
| 64 | + $this->assertEquals( |
| 65 | + $expectedMessage, |
| 66 | + $exception->getMessage() |
| 67 | + ); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @param string $maskedQuoteId |
| 73 | + * @param string $variantSku |
| 74 | + * @param int $qty |
| 75 | + * |
| 76 | + * @return string |
| 77 | + */ |
| 78 | + public function prepareAddConfigurableProductsToCartQuery(string $maskedQuoteId, string $variantSku, int $qty) |
| 79 | + { |
| 80 | + return <<<QUERY |
| 81 | +mutation { |
| 82 | + |
| 83 | + addConfigurableProductsToCart( |
| 84 | + input: { |
| 85 | + cart_id: "$maskedQuoteId", |
| 86 | + cartItems: [ |
| 87 | + { |
| 88 | + variant_sku: "$variantSku" |
| 89 | + data: { |
| 90 | + qty: $qty |
| 91 | + sku: "$variantSku" |
| 92 | + } |
| 93 | + } |
| 94 | + ] |
| 95 | + } |
| 96 | + ) { |
| 97 | + cart { |
| 98 | + items { |
| 99 | + id |
| 100 | + qty |
| 101 | + product { |
| 102 | + name |
| 103 | + sku |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | +
|
| 110 | +QUERY; |
| 111 | + } |
| 112 | +} |
0 commit comments