Skip to content

Commit

Permalink
Extend coverage for CustomerGraphQL
Browse files Browse the repository at this point in the history
 - cover \Magento\CustomerGraphQl\Model\Customer\Address\ExtractCustomerAddressData

Signed-off-by: Tomash Khamlai <tomash.khamlai@gmail.com>
  • Loading branch information
TomashKhamlai committed Oct 24, 2019
1 parent cc599e5 commit 56382f1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function execute(AddressInterface $address): array
foreach ($addressData[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] as $attribute) {
$isArray = false;
if (is_array($attribute['value'])) {
// @ignoreCoverageStart
$isArray = true;
foreach ($attribute['value'] as $attributeValue) {
if (is_array($attributeValue)) {
Expand All @@ -116,6 +117,7 @@ public function execute(AddressInterface $address): array
$customAttributes[$attribute['attribute_code']] = implode(',', $attribute['value']);
continue;
}
// @ignoreCoverageEnd
}
if ($isArray) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,63 @@ public function testUpdateCustomerAddressWithMissingAttribute()
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
}

/**
* Test custom attributes of the customer's address
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
* @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_address_custom_attribute.php
*/
public function testUpdateCustomerAddressHasCustomAndExtensionAttributes()
{
/** @var AddressRepositoryInterface $addressRepositoryInterface */
$addressRepositoryInterface = Bootstrap::getObjectManager()->get(AddressRepositoryInterface::class);
/** @var \Magento\Customer\Api\Data\AddressInterface $address */
$address = $addressRepositoryInterface->getById(1);
$address
->setCustomAttribute('custom_attribute1', '')
->setCustomAttribute('custom_attribute2', '');
$addressRepositoryInterface->save($address);

$userName = 'customer@example.com';
$password = 'password';
$addressId = 1;

$mutation
= <<<MUTATION
mutation {
updateCustomerAddress(
id: {$addressId}
input: {
firstname: "John"
lastname: "Doe"
custom_attributes: [
{
attribute_code: "custom_attribute1"
value: "[line1,line2]"
}
{
attribute_code: "custom_attribute2"
value: "line3"
}
]
}
) {
custom_attributes {
attribute_code
value
}
}
}
MUTATION;

$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
$actualCustomAttributes = $response['updateCustomerAddress']['custom_attributes'];
$this->assertEquals($actualCustomAttributes['0']['attribute_code'], 'custom_attribute1');
$this->assertEquals($actualCustomAttributes['0']['value'], '[line1,line2]');
$this->assertEquals($actualCustomAttributes['1']['attribute_code'], 'custom_attribute2');
$this->assertEquals($actualCustomAttributes['1']['value'], 'line3');
}

/**
* Verify the fields for Customer address
*
Expand Down

0 comments on commit 56382f1

Please sign in to comment.