@@ -241,4 +241,134 @@ private function getSearchQueryWithSuggestions(): string
241241 }
242242 QUERY ;
243243 }
244+
245+ #[
246+ DataFixture(CategoryFixture::class, as: 'category ' ),
247+ DataFixture(
248+ ProductFixture::class,
249+ [
250+ 'name ' => 'Lifelong 1 ' ,
251+ 'sku ' => 'lifelong1 ' ,
252+ 'description ' => 'Life product 1 ' ,
253+ 'category_ids ' => ['$category.id$ ' ],
254+ ],
255+ 'product1 '
256+ ),
257+ DataFixture(
258+ ProductFixture::class,
259+ [
260+ 'name ' => 'Life 2 ' ,
261+ 'sku ' => 'life2 ' ,
262+ 'description ' => 'Lifelong product 2 ' ,
263+ 'category_ids ' => ['$category.id$ ' ],
264+ ],
265+ 'product2 '
266+ ),
267+ DataFixture(
268+ ProductFixture::class,
269+ [
270+ 'name ' => 'Life 3 ' ,
271+ 'sku ' => 'life3 ' ,
272+ 'description ' => 'Life product 3 ' ,
273+ 'category_ids ' => ['$category.id$ ' ],
274+ ],
275+ 'product3 '
276+ ),
277+ DataFixture(
278+ ProductFixture::class,
279+ [
280+ 'name ' => 'Lifelong 4 ' ,
281+ 'sku ' => 'lifelong4 ' ,
282+ 'description ' => 'Lifelong product 4 ' ,
283+ 'category_ids ' => ['$category.id$ ' ],
284+ ],
285+ 'product4 '
286+ ),
287+ ]
288+ public function testSearchProductsWithFilterAndMatchTypeInQuery (): void
289+ {
290+ $ response1 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , false , '' , '' ));
291+ $ response2 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , false , 'FULL ' , '' ));
292+ $ response3 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , false , 'PARTIAL ' , '' ));
293+
294+ $ response4 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (false , true , '' , '' ));
295+ $ response5 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (false , true , '' , 'FULL ' ));
296+ $ response6 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (false , true , '' , 'PARTIAL ' ));
297+
298+ $ response7 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , true , '' , '' ));
299+ $ response8 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , true , 'FULL ' , 'FULL ' ));
300+ $ response9 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , true , 'PARTIAL ' , 'PARTIAL ' ));
301+ $ response10 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , true , 'FULL ' , 'PARTIAL ' ));
302+ $ response11 = $ this ->graphQlQuery ($ this ->getProductSearchQueryWithMatchType (true , true , 'PARTIAL ' , 'FULL ' ));
303+
304+ $ this ->assertEquals ($ response1 , $ response2 );
305+ $ this ->assertNotEquals ($ response2 , $ response3 );
306+ $ this ->assertEquals (2 , $ response1 ['products ' ]['total_count ' ]); // product 2, product 3
307+ $ this ->assertEquals (2 , $ response2 ['products ' ]['total_count ' ]); // product 2, product 3
308+ $ this ->assertEquals (4 , $ response3 ['products ' ]['total_count ' ]); // all
309+ $ this ->assertEquals ('life2 ' , $ response1 ['products ' ]['items ' ][1 ]['sku ' ]);
310+ $ this ->assertEquals ('life2 ' , $ response2 ['products ' ]['items ' ][1 ]['sku ' ]);
311+ $ this ->assertEquals ('lifelong4 ' , $ response3 ['products ' ]['items ' ][0 ]['sku ' ]);
312+
313+ $ this ->assertEquals ($ response4 , $ response5 );
314+ $ this ->assertNotEquals ($ response5 , $ response6 );
315+ $ this ->assertEquals (2 , $ response4 ['products ' ]['total_count ' ]); // product 1, product 3
316+ $ this ->assertEquals (2 , $ response5 ['products ' ]['total_count ' ]); // product 1, product 3
317+ $ this ->assertEquals (4 , $ response6 ['products ' ]['total_count ' ]); // all
318+ $ this ->assertEquals ('lifelong1 ' , $ response4 ['products ' ]['items ' ][1 ]['sku ' ]);
319+ $ this ->assertEquals ('lifelong1 ' , $ response5 ['products ' ]['items ' ][1 ]['sku ' ]);
320+ $ this ->assertEquals ('lifelong4 ' , $ response6 ['products ' ]['items ' ][0 ]['sku ' ]);
321+
322+ $ this ->assertEquals ($ response7 , $ response8 );
323+ $ this ->assertNotEquals ($ response8 , $ response9 );
324+ $ this ->assertEquals (1 , $ response7 ['products ' ]['total_count ' ]); // product 3
325+ $ this ->assertEquals (1 , $ response8 ['products ' ]['total_count ' ]); // product 3
326+ $ this ->assertEquals (4 , $ response9 ['products ' ]['total_count ' ]); // all
327+ $ this ->assertEquals (2 , $ response10 ['products ' ]['total_count ' ]); // product 2, product 3
328+ $ this ->assertEquals (2 , $ response11 ['products ' ]['total_count ' ]); // product 1, product 3
329+ $ this ->assertEquals ('life3 ' , $ response7 ['products ' ]['items ' ][0 ]['sku ' ]);
330+ $ this ->assertEquals ('life3 ' , $ response8 ['products ' ]['items ' ][0 ]['sku ' ]);
331+ $ this ->assertEquals ('lifelong4 ' , $ response9 ['products ' ]['items ' ][0 ]['sku ' ]);
332+ $ this ->assertEquals ('life2 ' , $ response10 ['products ' ]['items ' ][1 ]['sku ' ]);
333+ $ this ->assertEquals ('lifelong1 ' , $ response11 ['products ' ]['items ' ][1 ]['sku ' ]);
334+ }
335+
336+ /**
337+ * Get a combinations of queries which contain different match_type
338+ *
339+ * @param bool $filterByName
340+ * @param bool $filterByDescription
341+ * @param string $matchTypeName
342+ * @param string $matchTypeDescription
343+ * @return string
344+ */
345+ private function getProductSearchQueryWithMatchType (
346+ bool $ filterByName ,
347+ bool $ filterByDescription ,
348+ string $ matchTypeName = '' ,
349+ string $ matchTypeDescription = ''
350+ ): string {
351+ $ matchTypeName = $ matchTypeName ? 'match_type: ' . $ matchTypeName : '' ;
352+ $ matchTypeDescription = $ matchTypeDescription ? 'match_type: ' . $ matchTypeDescription : '' ;
353+ $ name = $ filterByName ? 'name : { match : "Life", ' .$ matchTypeName .'} ' : '' ;
354+ $ description = $ filterByDescription ? 'description: { match: "Life", ' .$ matchTypeDescription .'} ' : '' ;
355+ return <<<QUERY
356+ {
357+ products(filter :
358+ {
359+ $ name
360+ $ description
361+ }){
362+ total_count
363+ items {
364+ name
365+ sku
366+ description {
367+ html
368+ }
369+ }
370+ }
371+ }
372+ QUERY ;
373+ }
244374}
0 commit comments