Skip to content

Commit 6cbd253

Browse files
committed
MAGETWO-82728: Implement Functional test
- Addressed CR comments
1 parent be47646 commit 6cbd253

File tree

3 files changed

+275
-74
lines changed

3 files changed

+275
-74
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ProductSearchTest extends GraphQlAbstract
1818
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
1919
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2020
*/
21-
public function testQueryFilterSimpleProduct()
21+
public function testFilterProductsWithinSpecificPriceRangeSortedByNameDesc()
2222
{
2323
$query
2424
= <<<QUERY
@@ -32,7 +32,7 @@ public function testQueryFilterSimpleProduct()
3232
or:
3333
{
3434
sku:{like:"simple%"}
35-
name:{like:"simple%"}
35+
name:{like:"Simple%"}
3636
}
3737
}
3838
}
@@ -68,12 +68,10 @@ public function testQueryFilterSimpleProduct()
6868
* @var ProductRepositoryInterface $productRepository
6969
*/
7070
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
71-
// $product = $productRepository->get($prductSku, false, null, true);
7271
$product1 = $productRepository->get('simple1');
7372
$product2 = $productRepository->get('simple2');
7473
$product3 = $productRepository->get('simple3');
7574
$filteredProducts = [$product3, $product2, $product1];
76-
// rsort($filteredProducts);
7775

7876
$response = $this->graphQlQuery($query);
7977
$this->assertArrayHasKey('products', $response);
@@ -84,12 +82,12 @@ public function testQueryFilterSimpleProduct()
8482
}
8583

8684
/**
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
8886
*
89-
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products.php
87+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
9088
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
9189
*/
92-
public function testQueryFilterProductsWithPriceDesc()
90+
public function testFilterVisibleProductsWithMatchingSkuOrNameWithSpecialPrice()
9391
{
9492
$query
9593
= <<<QUERY
@@ -108,8 +106,8 @@ public function testQueryFilterProductsWithPriceDesc()
108106
}
109107
or:
110108
{
111-
visibility:{in:["1", "2", "3","4"]}
112-
weight:{gt:"1"}
109+
visibility:{in:["2", "3","4"]}
110+
weight:{eq:"1"}
113111
}
114112
}
115113
}
@@ -156,12 +154,12 @@ public function testQueryFilterProductsWithPriceDesc()
156154
}
157155

158156
/**
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
160158
*
161-
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products.php
159+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
162160
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
163161
*/
164-
public function testQuerySortAndPaginationMixedProducts1()
162+
public function testQueryProductsInCurrentPageSortedByPriceASC()
165163
{
166164
$query
167165
= <<<QUERY
@@ -174,16 +172,16 @@ public function testQuerySortAndPaginationMixedProducts1()
174172
price:{gt: "5", lt: "50"}
175173
or:
176174
{
177-
sku:{like:"simple%"}
178-
name:{like:"simple%"}
175+
sku:{like:"simple%"}
176+
name:{like:"simple%"}
179177
}
180178
}
181179
}
182180
pageSize:4
183181
currentPage:1
184182
sort:
185183
{
186-
name:ASC
184+
price:ASC
187185
}
188186
)
189187
{
@@ -204,38 +202,35 @@ public function testQuerySortAndPaginationMixedProducts1()
204202
page_size
205203
current_page
206204
}
207-
208205
}
209206
}
210207
QUERY;
211208
/**
212209
* @var ProductRepositoryInterface $productRepository
213210
*/
214211
$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');
221216
$filteredChildProducts = [$childProduct1, $childProduct2, $childProduct3, $childProduct4];
222217

223218
$response = $this->graphQlQuery($query);
224219
$this->assertArrayHasKey('products', $response);
225220
$this->assertArrayHasKey('total_count', $response['products']);
226-
$this->assertEquals(7, $response['products']['total_count']);
221+
$this->assertEquals(6, $response['products']['total_count']);
227222
$this->assertProductItems($filteredChildProducts, $response);
228223
$this->assertEquals(4, $response['products']['page_info']['page_size']);
229224
$this->assertEquals(1, $response['products']['page_info']['current_page']);
230225
}
231226

232227
/**
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
234229
*
235-
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products.php
230+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
236231
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
237232
*/
238-
public function testQuerySortAndPaginationMixedProducts2()
233+
public function testFilterProductsInNextPageSortedByNameASC()
239234
{
240235
$query
241236
= <<<QUERY
@@ -261,13 +256,13 @@ public function testQuerySortAndPaginationMixedProducts2()
261256
}
262257
)
263258
{
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
271266
weight
272267
visibility
273268
attribute_set_id
@@ -286,8 +281,6 @@ public function testQuerySortAndPaginationMixedProducts2()
286281
* @var ProductRepositoryInterface $productRepository
287282
*/
288283
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
289-
// $product = $productRepository->get($prductSku, false, null, true);
290-
291284
$product = $productRepository->get('simple1');
292285
$filteredProducts = [$product];
293286

@@ -297,82 +290,87 @@ public function testQuerySortAndPaginationMixedProducts2()
297290
$this->assertEquals(4, $response['products']['page_info']['page_size']);
298291
$this->assertEquals(2, $response['products']['page_info']['current_page']);
299292
}
293+
300294
/**
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
302296
*
303-
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products.php
297+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
304298
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
305299
*/
306-
public function testQueryFilterProductsWithSpecialPrice()
300+
public function testQuerySortByVisibilityAndPriceDESCWithDefaultPageSize()
307301
{
308302
$query
309303
= <<<QUERY
310304
{
311-
products(
305+
products(
312306
find:
313307
{
314308
and:
315309
{
316-
special_price:{neq:"null"}
317-
price:{lt:"50"}
318-
visibility:{neq:"1"}
319-
or:
310+
price:{gt: "5", lt: "60"}
311+
or:
320312
{
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+
}
325321
}
326-
pageSize:7
327-
currentPage:1
328-
sort:
329-
{
330-
sku:ASC
331-
}
332-
)
333-
{
334-
items
322+
sort:
335323
{
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+
}
345340
total_count
346341
page_info
347342
{
348343
page_size
349344
current_page
350-
}
345+
}
351346
}
352347
}
353348
QUERY;
354349
/**
355350
* @var ProductRepositoryInterface $productRepository
356351
*/
357352
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
358-
// $product = $productRepository->get($prductSku, false, null, true);
359353

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];
364362

365363
$response = $this->graphQlQuery($query);
366-
$this->assertEquals(3, $response['products']['total_count']);
364+
$this->assertEquals(6, $response['products']['total_count']);
367365
$this->assertProductItems($filteredProducts, $response);
368-
$this->assertEquals(7, $response['products']['page_info']['page_size']);
366+
$this->assertEquals(20, $response['products']['page_info']['page_size']);
369367
$this->assertEquals(1, $response['products']['page_info']['current_page']);
370368
}
371369

372370
/**
373371
* No items are returned if the conditions are not met
374372
*
375-
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products.php
373+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
376374
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
377375
*/
378376
public function testQueryFilterNoMatchingItems()

0 commit comments

Comments
 (0)