Skip to content

Commit

Permalink
Api-functional test for product with categories
Browse files Browse the repository at this point in the history
  • Loading branch information
rogyar committed Jul 20, 2018
1 parent 46a871e commit dfabfe5
Showing 1 changed file with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite as UrlRewriteDTO;

/**
* Test of getting child products info of configurable product on category request
* Test of getting URL rewrites data from products
*/
class UrlRewritesTest extends GraphQlAbstract
{
Expand Down Expand Up @@ -72,6 +72,60 @@ public function testProductWithNoCategoriesAssigned()
);
}

/**
*
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function testProductWithOneCategoryAssigned()
{

$query
= <<<QUERY
{
products (search:"Simple Product") {
items {
name,
sku,
description,
url_rewrites {
url,
parameters {
name,
value
}
}
}
}
}
QUERY;

$response = $this->graphQlQuery($query);

/** @var ProductRepositoryInterface $productRepository */
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
$product = $productRepository->get('simple', false, null, true);

$urlFinder = ObjectManager::getInstance()->get(UrlFinderInterface::class);

$rewritesCollection = $urlFinder->findAllByData([UrlRewriteDTO::ENTITY_ID => $product->getId()]);
$rewritesCount = count($rewritesCollection);

$this->assertArrayHasKey('url_rewrites', $response['products']['items'][0]);
$this->assertCount($rewritesCount, $response['products']['items'][0]['url_rewrites']);

for ($i = 0; $i < $rewritesCount; $i++) {
$urlRewrite = $rewritesCollection[$i];
$this->assertResponseFields(
$response['products']['items'][0]['url_rewrites'][$i],
[
"url" => $urlRewrite->getRequestPath(),
"parameters" => $this->getUrlParameters($urlRewrite->getTargetPath())
]
);
}
}

/**
* Parses target path and extracts parameters
*
Expand Down

0 comments on commit dfabfe5

Please sign in to comment.