Skip to content

Commit 0b8761f

Browse files
MC-29126: Admin: Create/update/delete configurable product
1 parent a514d7f commit 0b8761f

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class ProductTest extends AbstractBackendController
6363
protected function setUp()
6464
{
6565
parent::setUp();
66-
$this->productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
66+
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
67+
$this->productRepository->cleanCache();
6768
$this->productAttributeRepository = $this->_objectManager->create(ProductAttributeRepositoryInterface::class);
6869
$this->registry = $this->_objectManager->get(Registry::class);
6970
$this->jsonSerializer = $this->_objectManager->get(SerializerInterface::class);
@@ -106,7 +107,6 @@ public function testSaveNewProduct(array $childProducts): void
106107
$this->assertChildProducts($childProducts);
107108
$this->assertConfigurableOptions('configurable', $childProducts);
108109
$this->assertConfigurableLinks('configurable', $this->getProductIds(array_keys($childProducts)));
109-
$this->deleteProducts(array_merge(array_keys($childProducts), ['configurable']));
110110
}
111111

112112
/**
@@ -157,7 +157,7 @@ public function saveNewProductDataProvider(): array
157157
}
158158

159159
/**
160-
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable_with_one_simple.php
160+
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_one_simple.php
161161
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_attribute_2.php
162162
* @dataProvider saveExistProductDataProvider
163163
* @param array $childProducts
@@ -176,7 +176,6 @@ public function testSaveExistProduct(array $childProducts, array $associatedProd
176176
'configurable',
177177
$this->getProductIds(array_merge($associatedProducts, array_keys($childProducts)))
178178
);
179-
$this->deleteProducts(array_merge($associatedProducts, array_keys($childProducts)));
180179
}
181180

182181
/**
@@ -323,6 +322,7 @@ private function assertConfigurableLinks(string $sku, array $associatedProductId
323322
private function assertRegistryConfigurableLinks(array $associatedProductIds): void
324323
{
325324
$product = $this->registry->registry('current_product');
325+
$this->assertNotNull($product);
326326
$this->assertEquals(
327327
$associatedProductIds,
328328
array_values($product->getExtensionAttributes()->getConfigurableProductLinks() ?: []),
@@ -343,7 +343,7 @@ private function assertChildProducts(array $childProducts): void
343343
$this->assertEquals($expectedProduct['price'], $product->getPrice());
344344

345345
if (!empty($expectedProduct['weight'])) {
346-
$this->assertEquals($expectedProduct['weight'], (int)$product->getWeight());
346+
$this->assertEquals($expectedProduct['weight'], (double)$product->getWeight());
347347
$this->assertInstanceOf(Simple::class, $product->getTypeInstance());
348348
} else {
349349
$this->assertInstanceOf(Virtual::class, $product->getTypeInstance());
@@ -520,25 +520,4 @@ private function getProductIds(array $skuList): array
520520

521521
return $associatedProductIds;
522522
}
523-
524-
/**
525-
* @param array $skuList
526-
* @return void
527-
*/
528-
private function deleteProducts(array $skuList): void
529-
{
530-
$this->registry->unregister('isSecureArea');
531-
$this->registry->register('isSecureArea', true);
532-
533-
foreach ($skuList as $sku) {
534-
try {
535-
$product = $this->productRepository->get($sku, false, null, true);
536-
$this->productRepository->delete($product);
537-
} catch (NoSuchEntityException $e) {
538-
//Product already removed
539-
}
540-
}
541-
$this->registry->unregister('isSecureArea');
542-
$this->registry->register('isSecureArea', false);
543-
}
544523
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/** @var ProductExtensionInterfaceFactory $productExtensionAttributes */
2828
$productExtensionAttributesFactory = $objectManager->get(ProductExtensionInterfaceFactory::class);
2929
/** @var WebsiteRepositoryInterface $websiteRepository */
30-
$websiteRepository = $objectManager->create(WebsiteRepositoryInterface::class);
30+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
3131
$defaultWebsiteId = $websiteRepository->get('base')->getId();
3232

3333
$option = $attribute->getSource()->getOptionId('Option 1');

0 commit comments

Comments
 (0)