@@ -1616,11 +1616,16 @@ public function testFilterProductsBySingleCategoryId(string $fieldName, string $
1616
1616
/**
1617
1617
* Sorting the search results by relevance (DESC => most relevant)
1618
1618
*
1619
+ * Sorting by relevance may return different results depending on the ES.
1620
+ * To check that sorting works, we compare results with ASC and DESC relevance sorting
1621
+ *
1619
1622
* Search for products for a fuzzy match and checks if all matching results returned including
1620
1623
* results based on matching keywords from description
1621
1624
*
1622
1625
* @magentoApiDataFixture Magento/Catalog/_files/products_for_relevance_sorting.php
1623
1626
* @return void
1627
+ *
1628
+ * @throws \Exception
1624
1629
*/
1625
1630
public function testSearchAndSortByRelevance ()
1626
1631
{
@@ -1630,7 +1635,7 @@ public function testSearchAndSortByRelevance()
1630
1635
{
1631
1636
products(
1632
1637
search:" {$ search_term }"
1633
- sort:{relevance:DESC }
1638
+ sort:{relevance:%s }
1634
1639
pageSize: 5
1635
1640
currentPage: 1
1636
1641
)
@@ -1671,16 +1676,16 @@ public function testSearchAndSortByRelevance()
1671
1676
1672
1677
}
1673
1678
QUERY ;
1674
- $ response = $ this ->graphQlQuery ($ query );
1675
- $ this ->assertEquals ( 3 , $ response [ ' products ' ][ ' total_count ' ] );
1676
- $ this ->assertNotEmpty ( $ response ['products ' ]['filters ' ], ' Filters should have the Category layer ' );
1677
- $ this ->assertEquals ( ' Colorful Category ' , $ response ['products ' ]['filters ' ][ 0 ][ ' filter_items ' ][ 0 ][ ' label ' ] );
1678
- $ this ->assertCount ( 2 , $ response ['products ' ]['aggregations ' ]);
1679
- $ productsInResponse = [ ' Blue briefs ' , ' Navy Blue Striped Shoes ' , ' Grey shorts ' ] ;
1680
- $ count = count ( $ response [ ' products ' ][ ' items ' ]) ;
1681
- for ( $ i = 0 ; $ i < $ count ; $ i ++) {
1682
- $ this ->assertEquals ( $ productsInResponse [ $ i ] , $ response [ ' products ' ][ ' items ' ][ $ i ][ ' name ' ] );
1683
- }
1679
+ $ responseDesc = $ this ->graphQlQuery (sprintf ( $ query, ' DESC ' ) );
1680
+ $ responseAsc = $ this ->graphQlQuery ( sprintf ( $ query , ' ASC ' ) );
1681
+ $ this ->assertEquals ( 3 , $ responseDesc ['products ' ]['total_count ' ] );
1682
+ $ this ->assertNotEmpty ( $ responseDesc ['products ' ]['filters ' ], ' Filters should have the Category layer ' );
1683
+ $ this ->assertEquals ( ' Colorful Category ' , $ responseDesc ['products ' ]['filters ' ][ 0 ][ ' filter_items ' ][ 0 ][ ' label ' ]);
1684
+ $ this -> assertCount ( 2 , $ responseDesc [ ' products ' ][ ' aggregations ' ]) ;
1685
+ $ expectedProductsInResponse = [ ' Blue briefs ' , ' Navy Blue Striped Shoes ' , ' Grey shorts ' ] ;
1686
+ $ namesDesc = array_column ( $ responseDesc [ ' products ' ][ ' items ' ], ' name ' );
1687
+ $ this ->assertEqualsCanonicalizing ( $ expectedProductsInResponse , $ namesDesc );
1688
+ $ this -> assertEquals ( $ namesDesc , array_reverse ( array_column ( $ responseAsc [ ' products ' ][ ' items ' ], ' name ' )));
1684
1689
}
1685
1690
1686
1691
/**
0 commit comments