Skip to content

Commit efabb8f

Browse files
authored
ENGCOM-6192: Extend coverage for CustomerGraphQL #1030
2 parents 9640575 + 44ddb4c commit efabb8f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function execute(AddressInterface $address): array
105105
foreach ($addressData[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] as $attribute) {
106106
$isArray = false;
107107
if (is_array($attribute['value'])) {
108+
// @ignoreCoverageStart
108109
$isArray = true;
109110
foreach ($attribute['value'] as $attributeValue) {
110111
if (is_array($attributeValue)) {
@@ -116,6 +117,7 @@ public function execute(AddressInterface $address): array
116117
$customAttributes[$attribute['attribute_code']] = implode(',', $attribute['value']);
117118
continue;
118119
}
120+
// @ignoreCoverageEnd
119121
}
120122
if ($isArray) {
121123
continue;

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,49 @@ public function testUpdateCustomerAddressWithMissingAttribute()
176176
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
177177
}
178178

179+
/**
180+
* Test custom attributes of the customer's address
181+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
182+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
183+
* @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_address_custom_attribute.php
184+
*/
185+
public function testUpdateCustomerAddressHasCustomAttributes()
186+
{
187+
$userName = 'customer@example.com';
188+
$password = 'password';
189+
$addressId = 1;
190+
$attributes = [
191+
[
192+
'attribute_code' => 'custom_attribute1',
193+
'value'=> '[new-value1,new-value2]'
194+
],
195+
[
196+
'attribute_code' => 'custom_attribute2',
197+
'value'=> '"new-value3"'
198+
]
199+
];
200+
$attributesFragment = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($attributes));
201+
$mutation
202+
= <<<MUTATION
203+
mutation {
204+
updateCustomerAddress(
205+
id: {$addressId}
206+
input: {
207+
custom_attributes: {$attributesFragment}
208+
}
209+
) {
210+
custom_attributes {
211+
attribute_code
212+
value
213+
}
214+
}
215+
}
216+
MUTATION;
217+
218+
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
219+
$this->assertEquals($attributes, $response['updateCustomerAddress']['custom_attributes']);
220+
}
221+
179222
/**
180223
* Verify the fields for Customer address
181224
*

0 commit comments

Comments
 (0)