Skip to content

Commit c781fb3

Browse files
authored
ENGCOM-6422: magento/graphql-ce#808: [Test coverage] Add disabled variation of Configurable Product to cart #1071
2 parents f65f779 + 29a06dc commit c781fb3

File tree

5 files changed

+115
-3
lines changed

5 files changed

+115
-3
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function testAddVariationFromAnotherConfigurableProductWithDifferentSuper
199199
/**
200200
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
201201
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
202-
* @expectedException \Exception
202+
* @expectedException Exception
203203
* @expectedExceptionMessage The requested qty is not available
204204
*/
205205
public function testAddProductIfQuantityIsNotAvailable()
@@ -224,7 +224,7 @@ public function testAddProductIfQuantityIsNotAvailable()
224224
/**
225225
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
226226
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
227-
* @expectedException \Exception
227+
* @expectedException Exception
228228
* @expectedExceptionMessage Could not find a product with SKU "configurable_no_exist"
229229
*/
230230
public function testAddNonExistentConfigurableProductParentToCart()
@@ -263,7 +263,7 @@ public function testAddNonExistentConfigurableProductVariationToCart()
263263
2000
264264
);
265265

266-
$this->expectException(\Exception::class);
266+
$this->expectException(Exception::class);
267267
$this->expectExceptionMessage(
268268
'Could not add the product with SKU configurable to the shopping cart: The product that was requested ' .
269269
'doesn\'t exist. Verify the product and try again.'
@@ -272,6 +272,58 @@ public function testAddNonExistentConfigurableProductVariationToCart()
272272
$this->graphQlMutation($query);
273273
}
274274

275+
/**
276+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_disable_first_child.php
277+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
278+
*/
279+
public function testAddDisabledVariationToCart()
280+
{
281+
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable'));
282+
$product = current($searchResponse['products']['items']);
283+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
284+
$parentSku = $product['sku'];
285+
$sku = 'simple_10';
286+
$query = $this->getQuery(
287+
$maskedQuoteId,
288+
$parentSku,
289+
$sku,
290+
1
291+
);
292+
293+
$this->expectException(Exception::class);
294+
$this->expectExceptionMessage(
295+
'Could not add the product with SKU configurable to the shopping cart: This product is out of stock.'
296+
);
297+
298+
$this->graphQlMutation($query);
299+
}
300+
301+
/**
302+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_zero_qty_first_child.php
303+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
304+
*/
305+
public function testOutOfStockVariationToCart()
306+
{
307+
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable'));
308+
$product = current($searchResponse['products']['items']);
309+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
310+
$parentSku = $product['sku'];
311+
$sku = 'simple_10';
312+
$query = $this->getQuery(
313+
$maskedQuoteId,
314+
$parentSku,
315+
$sku,
316+
1
317+
);
318+
319+
$this->expectException(Exception::class);
320+
$this->expectExceptionMessage(
321+
'Could not add the product with SKU configurable to the shopping cart: This product is out of stock.'
322+
);
323+
324+
$this->graphQlMutation($query);
325+
}
326+
275327
/**
276328
* @param string $maskedQuoteId
277329
* @param string $parentSku
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
require __DIR__ . '/product_configurable_sku.php';
9+
10+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Catalog\Model\Product\Action;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
$childSku = 'simple_10';
16+
17+
$childProduct = $productRepository->get($childSku);
18+
$productAction = Bootstrap::getObjectManager()->get(Action::class);
19+
$productAction->updateAttributes(
20+
[$childProduct->getEntityId()],
21+
[ProductAttributeInterface::CODE_STATUS => Status::STATUS_DISABLED],
22+
$childProduct->getStoreId()
23+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
require __DIR__ . '/product_configurable_sku_rollback.php';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
require __DIR__ . '/product_configurable_sku.php';
9+
10+
$childSku = 'simple_10';
11+
12+
$childProduct = $productRepository->get($childSku);
13+
$childProduct->setStockData(
14+
[
15+
'use_config_manage_stock' => 1,
16+
'qty' => 0,
17+
'is_qty_decimal' => 0,
18+
'is_in_stock' => 0
19+
]
20+
);
21+
$productRepository->save($childProduct);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
require __DIR__ . '/product_configurable_sku_rollback.php';

0 commit comments

Comments
 (0)