Skip to content

Commit 594d04d

Browse files
committed
LYNX-100: CR changes
1 parent 184d205 commit 594d04d

File tree

3 files changed

+90
-82
lines changed

3 files changed

+90
-82
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function getFrontendInput(AttributeInterface $attribute): string
9393
}
9494
return $this->enumLookup->getEnumValueFromField(
9595
'AttributeFrontendInputEnum',
96-
$attribute->getFrontendInput() ?? "undefined"
96+
$attribute->getFrontendInput()
9797
);
9898
}
9999

app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\EavGraphQl\Model\Resolver;
99

1010
use Magento\Eav\Model\AttributeRepository;
11+
use Magento\Eav\Api\Data\AttributeInterface;
1112
use Magento\Framework\GraphQl\Query\EnumLookup;
1213
use Magento\Framework\Api\SearchCriteriaBuilder;
1314
use Magento\Framework\GraphQl\Config\Element\Field;
@@ -86,7 +87,7 @@ public function resolve(
8687
$storeId = (int) $context->getExtensionAttributes()->getStore()->getId();
8788
$entityType = $this->enumLookup->getEnumValueFromField(
8889
'AttributeEntityTypeEnum',
89-
mb_strtolower($args['entityType'])
90+
strtolower($args['entityType'])
9091
);
9192

9293
$searchCriteria = $this->searchCriteriaBuilder;
@@ -110,16 +111,16 @@ public function resolve(
110111
/**
111112
* Returns formatted list of attributes
112113
*
113-
* @param array $attributesList
114+
* @param AttributeInterface[] $attributesList
114115
* @param string $entityType
115116
* @param int $storeId
116117
*
117-
* @return array
118+
* @return array[]
118119
*/
119-
private function getAtrributesMetadata(array $attributesList, string $entityType, int $storeId)
120+
private function getAtrributesMetadata(array $attributesList, string $entityType, int $storeId): array
120121
{
121-
return array_map(function ($attribute) use ($entityType, $storeId) {
122-
return $this->getAttributeData->execute($attribute, mb_strtolower($entityType), $storeId);
122+
return array_map(function (AttributeInterface $attribute) use ($entityType, $storeId): array {
123+
return $this->getAttributeData->execute($attribute, strtolower($entityType), $storeId);
123124
}, $attributesList);
124125
}
125126
}

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

Lines changed: 82 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,68 @@
1919
/**
2020
* Test EAV attributes metadata retrieval for entity type via GraphQL API
2121
*/
22+
#[
23+
DataFixture(
24+
Attribute::class,
25+
[
26+
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
27+
'frontend_input' => 'boolean',
28+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
29+
],
30+
'customerAttribute0'
31+
),
32+
DataFixture(
33+
Attribute::class,
34+
[
35+
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
36+
'frontend_input' => 'boolean',
37+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
38+
],
39+
'customerAttribute1'
40+
),
41+
DataFixture(
42+
Attribute::class,
43+
[
44+
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
45+
'frontend_input' => 'boolean',
46+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
47+
],
48+
'customerAttribute2'
49+
),
50+
DataFixture(
51+
Attribute::class,
52+
[
53+
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
54+
'frontend_input' => 'boolean',
55+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
56+
],
57+
'catalogAttribute3'
58+
),
59+
DataFixture(
60+
Attribute::class,
61+
[
62+
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
63+
'frontend_input' => 'boolean',
64+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
65+
],
66+
'catalogAttribute4'
67+
),
68+
DataFixture(
69+
Attribute::class,
70+
[
71+
'entity_type_id' => SalesSetup::CREDITMEMO_PRODUCT_ENTITY_TYPE_ID,
72+
'frontend_input' => 'boolean',
73+
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
74+
],
75+
'creditmemoAttribute5'
76+
)
77+
]
2278
class AttributesListTest extends GraphQlAbstract
2379
{
2480
private const ATTRIBUTE_NOT_FOUND_ERROR = "Attribute was not found in query result";
2581

26-
#[
27-
DataFixture(
28-
Attribute::class,
29-
[
30-
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
31-
'frontend_input' => 'boolean',
32-
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
33-
],
34-
'attribute0'
35-
),
36-
DataFixture(
37-
Attribute::class,
38-
[
39-
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
40-
'frontend_input' => 'boolean',
41-
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
42-
],
43-
'attribute1'
44-
),
45-
DataFixture(
46-
Attribute::class,
47-
[
48-
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
49-
'frontend_input' => 'boolean',
50-
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
51-
],
52-
'attribute2'
53-
),
54-
DataFixture(
55-
Attribute::class,
56-
[
57-
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
58-
'frontend_input' => 'boolean',
59-
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
60-
],
61-
'attribute3'
62-
),
63-
DataFixture(
64-
Attribute::class,
65-
[
66-
'entity_type_id' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID,
67-
'frontend_input' => 'boolean',
68-
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
69-
],
70-
'attribute4'
71-
),
72-
DataFixture(
73-
Attribute::class,
74-
[
75-
'entity_type_id' => SalesSetup::CREDITMEMO_PRODUCT_ENTITY_TYPE_ID,
76-
'frontend_input' => 'boolean',
77-
'source_model' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean'
78-
],
79-
'attribute5'
80-
)
81-
]
82-
public function testAttributesList(): void
82+
83+
public function testAttributesListForCustomerEntityType(): void
8384
{
8485
$queryResult = $this->graphQlQuery(<<<QRY
8586
{
@@ -100,36 +101,39 @@ public function testAttributesList(): void
100101
$this->assertGreaterThanOrEqual(3, count($queryResult['attributesList']['items']));
101102

102103
/** @var AttributeInterface $attribute */
103-
$attribute5 = DataFixtureStorageManager::getStorage()->get('attribute5');
104+
$creditmemoAttribute5 = DataFixtureStorageManager::getStorage()->get('creditmemoAttribute5');
104105

105106
/** @var AttributeInterface $attribute */
106-
$attribute0 = DataFixtureStorageManager::getStorage()->get('attribute0');
107+
$customerAttribute0 = DataFixtureStorageManager::getStorage()->get('customerAttribute0');
107108
/** @var AttributeInterface $attribute */
108-
$attribute1 = DataFixtureStorageManager::getStorage()->get('attribute1');
109+
$customerAttribute1 = DataFixtureStorageManager::getStorage()->get('customerAttribute1');
109110
/** @var AttributeInterface $attribute */
110-
$attribute2 = DataFixtureStorageManager::getStorage()->get('attribute2');
111+
$customerAttribute2 = DataFixtureStorageManager::getStorage()->get('customerAttribute2');
111112

112113
$this->assertEquals(
113-
$attribute0->getAttributeCode(),
114-
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute0->getAttributeCode())['code'],
114+
$customerAttribute0->getAttributeCode(),
115+
$this->getAttributeByCode($queryResult['attributesList']['items'], $customerAttribute0->getAttributeCode())['code'],
115116
self::ATTRIBUTE_NOT_FOUND_ERROR
116117
);
117118

118119
$this->assertEquals(
119-
$attribute1->getAttributeCode(),
120-
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute1->getAttributeCode())['code'],
120+
$customerAttribute1->getAttributeCode(),
121+
$this->getAttributeByCode($queryResult['attributesList']['items'], $customerAttribute1->getAttributeCode())['code'],
121122
self::ATTRIBUTE_NOT_FOUND_ERROR
122123
);
123124
$this->assertEquals(
124-
$attribute2->getAttributeCode(),
125-
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute2->getAttributeCode())['code'],
125+
$customerAttribute2->getAttributeCode(),
126+
$this->getAttributeByCode($queryResult['attributesList']['items'], $customerAttribute2->getAttributeCode())['code'],
126127
self::ATTRIBUTE_NOT_FOUND_ERROR
127128
);
128129
$this->assertEquals(
129130
[],
130-
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute5->getAttributeCode())
131+
$this->getAttributeByCode($queryResult['attributesList']['items'], $creditmemoAttribute5->getAttributeCode())
131132
);
133+
}
132134

135+
public function testAttributesListForCatalogProductEntityType(): void
136+
{
133137
$queryResult = $this->graphQlQuery(<<<QRY
134138
{
135139
attributesList(entityType: CATALOG_PRODUCT) {
@@ -148,23 +152,26 @@ public function testAttributesList(): void
148152
$this->assertGreaterThanOrEqual(2, count($queryResult['attributesList']['items']));
149153

150154
/** @var AttributeInterface $attribute */
151-
$attribute3 = DataFixtureStorageManager::getStorage()->get('attribute3');
155+
$creditmemoAttribute5 = DataFixtureStorageManager::getStorage()->get('creditmemoAttribute5');
156+
157+
/** @var AttributeInterface $attribute */
158+
$catalogAttribute3 = DataFixtureStorageManager::getStorage()->get('catalogAttribute3');
152159
/** @var AttributeInterface $attribute */
153-
$attribute4 = DataFixtureStorageManager::getStorage()->get('attribute4');
160+
$catalogAttribute4 = DataFixtureStorageManager::getStorage()->get('catalogAttribute4');
154161

155162
$this->assertEquals(
156-
$attribute3->getAttributeCode(),
157-
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute3->getAttributeCode())['code'],
163+
$catalogAttribute3->getAttributeCode(),
164+
$this->getAttributeByCode($queryResult['attributesList']['items'], $catalogAttribute3->getAttributeCode())['code'],
158165
self::ATTRIBUTE_NOT_FOUND_ERROR
159166
);
160167
$this->assertEquals(
161-
$attribute4->getAttributeCode(),
162-
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute4->getAttributeCode())['code'],
168+
$catalogAttribute4->getAttributeCode(),
169+
$this->getAttributeByCode($queryResult['attributesList']['items'], $catalogAttribute4->getAttributeCode())['code'],
163170
self::ATTRIBUTE_NOT_FOUND_ERROR
164171
);
165172
$this->assertEquals(
166173
[],
167-
$this->getAttributeByCode($queryResult['attributesList']['items'], $attribute5->getAttributeCode())
174+
$this->getAttributeByCode($queryResult['attributesList']['items'], $creditmemoAttribute5->getAttributeCode())
168175
);
169176
}
170177

0 commit comments

Comments
 (0)