@@ -59,14 +59,6 @@ class AttributesFormTest extends GraphQlAbstract
59
59
'used_in_forms ' => ['customer_address_edit ' ]
60
60
],
61
61
'attribute_2 '
62
- ),
63
- DataFixture(
64
- CustomerAttribute::class,
65
- [
66
- 'entity_type_id ' => AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS ,
67
- 'used_in_forms ' => ['customer_register_address ' ]
68
- ],
69
- 'attribute_3 '
70
62
)
71
63
]
72
64
public function testAttributesForm (): void
@@ -75,22 +67,16 @@ public function testAttributesForm(): void
75
67
$ attribute1 = DataFixtureStorageManager::getStorage ()->get ('attribute_1 ' );
76
68
/** @var AttributeInterface $attribute2 */
77
69
$ attribute2 = DataFixtureStorageManager::getStorage ()->get ('attribute_2 ' );
78
- /** @var AttributeInterface $attribute3 */
79
- $ attribute3 = DataFixtureStorageManager::getStorage ()->get ('attribute_3 ' );
80
- $ attribute3 ->setIsVisible (false )->save ();
81
70
82
71
$ result = $ this ->graphQlQuery (sprintf (self ::QUERY , 'customer_register_address ' ));
83
72
84
- foreach ($ result ['attributesForm ' ]['items ' ] as $ item ) {
85
- if (array_contains ($ item , $ attribute1 ->getAttributeCode ())) {
86
- return ;
87
- }
88
- $ this ->assertNotContains ($ attribute2 ->getAttributeCode (), $ item );
89
- $ this ->assertNotContains ($ attribute3 ->getAttributeCode (), $ item );
90
- $ this ->assertNotContains ('region_id ' , $ item );
91
- $ this ->assertNotContains ('country_id ' , $ item );
92
- }
93
- $ this ->fail (sprintf ("Attribute '%s' not found in query response " , $ attribute1 ->getAttributeCode ()));
73
+ $ this ->assertNotEmpty ($ result ['attributesForm ' ]['items ' ]);
74
+ $ codes = $ this ->getAttributeCodes ($ result ['attributesForm ' ]['items ' ]);
75
+
76
+ $ this ->assertContains ($ attribute1 ->getAttributeCode (), $ codes );
77
+ $ this ->assertContains ('country_id ' , $ codes );
78
+ $ this ->assertContains ('region_id ' , $ codes );
79
+ $ this ->assertNotContains ($ attribute2 ->getAttributeCode (), $ codes );
94
80
}
95
81
96
82
public function testAttributesFormAdminHtmlForm (): void
@@ -152,13 +138,10 @@ public function testAttributesFormScope(): void
152
138
153
139
$ result = $ this ->graphQlQuery (sprintf (self ::QUERY , 'customer_register_address ' ));
154
140
155
- foreach ($ result ['attributesForm ' ]['items ' ] as $ item ) {
156
- if (array_contains ($ item , $ attribute1 ->getAttributeCode ())) {
157
- $ this ->fail (
158
- sprintf ("Attribute '%s' found in query response in global scope " , $ attribute1 ->getAttributeCode ())
159
- );
160
- }
161
- }
141
+ $ this ->assertNotEmpty ($ result ['attributesForm ' ]['items ' ]);
142
+ $ codes = $ this ->getAttributeCodes ($ result ['attributesForm ' ]['items ' ]);
143
+
144
+ $ this ->assertNotContains ($ attribute1 ->getAttributeCode (), $ codes );
162
145
163
146
/** @var StoreInterface $store */
164
147
$ store = DataFixtureStorageManager::getStorage ()->get ('store2 ' );
@@ -170,16 +153,31 @@ public function testAttributesFormScope(): void
170
153
['Store ' => $ store ->getCode ()]
171
154
);
172
155
173
- foreach ($ result ['attributesForm ' ]['items ' ] as $ item ) {
174
- if (array_contains ($ item , $ attribute1 ->getAttributeCode ())) {
175
- return ;
176
- }
177
- }
178
- $ this ->fail (
156
+ $ this ->assertNotEmpty ($ result ['attributesForm ' ]['items ' ]);
157
+ $ codes = $ this ->getAttributeCodes ($ result ['attributesForm ' ]['items ' ]);
158
+ $ this ->assertContains (
159
+ $ attribute1 ->getAttributeCode (),
160
+ $ codes ,
179
161
sprintf (
180
162
"Attribute '%s' not found in query response in website scope " ,
181
163
$ attribute1 ->getAttributeCode ()
182
164
)
183
165
);
184
166
}
167
+
168
+ /**
169
+ * Retrieve an array of attribute codes based on an array of attributes data
170
+ *
171
+ * @param array $attributes
172
+ * @return array
173
+ */
174
+ private function getAttributeCodes (array $ attributes ): array
175
+ {
176
+ return array_map (
177
+ function (array $ attribute ) {
178
+ return $ attribute ['code ' ];
179
+ },
180
+ $ attributes
181
+ );
182
+ }
185
183
}
0 commit comments