Skip to content

Commit 0fc0384

Browse files
committed
MC-20691: Admin: Update attribute set
1 parent dabb907 commit 0fc0384

File tree

5 files changed

+26
-42
lines changed

5 files changed

+26
-42
lines changed

dev/tests/integration/framework/Magento/TestFramework/Eav/Model/AttributeSet.php renamed to dev/tests/integration/framework/Magento/TestFramework/Eav/Model/GetAttributeSetByName.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Attribute set additional functions.
1616
*/
17-
class AttributeSet
17+
class GetAttributeSetByName
1818
{
1919
/**
2020
* @var SearchCriteriaBuilder
@@ -44,7 +44,7 @@ public function __construct(
4444
* @param string $attributeSetName
4545
* @return AttributeSetInterface|null
4646
*/
47-
public function getAttributeSetByName(string $attributeSetName): ?AttributeSetInterface
47+
public function execute(string $attributeSetName): ?AttributeSetInterface
4848
{
4949
$this->searchCriteriaBuilder->addFilter('attribute_set_name', $attributeSetName);
5050
$searchCriteria = $this->searchCriteriaBuilder->create();

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/UpdateTest.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Framework\App\Request\Http as HttpRequest;
1818
use Magento\Framework\Message\MessageInterface;
1919
use Magento\Framework\Serialize\Serializer\Json;
20-
use Magento\TestFramework\Eav\Model\AttributeSet;
20+
use Magento\TestFramework\Eav\Model\GetAttributeSetByName;
2121
use Magento\TestFramework\TestCase\AbstractBackendController;
2222

2323
/**
@@ -46,9 +46,9 @@ class UpdateTest extends AbstractBackendController
4646
private $attributeGroupCollectionFactory;
4747

4848
/**
49-
* @var AttributeSet
49+
* @var GetAttributeSetByName
5050
*/
51-
private $attributeSet;
51+
private $getAttributeSetByName;
5252

5353
/**
5454
* @inheritdoc
@@ -60,7 +60,7 @@ protected function setUp()
6060
$this->attributeSetRepository = $this->_objectManager->get(AttributeSetRepositoryInterface::class);
6161
$this->attributeManagement = $this->_objectManager->get(AttributeManagementInterface::class);
6262
$this->attributeGroupCollectionFactory = $this->_objectManager->get(CollectionFactory::class);
63-
$this->attributeSet = $this->_objectManager->get(AttributeSet::class);
63+
$this->getAttributeSetByName = $this->_objectManager->get(GetAttributeSetByName::class);
6464
}
6565

6666
/**
@@ -74,7 +74,7 @@ protected function setUp()
7474
*/
7575
public function testUpdateAttributeSetName(): void
7676
{
77-
$attributeSet = $this->attributeSet->getAttributeSetByName('new_attribute_set');
77+
$attributeSet = $this->getAttributeSetByName->execute('new_attribute_set');
7878
$currentAttrSetName = $attributeSet->getAttributeSetName();
7979
$this->assertNotNull($attributeSet);
8080
$postData = $this->prepareDataToRequest($attributeSet);
@@ -102,7 +102,7 @@ public function testUpdateAttributeSetName(): void
102102
*/
103103
public function testUpdateAttributeSetWithNewGroup(): void
104104
{
105-
$currentAttrSet = $this->attributeSet->getAttributeSetByName('new_attribute_set');
105+
$currentAttrSet = $this->getAttributeSetByName->execute('new_attribute_set');
106106
$this->assertNotNull($currentAttrSet);
107107
$attrSetId = (int)$currentAttrSet->getAttributeSetId();
108108
$currentAttrGroups = $this->getAttributeSetGroupCollection($attrSetId)->getItems();
@@ -140,18 +140,14 @@ public function testUpdateAttributeSetWithNewGroup(): void
140140
public function testDeleteCustomGroupFromCustomAttributeSet(): void
141141
{
142142
$testGroupName = 'Test attribute group name';
143-
$currentAttrSet = $this->attributeSet->getAttributeSetByName('new_attribute_set');
143+
$currentAttrSet = $this->getAttributeSetByName->execute('new_attribute_set');
144144
$this->assertNotNull($currentAttrSet);
145145
$attrSetId = (int)$currentAttrSet->getAttributeSetId();
146-
$currentAttrGroups = $this->getAttributeSetGroupCollection($attrSetId)->getItems();
147-
$customGroup = null;
148-
/** @var AttributeGroupInterface $attrGroup */
149-
foreach ($currentAttrGroups as $attrGroup) {
150-
if ($attrGroup->getAttributeGroupName() === $testGroupName) {
151-
$customGroup = $attrGroup;
152-
break;
153-
}
154-
}
146+
$currentAttrGroupsCollection = $this->getAttributeSetGroupCollection($attrSetId);
147+
$customGroup = $currentAttrGroupsCollection->getItemByColumnValue(
148+
AttributeGroupInterface::GROUP_NAME,
149+
$testGroupName
150+
);
155151
$this->assertNotNull($customGroup);
156152
$postData = $this->prepareDataToRequest($currentAttrSet);
157153
$postData['removeGroups'] = [
@@ -163,7 +159,7 @@ public function testDeleteCustomGroupFromCustomAttributeSet(): void
163159
MessageInterface::TYPE_SUCCESS
164160
);
165161
$updatedAttrGroups = $this->getAttributeSetGroupCollection($attrSetId)->getItems();
166-
$diffGroups = array_diff_key($currentAttrGroups, $updatedAttrGroups);
162+
$diffGroups = array_diff_key($currentAttrGroupsCollection->getItems(), $updatedAttrGroups);
167163
$this->assertCount(1, $diffGroups);
168164
/** @var AttributeGroupInterface $deletedGroup */
169165
$deletedGroup = reset($diffGroups);

dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_set_based_on_default_with_custom_group_rollback.php

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

8-
use Magento\Catalog\Api\Data\ProductAttributeInterface;
98
use Magento\Eav\Api\AttributeSetRepositoryInterface;
10-
use Magento\Eav\Api\Data\AttributeSetInterface;
11-
use Magento\Eav\Model\Entity\Type;
12-
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection;
13-
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory;
9+
use Magento\TestFramework\Eav\Model\GetAttributeSetByName;
1410
use Magento\TestFramework\Helper\Bootstrap;
1511

1612
$objectManager = Bootstrap::getObjectManager();
13+
/** @var GetAttributeSetByName $getAttributeSetByName */
14+
$getAttributeSetByName = $objectManager->get(GetAttributeSetByName::class);
1715
/** @var AttributeSetRepositoryInterface $attributeSetRepository */
1816
$attributeSetRepository = $objectManager->get(AttributeSetRepositoryInterface::class);
19-
/** @var Type $entityType */
20-
$entityType = $objectManager->create(Type::class)->loadByCode(ProductAttributeInterface::ENTITY_TYPE_CODE);
21-
/** @var Collection $attributeSetCollection */
22-
$attributeSetCollection = $objectManager->create(CollectionFactory::class)->create();
23-
$attributeSetCollection->addFilter('attribute_set_name', 'new_attribute_set');
24-
$attributeSetCollection->addFilter('entity_type_id', $entityType->getId());
25-
$attributeSetCollection->setOrder('attribute_set_id');
26-
$attributeSetCollection->setPageSize(1);
27-
$attributeSetCollection->load();
28-
/** @var AttributeSetInterface $attributeSet */
29-
$attributeSet = $attributeSetCollection->fetchItem();
17+
$attributeSet = $getAttributeSetByName->execute('new_attribute_set');
3018

3119
if ($attributeSet) {
3220
$attributeSetRepository->delete($attributeSet);

dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_test_attribute_set.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1010
use Magento\Catalog\Model\Product\Visibility;
1111
use Magento\Catalog\Model\ProductFactory;
12-
use Magento\TestFramework\Eav\Model\AttributeSet;
12+
use Magento\TestFramework\Eav\Model\GetAttributeSetByName;
1313
use Magento\TestFramework\Helper\Bootstrap;
1414
use Magento\Store\Model\StoreManagerInterface;
1515

@@ -20,13 +20,12 @@
2020
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
2121
/** @var ProductFactory $productFactory */
2222
$productFactory = $objectManager->get(ProductFactory::class);
23-
/** @var AttributeSet $attributeSet */
24-
$attributeSet = $objectManager->get(AttributeSet::class);
25-
$customAttributeSet = $attributeSet->getAttributeSetByName('new_attribute_set');
23+
/** @var GetAttributeSetByName $attributeSet */
24+
$attributeSet = $objectManager->get(GetAttributeSetByName::class);
25+
$customAttributeSet = $attributeSet->execute('new_attribute_set');
2626
$product = $productFactory->create();
2727
$product
2828
->setTypeId('simple')
29-
->setId(1)
3029
->setAttributeSetId($customAttributeSet->getAttributeSetId())
3130
->setWebsiteIds([1])
3231
->setStoreId($storeManager->getStore('admin')->getId())

dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_test_attribute_set_rollback.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\CatalogInventory\Model\StockRegistryStorage;
10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Framework\Registry;
1112
use Magento\TestFramework\Helper\Bootstrap;
1213

@@ -22,8 +23,8 @@
2223
try {
2324
$product = $productRepository->get('simple');
2425
$productRepository->delete($product);
25-
} catch (\Exception $e) {
26-
26+
} catch (NoSuchEntityException $e) {
27+
//Product already deleted.
2728
}
2829
$stockRegistryStorage->clean();
2930
$registry->unregister('isSecureArea');

0 commit comments

Comments
 (0)