@@ -59,14 +59,6 @@ class AttributesFormTest extends GraphQlAbstract
5959 'used_in_forms ' => ['customer_address_edit ' ]
6060 ],
6161 '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 '
7062 )
7163 ]
7264 public function testAttributesForm (): void
@@ -75,22 +67,16 @@ public function testAttributesForm(): void
7567 $ attribute1 = DataFixtureStorageManager::getStorage ()->get ('attribute_1 ' );
7668 /** @var AttributeInterface $attribute2 */
7769 $ attribute2 = DataFixtureStorageManager::getStorage ()->get ('attribute_2 ' );
78- /** @var AttributeInterface $attribute3 */
79- $ attribute3 = DataFixtureStorageManager::getStorage ()->get ('attribute_3 ' );
80- $ attribute3 ->setIsVisible (false )->save ();
8170
8271 $ result = $ this ->graphQlQuery (sprintf (self ::QUERY , 'customer_register_address ' ));
8372
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 );
9480 }
9581
9682 public function testAttributesFormAdminHtmlForm (): void
@@ -152,13 +138,10 @@ public function testAttributesFormScope(): void
152138
153139 $ result = $ this ->graphQlQuery (sprintf (self ::QUERY , 'customer_register_address ' ));
154140
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 );
162145
163146 /** @var StoreInterface $store */
164147 $ store = DataFixtureStorageManager::getStorage ()->get ('store2 ' );
@@ -170,16 +153,31 @@ public function testAttributesFormScope(): void
170153 ['Store ' => $ store ->getCode ()]
171154 );
172155
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 ,
179161 sprintf (
180162 "Attribute '%s' not found in query response in website scope " ,
181163 $ attribute1 ->getAttributeCode ()
182164 )
183165 );
184166 }
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+ }
185183}
0 commit comments