Skip to content

Commit b1b1b21

Browse files
LYNX-164: Add api-functional tests ensuring the attributes are returned by all queries according to sort order (#116)
1 parent f126202 commit b1b1b21

10 files changed

+122
-107
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ function (array $customAttribute) {
167167
},
168168
$attributes
169169
);
170+
usort($customAttributes['custom_attributesV2'], function (array $a, array $b) {
171+
$aPosition = $a['sort_order'];
172+
$bPosition = $b['sort_order'];
173+
return $aPosition <=> $bPosition;
174+
});
170175

171176
return $customAttributes;
172177
}

app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ function (array $customAttribute) {
8888
},
8989
$customerData['custom_attributes']
9090
);
91+
usort($customerData['custom_attributes'], function (array $a, array $b) {
92+
$aPosition = $a['sort_order'];
93+
$bPosition = $b['sort_order'];
94+
return $aPosition <=> $bPosition;
95+
});
9196
} else {
9297
$customerData['custom_attributes'] = [];
9398
}

app/code/Magento/CustomerGraphQl/Model/Customer/GetCustomAttributes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public function execute(string $entityType, array $customAttribute): ?array
7070
$entityType,
7171
$customAttribute['attribute_code']
7272
),
73-
'code' => $customAttribute['attribute_code']
73+
'code' => $customAttribute['attribute_code'],
74+
'sort_order' => $attr->getSortOrder() ?? ''
7475
];
7576

7677
if (in_array($attr->getFrontendInput(), $this->frontendInputs)) {

app/code/Magento/EavGraphQl/Model/Output/Value/GetCustomAttributes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public function execute(string $entity, string $code, string $value): ?array
6363

6464
$result = [
6565
'uid' => $this->uid->encode($entity, $code),
66-
'code' => $code
66+
'code' => $code,
67+
'sort_order' => $attr->getSortOrder() ?? ''
6768
];
6869

6970
if (in_array($attr->getFrontendInput(), $this->frontendInputs)) {

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'attribute_set_id' => AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS,
3737
'attribute_group_id' => 1,
3838
'attribute_code' => 'simple_attribute',
39-
'sort_order' => 1
39+
'sort_order' => 2
4040
],
4141
'simple_attribute',
4242
),
@@ -50,7 +50,7 @@
5050
'backend_model' => ArrayBackend::class,
5151
'attribute_code' => 'multiselect_attribute',
5252
'frontend_input' => 'multiselect',
53-
'sort_order' => 2
53+
'sort_order' => 1
5454
],
5555
'multiselect_attribute',
5656
),
@@ -60,7 +60,7 @@
6060
'entity_type' => AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS,
6161
'attribute_code' => '$multiselect_attribute.attribute_code$',
6262
'label' => 'line 1',
63-
'sort_order' => 10
63+
'sort_order' => 20
6464
],
6565
'multiselect_attribute_option1'
6666
),
@@ -70,7 +70,7 @@
7070
'entity_type' => AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS,
7171
'attribute_code' => '$multiselect_attribute.attribute_code$',
7272
'label' => 'line 2',
73-
'sort_order' => 20
73+
'sort_order' => 30
7474
],
7575
'multiselect_attribute_option2'
7676
),
@@ -80,7 +80,7 @@
8080
'entity_type' => AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS,
8181
'attribute_code' => '$multiselect_attribute.attribute_code$',
8282
'label' => 'line 3',
83-
'sort_order' => 30
83+
'sort_order' => 10
8484
],
8585
'multiselect_attribute_option3'
8686
),
@@ -242,24 +242,24 @@ public function testCreateCustomerAddressWithCustomAttributesV2()
242242
'custom_attributesV2' =>
243243
[
244244
0 =>
245-
[
246-
'code' => $this->simple_attribute->getAttributeCode(),
247-
'value' => 'brand new customer address value'
248-
],
249-
1 =>
250245
[
251246
'code' => $this->multiselect_attribute->getAttributeCode(),
252247
'selected_options' => [
253-
[
254-
'label' => $this->option2->getLabel(),
255-
'value' => $this->option2->getValue()
256-
],
257248
[
258249
'label' => $this->option3->getLabel(),
259250
'value' => $this->option3->getValue()
251+
],
252+
[
253+
'label' => $this->option2->getLabel(),
254+
'value' => $this->option2->getValue()
260255
]
261256
]
262257
],
258+
1 =>
259+
[
260+
'code' => $this->simple_attribute->getAttributeCode(),
261+
'value' => 'brand new customer address value'
262+
]
263263
],
264264
],
265265
],

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'attribute_set_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
3535
'attribute_group_id' => 1,
3636
'attribute_code' => 'random_attribute',
37-
'sort_order' => 1
37+
'sort_order' => 2
3838
],
3939
'random_attribute',
4040
),
@@ -48,7 +48,7 @@
4848
'backend_model' => ArrayBackend::class,
4949
'attribute_code' => 'multiselect_attribute',
5050
'frontend_input' => 'multiselect',
51-
'sort_order' => 2
51+
'sort_order' => 1
5252
],
5353
'multiselect_attribute',
5454
),
@@ -58,7 +58,7 @@
5858
'entity_type' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
5959
'attribute_code' => '$multiselect_attribute.attribute_code$',
6060
'label' => 'line 1',
61-
'sort_order' => 10
61+
'sort_order' => 20
6262
],
6363
'multiselect_attribute_option1'
6464
),
@@ -68,7 +68,7 @@
6868
'entity_type' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
6969
'attribute_code' => '$multiselect_attribute.attribute_code$',
7070
'label' => 'option 2',
71-
'sort_order' => 20
71+
'sort_order' => 30
7272
],
7373
'multiselect_attribute_option2'
7474
),
@@ -78,7 +78,7 @@
7878
'entity_type' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
7979
'attribute_code' => '$multiselect_attribute.attribute_code$',
8080
'label' => 'option 3',
81-
'sort_order' => 30
81+
'sort_order' => 10
8282
],
8383
'multiselect_attribute_option3'
8484
)
@@ -201,23 +201,23 @@ public function testCreateCustomerAccountWithCustomAttributes()
201201
'custom_attributes' =>
202202
[
203203
0 =>
204-
[
205-
'code' => $this->random_attribute->getAttributeCode(),
206-
'value' => 'new_value_for_attribute',
207-
],
208-
1 =>
209204
[
210205
'code' => $this->multiselect_attribute->getAttributeCode(),
211206
'selected_options' => [
212-
[
213-
'label' => $this->option2->getLabel(),
214-
'value' => $this->option2->getValue()
215-
],
216207
[
217208
'label' => $this->option3->getLabel(),
218209
'value' => $this->option3->getValue()
210+
],
211+
[
212+
'label' => $this->option2->getLabel(),
213+
'value' => $this->option2->getValue()
219214
]
220215
]
216+
],
217+
1 =>
218+
[
219+
'code' => $this->random_attribute->getAttributeCode(),
220+
'value' => 'new_value_for_attribute',
221221
]
222222
],
223223
],

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'backend_model' => ArrayBackend::class,
4141
'attribute_code' => 'labels',
4242
'attribute_group_id' => 1,
43+
'sort_order' => 2,
4344
],
4445
'multiselect_customer_address_attribute'
4546
),
@@ -60,7 +61,7 @@
6061
'entity_type' => AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS,
6162
'attribute_code' => '$multiselect_customer_address_attribute.attribute_code$',
6263
'label' => 'far',
63-
'sort_order' => 10
64+
'sort_order' => 20
6465
],
6566
'multiselect_customer_address_attribute_option_1'
6667
),
@@ -69,7 +70,7 @@
6970
[
7071
'entity_type' => AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS,
7172
'attribute_code' => '$multiselect_customer_address_attribute.attribute_code$',
72-
'sort_order' => 20,
73+
'sort_order' => 10,
7374
'label' => 'foreign',
7475
'is_default' => true
7576
],
@@ -90,17 +91,17 @@
9091
'default_billing' => true,
9192
'default_shipping' => true,
9293
'custom_attributes' => [
93-
[
94-
'attribute_code' => 'planet',
95-
'value' => 'Earth'
96-
],
9794
[
9895
'attribute_code' => 'labels',
9996
'selected_options' => [
10097
['value' => '$multiselect_customer_address_attribute_option_1.value$'],
10198
['value' => '$multiselect_customer_address_attribute_option_2.value$']
10299
],
103100
],
101+
[
102+
'attribute_code' => 'planet',
103+
'value' => 'Earth'
104+
]
104105
],
105106
],
106107
],
@@ -261,20 +262,20 @@ public function testGetCustomAddressAttributes()
261262
),
262263
'code' => $this->multiselectCustomerAddressAttribute->getAttributeCode(),
263264
'selected_options' => [
264-
[
265-
'uid' => $this->uid->encode(
266-
$this->multiselectCustomerAttributeOption1->getValue()
267-
),
268-
'label' => $this->multiselectCustomerAttributeOption1->getLabel(),
269-
'value' => $this->multiselectCustomerAttributeOption1->getValue(),
270-
],
271265
[
272266
'uid' => $this->uid->encode(
273267
$this->multiselectCustomerAttributeOption2->getValue()
274268
),
275269
'label' => $this->multiselectCustomerAttributeOption2->getLabel(),
276270
'value' => $this->multiselectCustomerAttributeOption2->getValue(),
277271
],
272+
[
273+
'uid' => $this->uid->encode(
274+
$this->multiselectCustomerAttributeOption1->getValue()
275+
),
276+
'label' => $this->multiselectCustomerAttributeOption1->getLabel(),
277+
'value' => $this->multiselectCustomerAttributeOption1->getValue(),
278+
]
278279
]
279280
]
280281
]
@@ -342,20 +343,20 @@ public function testGetFilteredCustomAddressAttributes()
342343
),
343344
'code' => $this->multiselectCustomerAddressAttribute->getAttributeCode(),
344345
'selected_options' => [
345-
[
346-
'uid' => $this->uid->encode(
347-
$this->multiselectCustomerAttributeOption1->getValue()
348-
),
349-
'label' => $this->multiselectCustomerAttributeOption1->getLabel(),
350-
'value' => $this->multiselectCustomerAttributeOption1->getValue(),
351-
],
352346
[
353347
'uid' => $this->uid->encode(
354348
$this->multiselectCustomerAttributeOption2->getValue()
355349
),
356350
'label' => $this->multiselectCustomerAttributeOption2->getLabel(),
357351
'value' => $this->multiselectCustomerAttributeOption2->getValue(),
358352
],
353+
[
354+
'uid' => $this->uid->encode(
355+
$this->multiselectCustomerAttributeOption1->getValue()
356+
),
357+
'label' => $this->multiselectCustomerAttributeOption1->getLabel(),
358+
'value' => $this->multiselectCustomerAttributeOption1->getValue(),
359+
]
359360
]
360361
]
361362
]

0 commit comments

Comments
 (0)