Skip to content

Commit

Permalink
API-functional tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rogyar committed Nov 13, 2018
1 parent 9aacf0e commit 19c1f87
Showing 1 changed file with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\Catalog;

use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\Product\Attribute\Source\Status as productStatus;

/**
* Class CategoryProductsCountTest
*
* Test for Magento\CatalogGraphQl\Model\Resolver\Category\ProductsCount resolver
*/
class CategoryProductsCountTest extends GraphQlAbstract
{
/**
* @var ProductRepositoryInterface
*/
private $productRepository;

protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->productRepository = $objectManager->create(ProductRepositoryInterface::class);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testCategoryWithSaleableProduct()
{
$categoryId = 2;

$query = <<<QUERY
{
category(id: {$categoryId}) {
id
product_count
}
}
QUERY;
$response = $this->graphQlQuery($query);

self::assertEquals(1, $response['category']['product_count']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/category_product.php
*/
public function testCategoryWithInvisibleProduct()
{
$categoryId = 333;
$sku = 'simple333';

$product = $this->productRepository->get($sku);
$product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
$this->productRepository->save($product);

$query = <<<QUERY
{
category(id: {$categoryId}) {
id
product_count
}
}
QUERY;
$response = $this->graphQlQuery($query);

self::assertEquals(0, $response['category']['product_count']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
*/
public function testCategoryWithOutOfStockProductManageStockEnabled()
{
$categoryId = 2;

$query = <<<QUERY
{
category(id: {$categoryId}) {
id
product_count
}
}
QUERY;
$response = $this->graphQlQuery($query);

self::assertEquals(0, $response['category']['product_count']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/category_product.php
*/
public function testCategoryWithOutOfStockProductManageStockDisabled()
{
$categoryId = 333;

$query = <<<QUERY
{
category(id: {$categoryId}) {
id
product_count
}
}
QUERY;
$response = $this->graphQlQuery($query);

self::assertEquals(1, $response['category']['product_count']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/category_product.php
*/
public function testCategoryWithDisabledProduct()
{
$categoryId = 333;
$sku = 'simple333';

$product = $this->productRepository->get($sku);
$product->setStatus(ProductStatus::STATUS_DISABLED);
$this->productRepository->save($product);

$query = <<<QUERY
{
category(id: {$categoryId}) {
id
product_count
}
}
QUERY;
$response = $this->graphQlQuery($query);

self::assertEquals(0, $response['category']['product_count']);
}
}

0 comments on commit 19c1f87

Please sign in to comment.