@@ -18,7 +18,7 @@ class ProductSearchTest extends GraphQlAbstract
18
18
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
19
19
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
20
20
*/
21
- public function testQueryFilterSimpleProduct ()
21
+ public function testFilterProductsWithinSpecificPriceRangeSortedByNameDesc ()
22
22
{
23
23
$ query
24
24
= <<<QUERY
@@ -32,7 +32,7 @@ public function testQueryFilterSimpleProduct()
32
32
or:
33
33
{
34
34
sku:{like:"simple%"}
35
- name:{like:"simple %"}
35
+ name:{like:"Simple %"}
36
36
}
37
37
}
38
38
}
@@ -68,12 +68,10 @@ public function testQueryFilterSimpleProduct()
68
68
* @var ProductRepositoryInterface $productRepository
69
69
*/
70
70
$ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
71
- // $product = $productRepository->get($prductSku, false, null, true);
72
71
$ product1 = $ productRepository ->get ('simple1 ' );
73
72
$ product2 = $ productRepository ->get ('simple2 ' );
74
73
$ product3 = $ productRepository ->get ('simple3 ' );
75
74
$ filteredProducts = [$ product3 , $ product2 , $ product1 ];
76
- // rsort($filteredProducts);
77
75
78
76
$ response = $ this ->graphQlQuery ($ query );
79
77
$ this ->assertArrayHasKey ('products ' , $ response );
@@ -84,12 +82,12 @@ public function testQueryFilterSimpleProduct()
84
82
}
85
83
86
84
/**
87
- * Requesting for items with either a matching SKU or NAME with a price < $60 and having a special price
85
+ * Request items that are visible in Catalog, Search or Both matching SKU or NAME and price < $60 with a special price and weight = 1 sorted by price in DESC
88
86
*
89
- * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products .php
87
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2 .php
90
88
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
91
89
*/
92
- public function testQueryFilterProductsWithPriceDesc ()
90
+ public function testFilterVisibleProductsWithMatchingSkuOrNameWithSpecialPrice ()
93
91
{
94
92
$ query
95
93
= <<<QUERY
@@ -108,8 +106,8 @@ public function testQueryFilterProductsWithPriceDesc()
108
106
}
109
107
or:
110
108
{
111
- visibility:{in:["1", " 2", "3","4"]}
112
- weight:{gt :"1"}
109
+ visibility:{in:["2", "3","4"]}
110
+ weight:{eq :"1"}
113
111
}
114
112
}
115
113
}
@@ -156,12 +154,12 @@ public function testQueryFilterProductsWithPriceDesc()
156
154
}
157
155
158
156
/**
159
- * Requesting for items that match a specific SKU or NAME within a certain price range sorted by NAME in DESC order
157
+ * Requesting for items that match a specific SKU or NAME within a certain price range sorted by Price in ASC order
160
158
*
161
- * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products .php
159
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2 .php
162
160
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
163
161
*/
164
- public function testQuerySortAndPaginationMixedProducts1 ()
162
+ public function testQueryProductsInCurrentPageSortedByPriceASC ()
165
163
{
166
164
$ query
167
165
= <<<QUERY
@@ -174,16 +172,16 @@ public function testQuerySortAndPaginationMixedProducts1()
174
172
price:{gt: "5", lt: "50"}
175
173
or:
176
174
{
177
- sku:{like:"simple%"}
178
- name:{like:"simple%"}
175
+ sku:{like:"simple%"}
176
+ name:{like:"simple%"}
179
177
}
180
178
}
181
179
}
182
180
pageSize:4
183
181
currentPage:1
184
182
sort:
185
183
{
186
- name :ASC
184
+ price :ASC
187
185
}
188
186
)
189
187
{
@@ -204,38 +202,35 @@ public function testQuerySortAndPaginationMixedProducts1()
204
202
page_size
205
203
current_page
206
204
}
207
-
208
205
}
209
206
}
210
207
QUERY ;
211
208
/**
212
209
* @var ProductRepositoryInterface $productRepository
213
210
*/
214
211
$ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
215
- // $product = $productRepository->get($prductSku, false, null, true);
216
- $ childProduct1 = $ productRepository ->get ('simple_31 ' );
217
- $ childProduct2 = $ productRepository ->get ('simple_32 ' );
218
- $ childProduct3 = $ productRepository ->get ('simple_41 ' );
219
- $ childProduct4 = $ productRepository ->get ('simple_42 ' );
220
- // $filteredChildProducts = [$childProduct1, $childProduct3, $childProduct2, $childProduct4];
212
+ $ childProduct1 = $ productRepository ->get ('simple1 ' );
213
+ $ childProduct2 = $ productRepository ->get ('simple2 ' );
214
+ $ childProduct3 = $ productRepository ->get ('simple_31 ' );
215
+ $ childProduct4 = $ productRepository ->get ('simple_32 ' );
221
216
$ filteredChildProducts = [$ childProduct1 , $ childProduct2 , $ childProduct3 , $ childProduct4 ];
222
217
223
218
$ response = $ this ->graphQlQuery ($ query );
224
219
$ this ->assertArrayHasKey ('products ' , $ response );
225
220
$ this ->assertArrayHasKey ('total_count ' , $ response ['products ' ]);
226
- $ this ->assertEquals (7 , $ response ['products ' ]['total_count ' ]);
221
+ $ this ->assertEquals (6 , $ response ['products ' ]['total_count ' ]);
227
222
$ this ->assertProductItems ($ filteredChildProducts , $ response );
228
223
$ this ->assertEquals (4 , $ response ['products ' ]['page_info ' ]['page_size ' ]);
229
224
$ this ->assertEquals (1 , $ response ['products ' ]['page_info ' ]['current_page ' ]);
230
225
}
231
226
232
227
/**
233
- * Verify the items in the second page is correct after sorting their name in ASC
228
+ * Verify the items in the second page is correct after sorting their name in ASC order
234
229
*
235
- * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products .php
230
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2 .php
236
231
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
237
232
*/
238
- public function testQuerySortAndPaginationMixedProducts2 ()
233
+ public function testFilterProductsInNextPageSortedByNameASC ()
239
234
{
240
235
$ query
241
236
= <<<QUERY
@@ -261,13 +256,13 @@ public function testQuerySortAndPaginationMixedProducts2()
261
256
}
262
257
)
263
258
{
264
- items
265
- {
266
- sku
267
- price
268
- name
269
- status
270
- type_id
259
+ items
260
+ {
261
+ sku
262
+ price
263
+ name
264
+ status
265
+ type_id
271
266
weight
272
267
visibility
273
268
attribute_set_id
@@ -286,8 +281,6 @@ public function testQuerySortAndPaginationMixedProducts2()
286
281
* @var ProductRepositoryInterface $productRepository
287
282
*/
288
283
$ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
289
- // $product = $productRepository->get($prductSku, false, null, true);
290
-
291
284
$ product = $ productRepository ->get ('simple1 ' );
292
285
$ filteredProducts = [$ product ];
293
286
@@ -297,82 +290,87 @@ public function testQuerySortAndPaginationMixedProducts2()
297
290
$ this ->assertEquals (4 , $ response ['products ' ]['page_info ' ]['page_size ' ]);
298
291
$ this ->assertEquals (2 , $ response ['products ' ]['page_info ' ]['current_page ' ]);
299
292
}
293
+
300
294
/**
301
- * Tests the items with special price returned after sorting sku in ASC
295
+ * Sorting by visibility and price in the DESC order from the filtered items with default pageSize
302
296
*
303
- * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products .php
297
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2 .php
304
298
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
305
299
*/
306
- public function testQueryFilterProductsWithSpecialPrice ()
300
+ public function testQuerySortByVisibilityAndPriceDESCWithDefaultPageSize ()
307
301
{
308
302
$ query
309
303
= <<<QUERY
310
304
{
311
- products(
305
+ products(
312
306
find:
313
307
{
314
308
and:
315
309
{
316
- special_price:{neq:"null"}
317
- price:{lt:"50"}
318
- visibility:{neq:"1"}
319
- or:
310
+ price:{gt: "5", lt: "60"}
311
+ or:
320
312
{
321
- sku:{like:"simple%"}
322
- name:{like:"config%"}
323
- }
324
- }
313
+ sku:{like:"%simple%"}
314
+ name:{like:"%Configurable%"}
315
+ }
316
+ or:
317
+ {
318
+ weight:{gt:"0"}
319
+ }
320
+ }
325
321
}
326
- pageSize:7
327
- currentPage:1
328
- sort:
329
- {
330
- sku:ASC
331
- }
332
- )
333
- {
334
- items
322
+ sort:
335
323
{
336
- sku
337
- price
338
- name
339
- weight
340
- status
341
- type_id
342
- visibility
343
- attribute_set_id
344
- }
324
+ visibility:DESC
325
+ price:DESC
326
+ }
327
+ )
328
+ {
329
+ items
330
+ {
331
+ sku
332
+ price
333
+ name
334
+ weight
335
+ status
336
+ type_id
337
+ visibility
338
+ attribute_set_id
339
+ }
345
340
total_count
346
341
page_info
347
342
{
348
343
page_size
349
344
current_page
350
- }
345
+ }
351
346
}
352
347
}
353
348
QUERY ;
354
349
/**
355
350
* @var ProductRepositoryInterface $productRepository
356
351
*/
357
352
$ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
358
- // $product = $productRepository->get($prductSku, false, null, true);
359
353
360
- $ productSplPrice1 = $ productRepository ->get ('simple1 ' );
361
- $ productSplPrice2 = $ productRepository ->get ('simple2 ' );
362
- $ productSplPrice3 = $ productRepository ->get ('simple3 ' );
363
- $ filteredProducts = [$ productSplPrice1 , $ productSplPrice2 , $ productSplPrice3 ];
354
+ $ visibleProduct1 = $ productRepository ->get ('simple1 ' );
355
+ $ visibleProduct2 = $ productRepository ->get ('simple2 ' );
356
+ $ visibleProduct3 = $ productRepository ->get ('simple_42 ' );
357
+ $ visibleProduct4 = $ productRepository ->get ('simple_41 ' );
358
+ $ visibleProduct5 = $ productRepository ->get ('simple_32 ' );
359
+ $ visibleProduct6 = $ productRepository ->get ('simple_31 ' );
360
+ $ filteredProducts = [$ visibleProduct1 , $ visibleProduct2 ,
361
+ $ visibleProduct3 , $ visibleProduct4 , $ visibleProduct5 , $ visibleProduct6 ];
364
362
365
363
$ response = $ this ->graphQlQuery ($ query );
366
- $ this ->assertEquals (3 , $ response ['products ' ]['total_count ' ]);
364
+ $ this ->assertEquals (6 , $ response ['products ' ]['total_count ' ]);
367
365
$ this ->assertProductItems ($ filteredProducts , $ response );
368
- $ this ->assertEquals (7 , $ response ['products ' ]['page_info ' ]['page_size ' ]);
366
+ $ this ->assertEquals (20 , $ response ['products ' ]['page_info ' ]['page_size ' ]);
369
367
$ this ->assertEquals (1 , $ response ['products ' ]['page_info ' ]['current_page ' ]);
370
368
}
371
369
372
370
/**
373
371
* No items are returned if the conditions are not met
374
372
*
375
- * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products .php
373
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2 .php
376
374
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
377
375
*/
378
376
public function testQueryFilterNoMatchingItems ()
0 commit comments