Skip to content

Commit 362e5c3

Browse files
author
Prabhu Ram
committed
Merge branch 'PWA-1720' of github.com:magento-honey-badgers/magento2ce into PWA-1720
2 parents d09b624 + 9d358d4 commit 362e5c3

File tree

4 files changed

+127
-11
lines changed

4 files changed

+127
-11
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductAttributeOptionsTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testCustomAttributeMetadataOptions()
6060
label
6161
value
6262
}
63-
}
63+
}
6464
}
6565
}
6666
QUERY;
@@ -101,5 +101,48 @@ public function testCustomAttributeMetadataOptions()
101101
$actualOption = $actualAttributes[$index]['attribute_options'];
102102
$this->assertEquals($expectedOptions, $actualOption);
103103
}
104+
$queryWithStoreFrontProperties = <<<QUERY
105+
106+
{
107+
customAttributeMetadata(attributes:
108+
[
109+
{
110+
attribute_code:"dropdown_attribute",
111+
entity_type:"catalog_product"
112+
}
113+
]
114+
)
115+
{
116+
items
117+
{
118+
attribute_code
119+
attribute_type
120+
entity_type
121+
input_type
122+
storefront_properties {
123+
position
124+
use_in_search
125+
used_in_product_listing
126+
use_in_layered_navigation
127+
use_in_search_results_layered_navigation
128+
visible_on_catalog_storefront
129+
}
130+
}
131+
}
132+
}
133+
134+
QUERY;
135+
$response = $this->graphQlQuery($queryWithStoreFrontProperties);
136+
$this->assertArrayHasKey('storefront_properties', $response['customAttributeMetadata']['items'][0]);
137+
$actualStorefrontPropery = $response['customAttributeMetadata']['items'][0]['storefront_properties'];
138+
$expectedStorefrontProperties = [
139+
'position' => 0,
140+
'use_in_search' => false,
141+
'used_in_product_listing' => true,
142+
'use_in_layered_navigation' => 'NO',
143+
'use_in_search_results_layered_navigation' => false,
144+
'visible_on_catalog_storefront' => true
145+
];
146+
$this->assertEquals($expectedStorefrontProperties, $actualStorefrontPropery);
104147
}
105148
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductAttributeTypeTest.php

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function testAttributeTypeResolver()
7373
];
7474
$attributeTypes = ['String', 'Int', 'Float','Boolean', 'Float'];
7575
$inputTypes = ['textarea', 'select', 'price', 'boolean', 'price'];
76+
7677
$this->assertAttributeType($attributeTypes, $expectedAttributeCodes, $entityType, $inputTypes, $response);
7778
}
7879

@@ -125,6 +126,13 @@ public function testComplexAttributeTypeResolver()
125126
attribute_type
126127
entity_type
127128
input_type
129+
storefront_properties {
130+
use_in_search
131+
used_in_product_listing
132+
use_in_layered_navigation
133+
use_in_search_results_layered_navigation
134+
visible_on_catalog_storefront
135+
}
128136
}
129137
}
130138
}
@@ -166,7 +174,7 @@ public function testComplexAttributeTypeResolver()
166174
'text',
167175
'gallery'
168176
];
169-
$this->assertAttributeType($attributeTypes, $expectedAttributeCodes, $entityTypes, $inputTypes, $response);
177+
$this->assertComplexAttributeType($attributeTypes, $expectedAttributeCodes, $entityTypes, $inputTypes, $response);
170178
}
171179

172180
/**
@@ -221,6 +229,62 @@ public function testUnDefinedAttributeType()
221229
}
222230
}
223231

232+
/**
233+
* @param array $attributeTypes
234+
* @param array $expectedAttributeCodes
235+
* @param array $entityTypes
236+
* @param array $inputTypes
237+
* @param array $actualResponse
238+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
239+
*/
240+
private function assertComplexAttributeType(
241+
$attributeTypes,
242+
$expectedAttributeCodes,
243+
$entityTypes,
244+
$inputTypes,
245+
$actualResponse
246+
) {
247+
$attributeMetaDataItems = array_map(null, $actualResponse['customAttributeMetadata']['items'], $attributeTypes);
248+
249+
foreach ($attributeMetaDataItems as $itemIndex => $itemArray) {
250+
if($itemArray[0]['entity_type'] === 'catalog_category' || $itemArray[0]['entity_type'] ==='catalog_product') {
251+
$this->assertResponseFields(
252+
$attributeMetaDataItems[$itemIndex][0],
253+
[
254+
"attribute_code" => $expectedAttributeCodes[$itemIndex],
255+
"attribute_type" => $attributeTypes[$itemIndex],
256+
"entity_type" => $entityTypes[$itemIndex],
257+
"input_type" => $inputTypes[$itemIndex],
258+
"storefront_properties" => [
259+
'use_in_search' => false,
260+
'used_in_product_listing' => false,
261+
'use_in_layered_navigation' => 'NO',
262+
'use_in_search_results_layered_navigation' => false,
263+
'visible_on_catalog_storefront' => false,
264+
]
265+
]
266+
);
267+
}
268+
else {
269+
$this->assertNotEmpty($attributeMetaDataItems[$itemIndex][0]['storefront_properties']);
270+
// 5 fields are present
271+
$this->assertCount(5, $attributeMetaDataItems[$itemIndex][0]['storefront_properties']);
272+
unset($attributeMetaDataItems[$itemIndex][0]['storefront_properties']);
273+
$this->assertResponseFields(
274+
$attributeMetaDataItems[$itemIndex][0],
275+
[
276+
"attribute_code" => $expectedAttributeCodes[$itemIndex],
277+
"attribute_type" => $attributeTypes[$itemIndex],
278+
"entity_type" => $entityTypes[$itemIndex],
279+
"input_type" => $inputTypes[$itemIndex]
280+
]
281+
);
282+
283+
}
284+
285+
}
286+
}
287+
224288
/**
225289
* @param array $attributeTypes
226290
* @param array $expectedAttributeCodes
@@ -239,15 +303,15 @@ private function assertAttributeType(
239303
$attributeMetaDataItems = array_map(null, $actualResponse['customAttributeMetadata']['items'], $attributeTypes);
240304

241305
foreach ($attributeMetaDataItems as $itemIndex => $itemArray) {
242-
$this->assertResponseFields(
243-
$attributeMetaDataItems[$itemIndex][0],
244-
[
245-
"attribute_code" => $expectedAttributeCodes[$itemIndex],
246-
"attribute_type" => $attributeTypes[$itemIndex],
247-
"entity_type" => $entityTypes[$itemIndex],
248-
"input_type" => $inputTypes[$itemIndex]
249-
]
250-
);
306+
$this->assertResponseFields(
307+
$attributeMetaDataItems[$itemIndex][0],
308+
[
309+
"attribute_code" => $expectedAttributeCodes[$itemIndex],
310+
"attribute_type" => $attributeTypes[$itemIndex],
311+
"entity_type" => $entityTypes[$itemIndex],
312+
"input_type" => $inputTypes[$itemIndex]
313+
]
314+
);
251315
}
252316
}
253317
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function testLayeredNavigationForConfigurableProducts()
198198
'attribute_code' => $attribute->getAttributeCode(),
199199
'label' => $attribute->getDefaultFrontendLabel(),
200200
'count' => 2,
201+
'position' => 0,
201202
'options' => [
202203
[
203204
'label' => 'Option 1',
@@ -255,6 +256,7 @@ private function getQueryProductsWithArrayOfCustomAttributes($attributeCode, $fi
255256
attribute_code
256257
count
257258
label
259+
position
258260
options{
259261
label
260262
value
@@ -313,6 +315,7 @@ public function testFilterProductsByDropDownCustomAttribute()
313315
attribute_code
314316
count
315317
label
318+
position
316319
options
317320
{
318321
label
@@ -361,6 +364,7 @@ public function testFilterProductsByDropDownCustomAttribute()
361364
'attribute_code' => $attribute->getAttributeCode(),
362365
'count' => 1,
363366
'label' => $attribute->getDefaultFrontendLabel(),
367+
'position' => $attribute->getPosition(),
364368
'options' => [
365369
[
366370
'label' => 'Option 3',
@@ -445,6 +449,7 @@ public function testFilterProductsByMultiSelectCustomAttributes()
445449
$this->assertEquals(3, $response['products']['total_count']);
446450
$this->assertNotEmpty($response['products']['filters']);
447451
$this->assertNotEmpty($response['products']['aggregations']);
452+
$this->assertCount(2, $response['products']['aggregations']);
448453
}
449454

450455
/**
@@ -515,6 +520,7 @@ public function testSearchAndFilterByCustomAttribute()
515520
attribute_code
516521
count
517522
label
523+
position
518524
options
519525
{
520526
count
@@ -588,6 +594,7 @@ public function testSearchAndFilterByCustomAttribute()
588594
'attribute_code' => $attribute_code,
589595
'count' => 1,
590596
'label' => 'Second Test Configurable',
597+
'position' => 1,
591598
'options' => [
592599
[
593600
'count' => 3,
@@ -663,6 +670,7 @@ public function testFilterByCategoryIdAndCustomAttribute()
663670
attribute_code
664671
count
665672
label
673+
position
666674
options
667675
{
668676
count

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_layered_navigation_custom_attribute.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
'is_visible_on_front' => 1,
9999
'used_in_product_listing' => 1,
100100
'used_for_sort_by' => 1,
101+
'position' => 1,
101102
'frontend_label' => ['Second Test Configurable'],
102103
'backend_type' => 'int',
103104
'option' => [

0 commit comments

Comments
 (0)