Skip to content

Commit d8b24bd

Browse files
committed
MC-18514: API functional test to cover filterable custom attributes in layered navigation
- fix failing tests
1 parent c9ed703 commit d8b24bd

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function testAnchorCategory()
383383
{
384384
category(id: {$categoryId}) {
385385
name
386-
products(sort: {sku: ASC}) {
386+
products(sort: {name: DESC}) {
387387
total_count
388388
items {
389389
sku
@@ -400,8 +400,8 @@ public function testAnchorCategory()
400400
'total_count' => 3,
401401
'items' => [
402402
['sku' => '12345'],
403-
['sku' => 'simple'],
404-
['sku' => 'simple-4']
403+
['sku' => 'simple-4'],
404+
['sku' => 'simple']
405405
]
406406
]
407407
]

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ class ProductSearchTest extends GraphQlAbstract
4343
*/
4444
public function testFilterLn()
4545
{
46-
/** @var \Magento\Eav\Model\Config $eavConfig */
47-
$eavConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(Config::class);
48-
$attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable');
49-
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $options */
50-
$options = $attribute->getOptions();
5146
$query = <<<QUERY
5247
{
5348
products (
@@ -128,9 +123,8 @@ public function testLayeredNavigationForConfigurableProducts()
128123

129124
$this->assertEquals(2, $response['products']['total_count']);
130125
$this->assertNotEmpty($response['products']['aggregations']);
131-
$this->assertNotEmpty($response['products']['filters'],'Filters is empty');
126+
$this->assertNotEmpty($response['products']['filters'], 'Filters is empty');
132127
$this->assertCount(2, $response['products']['aggregations'], 'Aggregation count does not match');
133-
//$this->assertResponseFields($response['products']['aggregations'])
134128

135129
// Custom attribute filter layer data
136130
$this->assertResponseFields(
@@ -224,6 +218,7 @@ public function testFilterProductsByDropDownCustomAttribute()
224218
products(filter:{
225219
$attributeCode: {eq: "{$optionValue}"}
226220
}
221+
sort:{relevance:DESC}
227222
pageSize: 3
228223
currentPage: 1
229224
)
@@ -278,8 +273,9 @@ public function testFilterProductsByDropDownCustomAttribute()
278273
$indexer->load('catalogsearch_fulltext');
279274
$indexer->reindexAll();
280275
$response = $this->graphQlQuery($query);
281-
$this->assertEquals(3, $response['products']['total_count']);
276+
$this->assertEquals(3, $response['products']['total_count'], 'Number of products returned is incorrect');
282277
$this->assertTrue(count($response['products']['filters']) > 0, 'Product filters is not empty');
278+
$this->assertCount(3, $response['products']['aggregations'], 'Incorrect count of aggregations');
283279
$productItemsInResponse = array_map(null, $response['products']['items'], $filteredProducts);
284280
//phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
285281
for ($itemIndex = 0; $itemIndex < count($filteredProducts); $itemIndex++) {
@@ -288,7 +284,7 @@ public function testFilterProductsByDropDownCustomAttribute()
288284
$this->assertResponseFields(
289285
$productItemsInResponse[$itemIndex][0],
290286
[ 'name' => $filteredProducts[$itemIndex]->getName(),
291-
'sku' => $filteredProducts[$itemIndex]->getSku()
287+
'sku' => $filteredProducts[$itemIndex]->getSku()
292288
]
293289
);
294290
}
@@ -627,8 +623,8 @@ public function testFilterByCategoryIdAndCustomAttribute()
627623
$this->assertEquals(2, $response['products']['total_count']);
628624
/** @var ProductRepositoryInterface $productRepository */
629625
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
630-
$product1 = $productRepository->get('simple-4');
631-
$product2 = $productRepository->get('simple');
626+
$product1 = $productRepository->get('simple');
627+
$product2 = $productRepository->get('simple-4');
632628
$filteredProducts = [$product1, $product2];
633629
$productItemsInResponse = array_map(null, $response['products']['items'], $filteredProducts);
634630
//phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
@@ -1069,8 +1065,7 @@ public function testFilterProductsForExactMatchingName()
10691065
$response = $this->graphQlQuery($query);
10701066
$this->assertEquals(2, $response['products']['total_count']);
10711067
$this->assertEquals(['page_size' => 2, 'current_page' => 1], $response['products']['page_info']);
1072-
$this->assertEquals
1073-
(
1068+
$this->assertEquals(
10741069
[
10751070
['sku' => $product1->getSku(), 'name' => $product1->getName()],
10761071
['sku' => $product2->getSku(), 'name' => $product2->getName()]
@@ -1192,7 +1187,7 @@ public function testFilterProductsBySingleCategoryId()
11921187
QUERY;
11931188

11941189
$response = $this->graphQlQuery($query);
1195-
1190+
$this->assertEquals(2, $response['products']['total_count'], 'Incorrect count of products returned');
11961191
/** @var CategoryLinkManagement $productLinks */
11971192
$productLinks = ObjectManager::getInstance()->get(CategoryLinkManagement::class);
11981193
/** @var CategoryRepositoryInterface $categoryRepository */
@@ -1300,9 +1295,9 @@ public function testSearchAndSortByRelevance()
13001295
QUERY;
13011296
$response = $this->graphQlQuery($query);
13021297
$this->assertEquals(4, $response['products']['total_count']);
1303-
$this->assertNotEmpty($response['products']['filters'],'Filters should have the Category layer');
1298+
$this->assertNotEmpty($response['products']['filters'], 'Filters should have the Category layer');
13041299
$this->assertEquals('Colorful Category', $response['products']['filters'][0]['filter_items'][0]['label']);
1305-
$productsInResponse = ['ocean blue Shoes', 'Blue briefs', 'Navy Striped Shoes','Grey shorts'];
1300+
$productsInResponse = ['ocean blue Shoes','Blue briefs','Navy Striped Shoes','Grey shorts'];
13061301
for ($i = 0; $i < count($response['products']['items']); $i++) {
13071302
$this->assertEquals($productsInResponse[$i], $response['products']['items'][$i]['name']);
13081303
}
@@ -1437,11 +1432,13 @@ public function testProductBasicFullTextSearchQuery()
14371432
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
14381433

14391434
$prod1 = $productRepository->get('blue_briefs');
1440-
1435+
$prod2 = $productRepository->get('grey_shorts');
1436+
$prod3 = $productRepository->get('navy-striped-shoes');
1437+
$prod4 = $productRepository->get('ocean-blue-shoes');
14411438
$response = $this->graphQlQuery($query);
1442-
$this->assertEquals(1, $response['products']['total_count']);
1439+
$this->assertEquals(4, $response['products']['total_count']);
14431440

1444-
$filteredProducts = [$prod1];
1441+
$filteredProducts = [$prod1, $prod2, $prod3, $prod4];
14451442
$productItemsInResponse = array_map(null, $response['products']['items'], $filteredProducts);
14461443
foreach ($productItemsInResponse as $itemIndex => $itemArray) {
14471444
$this->assertNotEmpty($itemArray);
@@ -1453,7 +1450,7 @@ public function testProductBasicFullTextSearchQuery()
14531450
'price' => [
14541451
'minimalPrice' => [
14551452
'amount' => [
1456-
'value' => $filteredProducts[$itemIndex]->getSpecialPrice(),
1453+
'value' => $filteredProducts[$itemIndex]->getPrice(),
14571454
'currency' => 'USD'
14581455
]
14591456
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private function findProduct(): string
158158
products (
159159
filter: {
160160
sku: {
161-
like:"simple%"
161+
eq:"simple1"
162162
}
163163
}
164164
pageSize: 1

0 commit comments

Comments
 (0)