Skip to content

Commit 201f9be

Browse files
Vahalenaorobei
authored andcommitted
magento/graphql-ce#808: [Test coverage] Add disabled variation of Configurable Product to cart, improved fixtures
1 parent 8fd5c78 commit 201f9be

File tree

5 files changed

+31
-39
lines changed

5 files changed

+31
-39
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ public function testAddNonExistentConfigurableProductVariationToCart()
273273
}
274274

275275
/**
276-
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
277276
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_disable_first_child.php
278277
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
279278
*/
@@ -300,7 +299,6 @@ public function testAddDisabledVariationToCart()
300299
}
301300

302301
/**
303-
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
304302
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_zero_qty_first_child.php
305303
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
306304
*/

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_disable_first_child.php

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,22 @@
55
*/
66
declare(strict_types=1);
77

8+
require __DIR__ . '/product_configurable_sku.php';
9+
810
use Magento\Catalog\Api\Data\ProductAttributeInterface;
9-
use Magento\Catalog\Api\ProductRepositoryInterface;
10-
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\Action;
1212
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13-
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1413
use Magento\TestFramework\Helper\Bootstrap;
1514

16-
/** @var ProductRepositoryInterface $productRepository */
17-
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
18-
15+
$childSku = 'simple_10';
1916
try {
20-
/** @var Product $configurableProduct */
21-
$configurableProduct = $productRepository->get('configurable');
22-
/** @var Configurable $productTypeInstance */
23-
$productTypeInstance = $configurableProduct->getTypeInstance();
24-
/** @var Product $child */
25-
foreach ($productTypeInstance->getUsedProducts($configurableProduct) as $child) {
26-
27-
$productAction = Bootstrap::getObjectManager()->get(Action::class);
28-
$productAction->updateAttributes(
29-
[$child->getId()],
30-
[ProductAttributeInterface::CODE_STATUS => Status::STATUS_DISABLED],
31-
$child->getStoreId()
32-
);
33-
break;
34-
}
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+
);
3524
} catch (Exception $e) {
3625
// Nothing to remove
3726
}
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';

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_zero_qty_first_child.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,13 @@
55
*/
66
declare(strict_types=1);
77

8-
use Magento\Catalog\Api\ProductRepositoryInterface;
9-
use Magento\Catalog\Model\Product as ProductModel;
10-
use Magento\TestFramework\Helper\Bootstrap;
11-
12-
/** @var ProductRepositoryInterface $productRepository */
13-
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
8+
require __DIR__ . '/product_configurable_sku.php';
149

10+
$childSku = 'simple_10';
1511
try {
16-
$configurableProduct = $productRepository->get('configurable');
17-
$productTypeInstance = $configurableProduct->getTypeInstance();
18-
19-
/** @var ProductModel $child */
20-
foreach ($productTypeInstance->getUsedProducts($configurableProduct) as $child) {
21-
$childProduct = $productRepository->getById($child->getId());
22-
$childProduct->setStockData(['use_config_manage_stock' => 1, 'qty' => 0, 'is_qty_decimal' => 0, 'is_in_stock' => 0]);
23-
$productRepository->save($childProduct);
24-
break;
25-
}
12+
$childProduct = $productRepository->get($childSku);
13+
$childProduct->setStockData(['use_config_manage_stock' => 1, 'qty' => 0, 'is_qty_decimal' => 0, 'is_in_stock' => 0]);
14+
$productRepository->save($childProduct);
2615
} catch (Exception $e) {
2716
// Nothing to remove
2817
}
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)