Skip to content

Commit ec8b705

Browse files
committed
LYNX-100: Fix WebAPI tests
1 parent de22909 commit ec8b705

File tree

3 files changed

+53
-28
lines changed

3 files changed

+53
-28
lines changed

app/code/Magento/EavGraphQl/Model/Output/GetAttributeData.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function execute(
6262
): array {
6363
return [
6464
'uid' => $this->attributeUid->encode($entityType, $attribute->getAttributeCode()),
65-
'attribute_code' => $attribute->getAttributeCode(),
65+
'code' => $attribute->getAttributeCode(),
6666
'label' => $attribute->getStoreLabel($storeId),
6767
'sort_order' => $attribute->getPosition(),
6868
'entity_type' => $this->enumLookup->getEnumValueFromField(
@@ -95,16 +95,18 @@ private function getOptions(AttributeInterface $attribute): array
9595
return array_filter(
9696
array_map(
9797
function (AttributeOptionInterface $option) use ($attribute) {
98-
if (empty($option->getValue()) && empty($option->getLabel())) {
98+
$value = (string)$option->getValue();
99+
$label = (string)$option->getLabel();
100+
if (empty(trim($value)) && empty(trim($label))) {
99101
return null;
100102
}
101103
return [
102-
'uid' => $this->uid->encode($option->getValue()),
103-
'label' => $option->getLabel(),
104-
'value' => $option->getValue(),
104+
'uid' => $this->uid->encode($value),
105+
'label' => $label,
106+
'value' => $value,
105107
'is_default' =>
106108
$attribute->getDefaultValue() ?
107-
in_array($option->getValue(), explode(',', $attribute->getDefaultValue())) : null
109+
in_array($value, explode(',', $attribute->getDefaultValue())) : null
108110
];
109111
},
110112
$attribute->getOptions()

app/code/Magento/EavGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum AttributeMetadataErrorType @doc(description: "Attribute metadata retrieval
6767

6868
interface AttributeMetadataInterface @typeResolver(class: "Magento\\EavGraphQl\\Model\\TypeResolver\\AttributeMetadata") @doc(description: "An interface containing fields that define the EAV attribute."){
6969
uid: ID! @doc(description: "The unique ID of an attribute. Based on entity type and attribute code")
70-
attribute_code: String! @doc(description: "The unique identifier for an attribute code. This value should be in lowercase letters without spaces.")
70+
code: String! @doc(description: "The unique identifier for an attribute code. This value should be in lowercase letters without spaces.")
7171
label: String @doc(description: "The label assigned to the attribute.")
7272
entity_type: AttributeEntityTypeEnum! @doc(description: "The type of entity that defines the attribute.")
7373
frontend_input: AttributeFrontendInputEnum @doc(description: "The frontend input type of the attribute.")

dev/tests/api-functional/testsuite/Magento/GraphQl/EavGraphQl/AttributesListTest.php

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
use Magento\Customer\Api\CustomerMetadataInterface;
1111
use Magento\Catalog\Setup\CategorySetup;
1212
use Magento\Eav\Test\Fixture\Attribute;
13+
use Magento\Eav\Api\Data\AttributeInterface;
1314
use Magento\Sales\Setup\SalesSetup;
1415
use Magento\TestFramework\Fixture\DataFixture;
1516
use Magento\TestFramework\TestCase\GraphQlAbstract;
17+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1618

1719
/**
1820
* Test EAV attributes metadata retrieval for entity type via GraphQL API
@@ -26,47 +28,53 @@ class AttributesListTest extends GraphQlAbstract
2628
Attribute::class,
2729
[
2830
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
29-
'attribute_code' => 'attribute_0'
31+
'frontend_input' => 'boolean',
32+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
3033
],
3134
'attribute0'
3235
),
3336
DataFixture(
3437
Attribute::class,
3538
[
3639
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
37-
'attribute_code' => 'attribute_1'
40+
'frontend_input' => 'boolean',
41+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
3842
],
3943
'attribute1'
4044
),
4145
DataFixture(
4246
Attribute::class,
4347
[
4448
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
45-
'attribute_code' => 'attribute_2'
49+
'frontend_input' => 'boolean',
50+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
4651
],
4752
'attribute2'
4853
),
4954
DataFixture(
5055
Attribute::class,
5156
[
5257
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
53-
'attribute_code' => 'attribute_3'
58+
'frontend_input' => 'boolean',
59+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
5460
],
5561
'attribute3'
5662
),
5763
DataFixture(
5864
Attribute::class,
5965
[
6066
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
61-
'attribute_code' => 'attribute_4'
67+
'frontend_input' => 'boolean',
68+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
6269
],
6370
'attribute4'
6471
),
6572
DataFixture(
6673
Attribute::class,
6774
[
6875
'entity_type_id' => SalesSetup::CREDITMEMO_PRODUCT_ENTITY_TYPE_ID,
69-
'attribute_code' => 'attribute_5'
76+
'frontend_input' => 'boolean',
77+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
7078
],
7179
'attribute5'
7280
)
@@ -78,7 +86,7 @@ public function testAttributesList(): void
7886
attributesList(entity_type: CUSTOMER) {
7987
items {
8088
uid
81-
attribute_code
89+
code
8290
}
8391
errors {
8492
type
@@ -91,33 +99,43 @@ public function testAttributesList(): void
9199
$this->assertArrayHasKey('items', $queryResult['attributesList'], 'Query result does not contain items');
92100
$this->assertGreaterThanOrEqual(3, count($queryResult['attributesList']['items']));
93101

102+
/** @var AttributeInterface $attribute */
103+
$attribute5 = DataFixtureStorageManager::getStorage()->get('attribute5');
104+
105+
/** @var AttributeInterface $attribute */
106+
$attribute0 = DataFixtureStorageManager::getStorage()->get('attribute0');
107+
/** @var AttributeInterface $attribute */
108+
$attribute1 = DataFixtureStorageManager::getStorage()->get('attribute1');
109+
/** @var AttributeInterface $attribute */
110+
$attribute2 = DataFixtureStorageManager::getStorage()->get('attribute2');
111+
94112
$this->assertEquals(
95-
'attribute_0',
96-
$this->getAttributeByCode($queryResult['attributesList']['items'], 'attribute_0')['attribute_code'],
113+
$attribute0->getAttributeCode(),
114+
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute0->getAttributeCode())['code'],
97115
self::ATTRIBUTE_NOT_FOUND_ERROR
98116
);
99117

100118
$this->assertEquals(
101-
'attribute_1',
102-
$this->getAttributeByCode($queryResult['attributesList']['items'], 'attribute_1')['attribute_code'],
119+
$attribute1->getAttributeCode(),
120+
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute1->getAttributeCode())['code'],
103121
self::ATTRIBUTE_NOT_FOUND_ERROR
104122
);
105123
$this->assertEquals(
106-
'attribute_2',
107-
$this->getAttributeByCode($queryResult['attributesList']['items'], 'attribute_2')['attribute_code'],
124+
$attribute2->getAttributeCode(),
125+
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute2->getAttributeCode())['code'],
108126
self::ATTRIBUTE_NOT_FOUND_ERROR
109127
);
110128
$this->assertEquals(
111129
[],
112-
$this->getAttributeByCode($queryResult['attributesList']['items'], 'attribute_5')
130+
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute5->getAttributeCode())
113131
);
114132

115133
$queryResult = $this->graphQlQuery(<<<QRY
116134
{
117135
attributesList(entity_type: CATALOG_PRODUCT) {
118136
items {
119137
uid
120-
attribute_code
138+
code
121139
}
122140
errors {
123141
type
@@ -129,19 +147,24 @@ public function testAttributesList(): void
129147
$this->assertArrayHasKey('items', $queryResult['attributesList'], 'Query result does not contain items');
130148
$this->assertGreaterThanOrEqual(2, count($queryResult['attributesList']['items']));
131149

150+
/** @var AttributeInterface $attribute */
151+
$attribute3 = DataFixtureStorageManager::getStorage()->get('attribute3');
152+
/** @var AttributeInterface $attribute */
153+
$attribute4 = DataFixtureStorageManager::getStorage()->get('attribute4');
154+
132155
$this->assertEquals(
133-
'attribute_3',
134-
$this->getAttributeByCode($queryResult['attributesList']['items'], 'attribute_3')['attribute_code'],
156+
$attribute3->getAttributeCode(),
157+
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute3->getAttributeCode())['code'],
135158
self::ATTRIBUTE_NOT_FOUND_ERROR
136159
);
137160
$this->assertEquals(
138-
'attribute_4',
139-
$this->getAttributeByCode($queryResult['attributesList']['items'], 'attribute_4')['attribute_code'],
161+
$attribute4->getAttributeCode(),
162+
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute4->getAttributeCode())['code'],
140163
self::ATTRIBUTE_NOT_FOUND_ERROR
141164
);
142165
$this->assertEquals(
143166
[],
144-
$this->getAttributeByCode($queryResult['attributesList']['items'], 'attribute_5')
167+
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute5->getAttributeCode())
145168
);
146169
}
147170

@@ -155,7 +178,7 @@ public function testAttributesList(): void
155178
private function getAttributeByCode(array $items, string $attribute_code): array
156179
{
157180
$attribute = array_filter($items, function ($item) use ($attribute_code) {
158-
return $item['attribute_code'] == $attribute_code;
181+
return $item['code'] == $attribute_code;
159182
});
160183
return $attribute[array_key_first($attribute)] ?? [];
161184
}

0 commit comments

Comments
 (0)