@@ -43,11 +43,6 @@ class ProductSearchTest extends GraphQlAbstract
43
43
*/
44
44
public function testFilterLn ()
45
45
{
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 ();
51
46
$ query = <<<QUERY
52
47
{
53
48
products (
@@ -128,9 +123,8 @@ public function testLayeredNavigationForConfigurableProducts()
128
123
129
124
$ this ->assertEquals (2 , $ response ['products ' ]['total_count ' ]);
130
125
$ this ->assertNotEmpty ($ response ['products ' ]['aggregations ' ]);
131
- $ this ->assertNotEmpty ($ response ['products ' ]['filters ' ],'Filters is empty ' );
126
+ $ this ->assertNotEmpty ($ response ['products ' ]['filters ' ], 'Filters is empty ' );
132
127
$ this ->assertCount (2 , $ response ['products ' ]['aggregations ' ], 'Aggregation count does not match ' );
133
- //$this->assertResponseFields($response['products']['aggregations'])
134
128
135
129
// Custom attribute filter layer data
136
130
$ this ->assertResponseFields (
@@ -224,6 +218,7 @@ public function testFilterProductsByDropDownCustomAttribute()
224
218
products(filter:{
225
219
$ attributeCode: {eq: " {$ optionValue }"}
226
220
}
221
+ sort:{relevance:DESC}
227
222
pageSize: 3
228
223
currentPage: 1
229
224
)
@@ -278,8 +273,9 @@ public function testFilterProductsByDropDownCustomAttribute()
278
273
$ indexer ->load ('catalogsearch_fulltext ' );
279
274
$ indexer ->reindexAll ();
280
275
$ 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 ' );
282
277
$ this ->assertTrue (count ($ response ['products ' ]['filters ' ]) > 0 , 'Product filters is not empty ' );
278
+ $ this ->assertCount (3 , $ response ['products ' ]['aggregations ' ], 'Incorrect count of aggregations ' );
283
279
$ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
284
280
//phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
285
281
for ($ itemIndex = 0 ; $ itemIndex < count ($ filteredProducts ); $ itemIndex ++) {
@@ -288,7 +284,7 @@ public function testFilterProductsByDropDownCustomAttribute()
288
284
$ this ->assertResponseFields (
289
285
$ productItemsInResponse [$ itemIndex ][0 ],
290
286
[ 'name ' => $ filteredProducts [$ itemIndex ]->getName (),
291
- 'sku ' => $ filteredProducts [$ itemIndex ]->getSku ()
287
+ 'sku ' => $ filteredProducts [$ itemIndex ]->getSku ()
292
288
]
293
289
);
294
290
}
@@ -627,8 +623,8 @@ public function testFilterByCategoryIdAndCustomAttribute()
627
623
$ this ->assertEquals (2 , $ response ['products ' ]['total_count ' ]);
628
624
/** @var ProductRepositoryInterface $productRepository */
629
625
$ 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 ' );
632
628
$ filteredProducts = [$ product1 , $ product2 ];
633
629
$ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
634
630
//phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
@@ -1069,8 +1065,7 @@ public function testFilterProductsForExactMatchingName()
1069
1065
$ response = $ this ->graphQlQuery ($ query );
1070
1066
$ this ->assertEquals (2 , $ response ['products ' ]['total_count ' ]);
1071
1067
$ this ->assertEquals (['page_size ' => 2 , 'current_page ' => 1 ], $ response ['products ' ]['page_info ' ]);
1072
- $ this ->assertEquals
1073
- (
1068
+ $ this ->assertEquals (
1074
1069
[
1075
1070
['sku ' => $ product1 ->getSku (), 'name ' => $ product1 ->getName ()],
1076
1071
['sku ' => $ product2 ->getSku (), 'name ' => $ product2 ->getName ()]
@@ -1192,7 +1187,7 @@ public function testFilterProductsBySingleCategoryId()
1192
1187
QUERY ;
1193
1188
1194
1189
$ response = $ this ->graphQlQuery ($ query );
1195
-
1190
+ $ this -> assertEquals ( 2 , $ response [ ' products ' ][ ' total_count ' ], ' Incorrect count of products returned ' );
1196
1191
/** @var CategoryLinkManagement $productLinks */
1197
1192
$ productLinks = ObjectManager::getInstance ()->get (CategoryLinkManagement::class);
1198
1193
/** @var CategoryRepositoryInterface $categoryRepository */
@@ -1300,9 +1295,9 @@ public function testSearchAndSortByRelevance()
1300
1295
QUERY ;
1301
1296
$ response = $ this ->graphQlQuery ($ query );
1302
1297
$ 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 ' );
1304
1299
$ 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 ' ];
1306
1301
for ($ i = 0 ; $ i < count ($ response ['products ' ]['items ' ]); $ i ++) {
1307
1302
$ this ->assertEquals ($ productsInResponse [$ i ], $ response ['products ' ]['items ' ][$ i ]['name ' ]);
1308
1303
}
@@ -1437,11 +1432,13 @@ public function testProductBasicFullTextSearchQuery()
1437
1432
$ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
1438
1433
1439
1434
$ 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 ' );
1441
1438
$ response = $ this ->graphQlQuery ($ query );
1442
- $ this ->assertEquals (1 , $ response ['products ' ]['total_count ' ]);
1439
+ $ this ->assertEquals (4 , $ response ['products ' ]['total_count ' ]);
1443
1440
1444
- $ filteredProducts = [$ prod1 ];
1441
+ $ filteredProducts = [$ prod1, $ prod2 , $ prod3 , $ prod4 ];
1445
1442
$ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
1446
1443
foreach ($ productItemsInResponse as $ itemIndex => $ itemArray ) {
1447
1444
$ this ->assertNotEmpty ($ itemArray );
@@ -1453,7 +1450,7 @@ public function testProductBasicFullTextSearchQuery()
1453
1450
'price ' => [
1454
1451
'minimalPrice ' => [
1455
1452
'amount ' => [
1456
- 'value ' => $ filteredProducts [$ itemIndex ]->getSpecialPrice (),
1453
+ 'value ' => $ filteredProducts [$ itemIndex ]->getPrice (),
1457
1454
'currency ' => 'USD '
1458
1455
]
1459
1456
]
0 commit comments