Skip to content

Commit 19c1f87

Browse files
committed
API-functional tests coverage
1 parent 9aacf0e commit 19c1f87

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Catalog;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\Catalog\Model\Product\Visibility;
14+
use Magento\Catalog\Model\Product\Attribute\Source\Status as productStatus;
15+
16+
/**
17+
* Class CategoryProductsCountTest
18+
*
19+
* Test for Magento\CatalogGraphQl\Model\Resolver\Category\ProductsCount resolver
20+
*/
21+
class CategoryProductsCountTest extends GraphQlAbstract
22+
{
23+
/**
24+
* @var ProductRepositoryInterface
25+
*/
26+
private $productRepository;
27+
28+
protected function setUp()
29+
{
30+
$objectManager = Bootstrap::getObjectManager();
31+
$this->productRepository = $objectManager->create(ProductRepositoryInterface::class);
32+
}
33+
34+
/**
35+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
36+
*/
37+
public function testCategoryWithSaleableProduct()
38+
{
39+
$categoryId = 2;
40+
41+
$query = <<<QUERY
42+
{
43+
category(id: {$categoryId}) {
44+
id
45+
product_count
46+
}
47+
}
48+
QUERY;
49+
$response = $this->graphQlQuery($query);
50+
51+
self::assertEquals(1, $response['category']['product_count']);
52+
}
53+
54+
/**
55+
* @magentoApiDataFixture Magento/Catalog/_files/category_product.php
56+
*/
57+
public function testCategoryWithInvisibleProduct()
58+
{
59+
$categoryId = 333;
60+
$sku = 'simple333';
61+
62+
$product = $this->productRepository->get($sku);
63+
$product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
64+
$this->productRepository->save($product);
65+
66+
$query = <<<QUERY
67+
{
68+
category(id: {$categoryId}) {
69+
id
70+
product_count
71+
}
72+
}
73+
QUERY;
74+
$response = $this->graphQlQuery($query);
75+
76+
self::assertEquals(0, $response['category']['product_count']);
77+
}
78+
79+
/**
80+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
81+
*/
82+
public function testCategoryWithOutOfStockProductManageStockEnabled()
83+
{
84+
$categoryId = 2;
85+
86+
$query = <<<QUERY
87+
{
88+
category(id: {$categoryId}) {
89+
id
90+
product_count
91+
}
92+
}
93+
QUERY;
94+
$response = $this->graphQlQuery($query);
95+
96+
self::assertEquals(0, $response['category']['product_count']);
97+
}
98+
99+
/**
100+
* @magentoApiDataFixture Magento/Catalog/_files/category_product.php
101+
*/
102+
public function testCategoryWithOutOfStockProductManageStockDisabled()
103+
{
104+
$categoryId = 333;
105+
106+
$query = <<<QUERY
107+
{
108+
category(id: {$categoryId}) {
109+
id
110+
product_count
111+
}
112+
}
113+
QUERY;
114+
$response = $this->graphQlQuery($query);
115+
116+
self::assertEquals(1, $response['category']['product_count']);
117+
}
118+
119+
/**
120+
* @magentoApiDataFixture Magento/Catalog/_files/category_product.php
121+
*/
122+
public function testCategoryWithDisabledProduct()
123+
{
124+
$categoryId = 333;
125+
$sku = 'simple333';
126+
127+
$product = $this->productRepository->get($sku);
128+
$product->setStatus(ProductStatus::STATUS_DISABLED);
129+
$this->productRepository->save($product);
130+
131+
$query = <<<QUERY
132+
{
133+
category(id: {$categoryId}) {
134+
id
135+
product_count
136+
}
137+
}
138+
QUERY;
139+
$response = $this->graphQlQuery($query);
140+
141+
self::assertEquals(0, $response['category']['product_count']);
142+
}
143+
}

0 commit comments

Comments
 (0)