|
8 | 8 | namespace Magento\GraphQl\Quote\Guest;
|
9 | 9 |
|
10 | 10 | use Exception;
|
| 11 | +use Magento\Framework\Exception\NoSuchEntityException; |
11 | 12 | use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
12 | 13 | use Magento\TestFramework\Helper\Bootstrap;
|
| 14 | +use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; |
13 | 15 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
14 | 16 |
|
15 | 17 | /**
|
@@ -79,6 +81,57 @@ public function testAddSimpleProductToCart()
|
79 | 81 | self::assertEquals('USD', $rowTotalIncludingTax['currency']);
|
80 | 82 | }
|
81 | 83 |
|
| 84 | + /** |
| 85 | + * Add disabled product to cart |
| 86 | + * |
| 87 | + * @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php |
| 88 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php |
| 89 | + * @return void |
| 90 | + */ |
| 91 | + public function testAddDisabledProductToCart(): void |
| 92 | + { |
| 93 | + $sku = 'simple3'; |
| 94 | + $quantity = 2; |
| 95 | + |
| 96 | + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); |
| 97 | + $query = $this->getQuery($maskedQuoteId, $sku, $quantity); |
| 98 | + |
| 99 | + $this->expectException(ResponseContainsErrorsException::class); |
| 100 | + $this->expectExceptionMessage( |
| 101 | + 'Could not add the product with SKU ' . $sku . ' to the shopping cart: ' . |
| 102 | + 'Product that you are trying to add is not available.' |
| 103 | + ); |
| 104 | + |
| 105 | + $this->graphQlMutation($query); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Add out of stock product to cart |
| 110 | + * |
| 111 | + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php |
| 112 | + * @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php |
| 113 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php |
| 114 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php |
| 115 | + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php |
| 116 | + * @return void |
| 117 | + * @throws NoSuchEntityException |
| 118 | + */ |
| 119 | + public function testAddOutOfStockProductToCart(): void |
| 120 | + { |
| 121 | + $sku = 'simple1'; |
| 122 | + $quantity = 1; |
| 123 | + |
| 124 | + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); |
| 125 | + $query = $this->getQuery($maskedQuoteId, $sku, $quantity); |
| 126 | + |
| 127 | + $this->expectException(ResponseContainsErrorsException::class); |
| 128 | + $this->expectExceptionMessage( |
| 129 | + 'Some of the products are out of stock.' |
| 130 | + ); |
| 131 | + |
| 132 | + $this->graphQlMutation($query); |
| 133 | + } |
| 134 | + |
82 | 135 | /**
|
83 | 136 | * @expectedException Exception
|
84 | 137 | * @expectedExceptionMessage Required parameter "cart_id" is missing
|
@@ -191,7 +244,7 @@ public function testAddSimpleProductToCustomerCart()
|
191 | 244 | private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
|
192 | 245 | {
|
193 | 246 | return <<<QUERY
|
194 |
| -mutation { |
| 247 | +mutation { |
195 | 248 | addSimpleProductsToCart(
|
196 | 249 | input: {
|
197 | 250 | cart_id: "{$maskedQuoteId}"
|
|
0 commit comments