10
10
use Magento \Customer \Api \CustomerMetadataInterface ;
11
11
use Magento \Catalog \Setup \CategorySetup ;
12
12
use Magento \Eav \Test \Fixture \Attribute ;
13
+ use Magento \Eav \Api \Data \AttributeInterface ;
13
14
use Magento \Sales \Setup \SalesSetup ;
14
15
use Magento \TestFramework \Fixture \DataFixture ;
15
16
use Magento \TestFramework \TestCase \GraphQlAbstract ;
17
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
16
18
17
19
/**
18
20
* Test EAV attributes metadata retrieval for entity type via GraphQL API
@@ -26,47 +28,53 @@ class AttributesListTest extends GraphQlAbstract
26
28
Attribute::class,
27
29
[
28
30
'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 '
30
33
],
31
34
'attribute0 '
32
35
),
33
36
DataFixture(
34
37
Attribute::class,
35
38
[
36
39
'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 '
38
42
],
39
43
'attribute1 '
40
44
),
41
45
DataFixture(
42
46
Attribute::class,
43
47
[
44
48
'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 '
46
51
],
47
52
'attribute2 '
48
53
),
49
54
DataFixture(
50
55
Attribute::class,
51
56
[
52
57
'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 '
54
60
],
55
61
'attribute3 '
56
62
),
57
63
DataFixture(
58
64
Attribute::class,
59
65
[
60
66
'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 '
62
69
],
63
70
'attribute4 '
64
71
),
65
72
DataFixture(
66
73
Attribute::class,
67
74
[
68
75
'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 '
70
78
],
71
79
'attribute5 '
72
80
)
@@ -78,7 +86,7 @@ public function testAttributesList(): void
78
86
attributesList(entity_type: CUSTOMER) {
79
87
items {
80
88
uid
81
- attribute_code
89
+ code
82
90
}
83
91
errors {
84
92
type
@@ -91,33 +99,43 @@ public function testAttributesList(): void
91
99
$ this ->assertArrayHasKey ('items ' , $ queryResult ['attributesList ' ], 'Query result does not contain items ' );
92
100
$ this ->assertGreaterThanOrEqual (3 , count ($ queryResult ['attributesList ' ]['items ' ]));
93
101
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
+
94
112
$ 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 ' ],
97
115
self ::ATTRIBUTE_NOT_FOUND_ERROR
98
116
);
99
117
100
118
$ 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 ' ],
103
121
self ::ATTRIBUTE_NOT_FOUND_ERROR
104
122
);
105
123
$ 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 ' ],
108
126
self ::ATTRIBUTE_NOT_FOUND_ERROR
109
127
);
110
128
$ this ->assertEquals (
111
129
[],
112
- $ this ->getAttributeByCode ($ queryResult ['attributesList ' ]['items ' ], ' attribute_5 ' )
130
+ $ this ->getAttributeByCode ($ queryResult ['attributesList ' ]['items ' ], $ attribute5 -> getAttributeCode () )
113
131
);
114
132
115
133
$ queryResult = $ this ->graphQlQuery (<<<QRY
116
134
{
117
135
attributesList(entity_type: CATALOG_PRODUCT) {
118
136
items {
119
137
uid
120
- attribute_code
138
+ code
121
139
}
122
140
errors {
123
141
type
@@ -129,19 +147,24 @@ public function testAttributesList(): void
129
147
$ this ->assertArrayHasKey ('items ' , $ queryResult ['attributesList ' ], 'Query result does not contain items ' );
130
148
$ this ->assertGreaterThanOrEqual (2 , count ($ queryResult ['attributesList ' ]['items ' ]));
131
149
150
+ /** @var AttributeInterface $attribute */
151
+ $ attribute3 = DataFixtureStorageManager::getStorage ()->get ('attribute3 ' );
152
+ /** @var AttributeInterface $attribute */
153
+ $ attribute4 = DataFixtureStorageManager::getStorage ()->get ('attribute4 ' );
154
+
132
155
$ 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 ' ],
135
158
self ::ATTRIBUTE_NOT_FOUND_ERROR
136
159
);
137
160
$ 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 ' ],
140
163
self ::ATTRIBUTE_NOT_FOUND_ERROR
141
164
);
142
165
$ this ->assertEquals (
143
166
[],
144
- $ this ->getAttributeByCode ($ queryResult ['attributesList ' ]['items ' ], ' attribute_5 ' )
167
+ $ this ->getAttributeByCode ($ queryResult ['attributesList ' ]['items ' ], $ attribute5 -> getAttributeCode () )
145
168
);
146
169
}
147
170
@@ -155,7 +178,7 @@ public function testAttributesList(): void
155
178
private function getAttributeByCode (array $ items , string $ attribute_code ): array
156
179
{
157
180
$ attribute = array_filter ($ items , function ($ item ) use ($ attribute_code ) {
158
- return $ item ['attribute_code ' ] == $ attribute_code ;
181
+ return $ item ['code ' ] == $ attribute_code ;
159
182
});
160
183
return $ attribute [array_key_first ($ attribute )] ?? [];
161
184
}
0 commit comments