Skip to content

Commit b688f57

Browse files
committed
MC-20689: Admin: Create new attribute set
1 parent 9310b48 commit b688f57

File tree

1 file changed

+42
-10
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set

1 file changed

+42
-10
lines changed

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

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
use Magento\Eav\Api\AttributeManagementInterface;
1616
use Magento\Eav\Api\AttributeSetRepositoryInterface;
1717
use Magento\Eav\Api\Data\AttributeSetInterface;
18+
use Magento\Eav\Model\Config;
1819
use Magento\Framework\Api\DataObjectHelper;
1920
use Magento\Framework\Api\SearchCriteriaBuilder;
2021
use Magento\Framework\App\Request\Http as HttpRequest;
2122
use Magento\Framework\Logger\Handler\System;
2223
use Magento\Framework\Logger\Monolog;
2324
use Magento\Framework\Message\MessageInterface;
25+
use Magento\Framework\Serialize\Serializer\Json;
2426
use Magento\TestFramework\Helper\Bootstrap;
2527
use Magento\TestFramework\TestCase\AbstractBackendController;
2628

@@ -71,6 +73,16 @@ class SaveTest extends AbstractBackendController
7173
*/
7274
private $attributeSetRepository;
7375

76+
/**
77+
* @var Config
78+
*/
79+
private $eavConfig;
80+
81+
/**
82+
* @var Json
83+
*/
84+
private $json;
85+
7486
/**
7587
* @inheritDoc
7688
*/
@@ -89,6 +101,8 @@ public function setUp()
89101
$this->attributeRepository = $this->_objectManager->get(Repository::class);
90102
$this->dataObjectHelper = $this->_objectManager->get(DataObjectHelper::class);
91103
$this->attributeSetRepository = $this->_objectManager->get(AttributeSetRepositoryInterface::class);
104+
$this->eavConfig = $this->_objectManager->get(Config::class);
105+
$this->json = $this->_objectManager->get(Json::class);
92106
}
93107

94108
/**
@@ -109,7 +123,10 @@ public function tearDown()
109123
*/
110124
public function testCreateNewAttributeSetBasedOnDefaultAttributeSet(): void
111125
{
112-
$this->createAttributeSetBySkeletonAndAssert('Attribute set name for test', 4);
126+
$this->createAttributeSetBySkeletonAndAssert(
127+
'Attribute set name for test',
128+
$this->getCatalogProductDefaultAttributeSetId()
129+
);
113130
}
114131

115132
/**
@@ -143,12 +160,12 @@ public function testGotErrorDuringCreateAttributeSetWithoutName(): void
143160
$this->getRequest()->setPostValue(
144161
[
145162
'gotoEdit' => '1',
146-
'skeleton_set' => 4,
163+
'skeleton_set' => $this->getCatalogProductDefaultAttributeSetId(),
147164
]
148165
);
149166
$this->dispatch('backend/catalog/product_set/save/');
150167
$this->assertSessionMessages(
151-
$this->contains('The attribute set name is empty. Enter the name and try again.'),
168+
$this->equalTo([(string)__('The attribute set name is empty. Enter the name and try again.')]),
152169
MessageInterface::TYPE_ERROR
153170
);
154171
}
@@ -167,7 +184,7 @@ public function testAlreadyExistsExceptionProcessingWhenGroupCodeIsDuplicated():
167184
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
168185
$this->getRequest()->setPostValue(
169186
'data',
170-
json_encode(
187+
$this->json->serialize(
171188
[
172189
'attribute_set_name' => 'attribute_set_test',
173190
'groups' => [
@@ -183,12 +200,12 @@ public function testAlreadyExistsExceptionProcessingWhenGroupCodeIsDuplicated():
183200
);
184201
$this->dispatch('backend/catalog/product_set/save/id/' . $attributeSet->getAttributeSetId());
185202

186-
$jsonResponse = json_decode($this->getResponse()->getBody());
203+
$jsonResponse = $this->json->unserialize($this->getResponse()->getBody());
187204
$this->assertNotNull($jsonResponse);
188-
$this->assertEquals(1, $jsonResponse->error);
205+
$this->assertEquals(1, $jsonResponse['error']);
189206
$this->assertContains(
190-
'Attribute group with same code already exist. Please rename "attribute-group-name" group',
191-
$jsonResponse->message
207+
(string)__('Attribute group with same code already exist. Please rename "attribute-group-name" group'),
208+
$jsonResponse['message']
192209
);
193210
}
194211

@@ -265,9 +282,10 @@ private function getAttributeSetByName(string $attributeSetName): ?AttributeSetI
265282
$searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
266283
$searchCriteriaBuilder->addFilter('attribute_set_name', $attributeSetName);
267284
$result = $this->attributeSetRepository->getList($searchCriteriaBuilder->create());
285+
268286
$items = $result->getItems();
269287

270-
return $result->getTotalCount() ? array_pop($items) : null;
288+
return array_pop($items);
271289
}
272290

273291
/**
@@ -276,6 +294,7 @@ private function getAttributeSetByName(string $attributeSetName): ?AttributeSetI
276294
*
277295
* @param string $attributeSetName
278296
* @param int $skeletonAttributeSetId
297+
* @return void
279298
*/
280299
private function createAttributeSetBySkeletonAndAssert(
281300
string $attributeSetName,
@@ -308,6 +327,7 @@ private function createAttributeSetBySkeletonAndAssert(
308327
*
309328
* @param AttributeSetInterface $createdAttributeSet
310329
* @param AttributeSetInterface $existAttributeSet
330+
* @return void
311331
*/
312332
private function assertAttributeSetsAttributesAreEquals(
313333
AttributeSetInterface $createdAttributeSet,
@@ -327,7 +347,19 @@ private function assertAttributeSetsAttributesAreEquals(
327347
);
328348
$this->assertEquals(count($expectedAttributeIds), count($actualAttributeIds));
329349
foreach ($actualAttributeIds as $attributeId) {
330-
$this->assertTrue(in_array($attributeId, $expectedAttributeIds, true));
350+
$this->assertContains($attributeId, $expectedAttributeIds);
331351
}
332352
}
353+
354+
/**
355+
* Retrieve default catalog product attribute set ID.
356+
*
357+
* @return int
358+
*/
359+
private function getCatalogProductDefaultAttributeSetId(): int
360+
{
361+
return (int)$this->eavConfig
362+
->getEntityType(ProductAttributeInterface::ENTITY_TYPE_CODE)
363+
->getDefaultAttributeSetId();
364+
}
333365
}

0 commit comments

Comments
 (0)