@@ -61,12 +61,21 @@ public function testSearchBySku()
61
61
public function testCategorySearch ()
62
62
{
63
63
// Get products by categoryId
64
- $ results = $ this ->search ('' , 1 , [
64
+ list ( $ results, $ totalHits , $ facetsFromAlgolia ) = $ this ->search ('' , 1 , [
65
65
'facetFilters ' => ['categoryIds: ' . $ this ->assertValues ->expectedCategory ]
66
66
]);
67
- $ result = $ this ->getFirstResult ($ results );
68
67
// Category filter returns result
69
- $ this ->assertNotEmpty ($ result , "Category filter didn't return result " );
68
+ $ this ->assertNotEmpty ($ results , "Category filter didn't return result " );
69
+
70
+ $ collection = $ this ->objectManager ->create (\Magento \Catalog \Model \ResourceModel \Product \Collection::class);
71
+ $ collection
72
+ ->addAttributeToSelect ('* ' )
73
+ ->addAttributeToFilter ('status ' ,\Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED )
74
+ ->addAttributeToFilter ('visibility ' , \Magento \Catalog \Model \Product \Visibility::VISIBILITY_BOTH )
75
+ ->addCategoriesFilter (["in " => $ this ->assertValues ->expectedCategory ])
76
+ ->setStore (1 );
77
+ // Products in category count matches
78
+ $ this ->assertEquals (count ($ results ), $ collection ->count (), "Indexed number of products in a category doesn't match with DB " );
70
79
}
71
80
72
81
/**
@@ -82,6 +91,7 @@ protected function getFirstResult(array $results): array
82
91
/**
83
92
* @param string $query
84
93
* @param int $storeId
94
+ * @param array $params
85
95
* @return array
86
96
*/
87
97
protected function search (string $ query = '' , int $ storeId = 1 , array $ params = []): array
0 commit comments