Skip to content

Commit a6c6658

Browse files
committed
MAGETWO-63190: L4 Exception on configurable product in Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php
1 parent ed746e3 commit a6c6658

File tree

3 files changed

+135
-2
lines changed

3 files changed

+135
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Model\Product;
99
use Magento\Framework\Registry;
1010
use Magento\TestFramework\ObjectManager;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
1112

1213
/**
1314
* @magentoAppArea adminhtml
@@ -16,13 +17,15 @@ class ProductTest extends \Magento\TestFramework\TestCase\AbstractBackendControl
1617
{
1718
/**
1819
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
20+
* @magentoDataFixture Magento/ConfigurableProduct/_files/associated_products.php
1921
*/
2022
public function testSaveActionAssociatedProductIds()
2123
{
22-
$associatedProductIds = [3, 14, 15, 92];
24+
$associatedProductIds = ['3', '14', '15', '92'];
2325
$associatedProductIdsJSON = json_encode($associatedProductIds);
2426
$this->getRequest()->setPostValue(
2527
[
28+
'id' => 1,
2629
'attributes' => [$this->_getConfigurableAttribute()->getId()],
2730
'associated_product_ids_serialized' => $associatedProductIdsJSON,
2831
]
@@ -35,8 +38,21 @@ public function testSaveActionAssociatedProductIds()
3538

3639
/** @var $product Product */
3740
$product = $objectManager->get(Registry::class)->registry('current_product');
41+
$configurableProductLinks = array_values($product->getExtensionAttributes()->getConfigurableProductLinks());
42+
self::assertEquals(
43+
$associatedProductIds,
44+
$configurableProductLinks,
45+
'Product links are not available in the registry'
46+
);
3847

39-
self::assertEquals($associatedProductIds, $product->getExtensionAttributes()->getConfigurableProductLinks());
48+
/** @var $product \Magento\Catalog\Api\Data\ProductInterface */
49+
$product = $objectManager->get(ProductRepositoryInterface::class)->getById(1, false, null, true);
50+
$configurableProductLinks = array_values($product->getExtensionAttributes()->getConfigurableProductLinks());
51+
self::assertEquals(
52+
$associatedProductIds,
53+
$configurableProductLinks,
54+
'Product links are not available in the database'
55+
);
4056
}
4157

4258
/**
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var $product \Magento\Catalog\Model\Product */
8+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
9+
->create(\Magento\Catalog\Model\Product::class);
10+
$product
11+
->setTypeId('simple')
12+
->setId(3)
13+
->setAttributeSetId(4)
14+
->setWebsiteIds([1])
15+
->setName('Simple Product 3')
16+
->setSku('simple_3')
17+
->setPrice(10)
18+
->setMetaTitle('meta title 3')
19+
->setMetaKeyword('meta keyword 3')
20+
->setMetaDescription('meta description 3')
21+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
22+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
23+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1])
24+
->setQty(22)
25+
->save();
26+
27+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
28+
->create(\Magento\Catalog\Model\Product::class);
29+
$product
30+
->setTypeId('simple')
31+
->setId(14)
32+
->setAttributeSetId(4)
33+
->setWebsiteIds([1])
34+
->setName('Simple Product 14')
35+
->setSku('simple_14')
36+
->setPrice(10)
37+
->setMetaTitle('meta title 14')
38+
->setMetaKeyword('meta keyword 14')
39+
->setMetaDescription('meta description 14')
40+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
41+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
42+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1])
43+
->setQty(22)
44+
->save();
45+
46+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
47+
->create(\Magento\Catalog\Model\Product::class);
48+
$product
49+
->setTypeId('simple')
50+
->setId(15)
51+
->setAttributeSetId(4)
52+
->setWebsiteIds([1])
53+
->setName('Simple Product 15')
54+
->setSku('simple_15')
55+
->setPrice(10)
56+
->setMetaTitle('meta title 15')
57+
->setMetaKeyword('meta keyword 15')
58+
->setMetaDescription('meta description 15')
59+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
60+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
61+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1])
62+
->setQty(22)
63+
->save();
64+
65+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
66+
->create(\Magento\Catalog\Model\Product::class);
67+
$product
68+
->setTypeId('simple')
69+
->setId(92)
70+
->setAttributeSetId(4)
71+
->setWebsiteIds([1])
72+
->setName('Simple Product 92')
73+
->setSku('simple_92')
74+
->setPrice(10)
75+
->setMetaTitle('meta title 92')
76+
->setMetaKeyword('meta keyword 92')
77+
->setMetaDescription('meta description 92')
78+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
79+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
80+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 22, 'is_in_stock' => 1])
81+
->setQty(22)
82+
->save();
83+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
9+
/** @var \Magento\Framework\Registry $registry */
10+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
11+
12+
$registry->unregister('isSecureArea');
13+
$registry->register('isSecureArea', true);
14+
15+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
16+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
17+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
18+
19+
foreach (['simple_3', 'simple_14', 'simple_15', 'simple_92'] as $sku) {
20+
try {
21+
$product = $productRepository->get($sku, false, null, true);
22+
23+
$stockStatus = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Status::class);
24+
$stockStatus->load($product->getEntityId(), 'product_id');
25+
$stockStatus->delete();
26+
27+
$productRepository->delete($product);
28+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
29+
//Product already removed
30+
}
31+
}
32+
33+
$registry->unregister('isSecureArea');
34+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)