17
17
use Magento \Framework \App \Request \Http as HttpRequest ;
18
18
use Magento \Framework \Message \MessageInterface ;
19
19
use Magento \Framework \Serialize \Serializer \Json ;
20
- use Magento \TestFramework \Eav \Model \AttributeSet ;
20
+ use Magento \TestFramework \Eav \Model \GetAttributeSetByName ;
21
21
use Magento \TestFramework \TestCase \AbstractBackendController ;
22
22
23
23
/**
@@ -46,9 +46,9 @@ class UpdateTest extends AbstractBackendController
46
46
private $ attributeGroupCollectionFactory ;
47
47
48
48
/**
49
- * @var AttributeSet
49
+ * @var GetAttributeSetByName
50
50
*/
51
- private $ attributeSet ;
51
+ private $ getAttributeSetByName ;
52
52
53
53
/**
54
54
* @inheritdoc
@@ -60,7 +60,7 @@ protected function setUp()
60
60
$ this ->attributeSetRepository = $ this ->_objectManager ->get (AttributeSetRepositoryInterface::class);
61
61
$ this ->attributeManagement = $ this ->_objectManager ->get (AttributeManagementInterface::class);
62
62
$ this ->attributeGroupCollectionFactory = $ this ->_objectManager ->get (CollectionFactory::class);
63
- $ this ->attributeSet = $ this ->_objectManager ->get (AttributeSet ::class);
63
+ $ this ->getAttributeSetByName = $ this ->_objectManager ->get (GetAttributeSetByName ::class);
64
64
}
65
65
66
66
/**
@@ -74,7 +74,7 @@ protected function setUp()
74
74
*/
75
75
public function testUpdateAttributeSetName (): void
76
76
{
77
- $ attributeSet = $ this ->attributeSet -> getAttributeSetByName ('new_attribute_set ' );
77
+ $ attributeSet = $ this ->getAttributeSetByName -> execute ('new_attribute_set ' );
78
78
$ currentAttrSetName = $ attributeSet ->getAttributeSetName ();
79
79
$ this ->assertNotNull ($ attributeSet );
80
80
$ postData = $ this ->prepareDataToRequest ($ attributeSet );
@@ -102,7 +102,7 @@ public function testUpdateAttributeSetName(): void
102
102
*/
103
103
public function testUpdateAttributeSetWithNewGroup (): void
104
104
{
105
- $ currentAttrSet = $ this ->attributeSet -> getAttributeSetByName ('new_attribute_set ' );
105
+ $ currentAttrSet = $ this ->getAttributeSetByName -> execute ('new_attribute_set ' );
106
106
$ this ->assertNotNull ($ currentAttrSet );
107
107
$ attrSetId = (int )$ currentAttrSet ->getAttributeSetId ();
108
108
$ currentAttrGroups = $ this ->getAttributeSetGroupCollection ($ attrSetId )->getItems ();
@@ -140,18 +140,14 @@ public function testUpdateAttributeSetWithNewGroup(): void
140
140
public function testDeleteCustomGroupFromCustomAttributeSet (): void
141
141
{
142
142
$ testGroupName = 'Test attribute group name ' ;
143
- $ currentAttrSet = $ this ->attributeSet -> getAttributeSetByName ('new_attribute_set ' );
143
+ $ currentAttrSet = $ this ->getAttributeSetByName -> execute ('new_attribute_set ' );
144
144
$ this ->assertNotNull ($ currentAttrSet );
145
145
$ 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
+ );
155
151
$ this ->assertNotNull ($ customGroup );
156
152
$ postData = $ this ->prepareDataToRequest ($ currentAttrSet );
157
153
$ postData ['removeGroups ' ] = [
@@ -163,7 +159,7 @@ public function testDeleteCustomGroupFromCustomAttributeSet(): void
163
159
MessageInterface::TYPE_SUCCESS
164
160
);
165
161
$ updatedAttrGroups = $ this ->getAttributeSetGroupCollection ($ attrSetId )->getItems ();
166
- $ diffGroups = array_diff_key ($ currentAttrGroups , $ updatedAttrGroups );
162
+ $ diffGroups = array_diff_key ($ currentAttrGroupsCollection -> getItems () , $ updatedAttrGroups );
167
163
$ this ->assertCount (1 , $ diffGroups );
168
164
/** @var AttributeGroupInterface $deletedGroup */
169
165
$ deletedGroup = reset ($ diffGroups );
0 commit comments