|
| 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 AddSimpleProductToCartTest extends GraphQlAbstract |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var QuoteResource |
| 20 | + */ |
| 21 | + private $quoteResource; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var Quote |
| 25 | + */ |
| 26 | + private $quote; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var QuoteIdToMaskedQuoteIdInterface |
| 30 | + */ |
| 31 | + private $quoteIdToMaskedId; |
| 32 | + |
| 33 | + /** |
| 34 | + * @inheritdoc |
| 35 | + */ |
| 36 | + protected function setUp() |
| 37 | + { |
| 38 | + $objectManager = Bootstrap::getObjectManager(); |
| 39 | + $this->quoteResource = $objectManager->get(QuoteResource::class); |
| 40 | + $this->quote = $objectManager->create(Quote::class); |
| 41 | + $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @magentoApiDataFixture Magento/Catalog/_files/products.php |
| 46 | + * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php |
| 47 | + * @expectedException \Exception |
| 48 | + * @expectedExceptionMessage The requested qty is not available |
| 49 | + */ |
| 50 | + public function testAddProductIfQuantityIsNotAvailable() |
| 51 | + { |
| 52 | + $sku = 'simple'; |
| 53 | + $qty = 200; |
| 54 | + |
| 55 | + $this->quoteResource->load( |
| 56 | + $this->quote, |
| 57 | + 'test_order_1', |
| 58 | + 'reserved_order_id' |
| 59 | + ); |
| 60 | + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); |
| 61 | + |
| 62 | + $query = <<<QUERY |
| 63 | +mutation { |
| 64 | + addSimpleProductsToCart( |
| 65 | + input: { |
| 66 | + cart_id: "{$maskedQuoteId}", |
| 67 | + cartItems: [ |
| 68 | + { |
| 69 | + data: { |
| 70 | + qty: $qty |
| 71 | + sku: "$sku" |
| 72 | + } |
| 73 | + } |
| 74 | + ] |
| 75 | + } |
| 76 | + ) { |
| 77 | + cart { |
| 78 | + cart_id |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +QUERY; |
| 83 | + |
| 84 | + $this->graphQlQuery($query); |
| 85 | + } |
| 86 | +} |
0 commit comments