AddSimpleProductToCartTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\GraphQl\Quote;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. use Magento\TestFramework\TestCase\GraphQlAbstract;
  10. use Magento\Quote\Model\Quote;
  11. use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
  12. use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
  13. class AddSimpleProductToCartTest extends GraphQlAbstract
  14. {
  15. /**
  16. * @var QuoteResource
  17. */
  18. private $quoteResource;
  19. /**
  20. * @var Quote
  21. */
  22. private $quote;
  23. /**
  24. * @var QuoteIdToMaskedQuoteIdInterface
  25. */
  26. private $quoteIdToMaskedId;
  27. /**
  28. * @inheritdoc
  29. */
  30. protected function setUp()
  31. {
  32. $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/434');
  33. $objectManager = Bootstrap::getObjectManager();
  34. $this->quoteResource = $objectManager->get(QuoteResource::class);
  35. $this->quote = $objectManager->create(Quote::class);
  36. $this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
  37. }
  38. /**
  39. * @magentoApiDataFixture Magento/Catalog/_files/products.php
  40. * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
  41. * @expectedException \Exception
  42. * @expectedExceptionMessage The requested qty is not available
  43. */
  44. public function testAddProductIfQuantityIsNotAvailable()
  45. {
  46. $sku = 'simple';
  47. $qty = 200;
  48. $this->quoteResource->load(
  49. $this->quote,
  50. 'test_order_1',
  51. 'reserved_order_id'
  52. );
  53. $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
  54. $query = <<<QUERY
  55. mutation {
  56. addSimpleProductsToCart(
  57. input: {
  58. cart_id: "{$maskedQuoteId}",
  59. cartItems: [
  60. {
  61. data: {
  62. qty: $qty
  63. sku: "$sku"
  64. }
  65. }
  66. ]
  67. }
  68. ) {
  69. cart {
  70. items {
  71. qty
  72. }
  73. }
  74. }
  75. }
  76. QUERY;
  77. $this->graphQlQuery($query);
  78. }
  79. }