@@ -122,7 +122,7 @@ protected function setUp(): void
122
122
*/
123
123
public function testSortMultipleFieldsSentInVariables (): void
124
124
{
125
- $ query = <<<'QUERY'
125
+ $ queryAsc = <<<'QUERY'
126
126
query GetProductsQuery(
127
127
$search: String,
128
128
$filter: ProductAttributeFilterInput,
@@ -164,7 +164,7 @@ public function testSortMultipleFieldsSentInVariables(): void
164
164
'currentPage ' => 1 ,
165
165
'sort ' => ['price ' => 'ASC ' , 'name ' => 'ASC ' ]
166
166
];
167
- $ response = $ this ->graphQlQuery ($ query , $ variables );
167
+ $ response = $ this ->graphQlQuery ($ queryAsc , $ variables );
168
168
$ this ->assertEquals (5 , $ response ['products ' ]['total_count ' ]);
169
169
$ prod1 = $ this ->productRepository ->get ('search_product_1 ' );
170
170
$ prod2 = $ this ->productRepository ->get ('search_product_2 ' );
@@ -183,6 +183,64 @@ public function testSortMultipleFieldsSentInVariables(): void
183
183
]
184
184
);
185
185
}
186
+
187
+ //price DESC and name ASC order
188
+ $ queryPriceDescNameAsc = <<<'QUERY'
189
+ query GetProductsQuery(
190
+ $search: String,
191
+ $filter: ProductAttributeFilterInput,
192
+ $pageSize: Int,
193
+ $currentPage: Int,
194
+ $sort: ProductAttributeSortInput
195
+ ) {
196
+ products(
197
+ search: $search,
198
+ filter: $filter,
199
+ pageSize: $pageSize,
200
+ currentPage: $currentPage,
201
+ sort: $sort
202
+ ) {
203
+ total_count
204
+ page_info{total_pages}
205
+ items{
206
+ __typename
207
+ url_key
208
+ sku
209
+ name
210
+ stock_status
211
+ price_range {
212
+ minimum_price {
213
+ final_price {
214
+ value
215
+ currency
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+ }
222
+ QUERY;
223
+ $ variables = [
224
+ 'search ' => null ,
225
+ 'filter ' => [],
226
+ 'pageSize ' => 24 ,
227
+ 'currentPage ' => 1 ,
228
+ 'sort ' => ['price ' => 'DESC ' , 'name ' => 'ASC ' ]
229
+ ];
230
+ $ response = $ this ->graphQlQuery ($ queryPriceDescNameAsc , $ variables );
231
+ $ this ->assertEquals (5 , $ response ['products ' ]['total_count ' ]);
232
+
233
+ $ filteredProducts = [$ prod5 , $ prod4 , $ prod3 , $ prod1 , $ prod2 ];
234
+ $ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
235
+ foreach ($ productItemsInResponse as $ itemIndex => $ itemArray ) {
236
+ $ this ->assertNotEmpty ($ itemArray );
237
+ $ this ->assertResponseFields (
238
+ $ productItemsInResponse [$ itemIndex ][0 ],
239
+ [
240
+ 'name ' => $ filteredProducts [$ itemIndex ]->getName (),
241
+ ]
242
+ );
243
+ }
186
244
}
187
245
188
246
/**
0 commit comments