Skip to content

Commit 56382f1

Browse files
committed
Extend coverage for CustomerGraphQL
- cover \Magento\CustomerGraphQl\Model\Customer\Address\ExtractCustomerAddressData Signed-off-by: Tomash Khamlai <tomash.khamlai@gmail.com>
1 parent cc599e5 commit 56382f1

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,63 @@ 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 testUpdateCustomerAddressHasCustomAndExtensionAttributes()
186+
{
187+
/** @var AddressRepositoryInterface $addressRepositoryInterface */
188+
$addressRepositoryInterface = Bootstrap::getObjectManager()->get(AddressRepositoryInterface::class);
189+
/** @var \Magento\Customer\Api\Data\AddressInterface $address */
190+
$address = $addressRepositoryInterface->getById(1);
191+
$address
192+
->setCustomAttribute('custom_attribute1', '')
193+
->setCustomAttribute('custom_attribute2', '');
194+
$addressRepositoryInterface->save($address);
195+
196+
$userName = 'customer@example.com';
197+
$password = 'password';
198+
$addressId = 1;
199+
200+
$mutation
201+
= <<<MUTATION
202+
mutation {
203+
updateCustomerAddress(
204+
id: {$addressId}
205+
input: {
206+
firstname: "John"
207+
lastname: "Doe"
208+
custom_attributes: [
209+
{
210+
attribute_code: "custom_attribute1"
211+
value: "[line1,line2]"
212+
}
213+
{
214+
attribute_code: "custom_attribute2"
215+
value: "line3"
216+
}
217+
]
218+
}
219+
) {
220+
custom_attributes {
221+
attribute_code
222+
value
223+
}
224+
}
225+
}
226+
MUTATION;
227+
228+
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
229+
$actualCustomAttributes = $response['updateCustomerAddress']['custom_attributes'];
230+
$this->assertEquals($actualCustomAttributes['0']['attribute_code'], 'custom_attribute1');
231+
$this->assertEquals($actualCustomAttributes['0']['value'], '[line1,line2]');
232+
$this->assertEquals($actualCustomAttributes['1']['attribute_code'], 'custom_attribute2');
233+
$this->assertEquals($actualCustomAttributes['1']['value'], 'line3');
234+
}
235+
179236
/**
180237
* Verify the fields for Customer address
181238
*

0 commit comments

Comments
 (0)