Skip to content

Commit dfabfe5

Browse files
committed
Api-functional test for product with categories
1 parent 46a871e commit dfabfe5

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite as UrlRewriteDTO;
1515

1616
/**
17-
* Test of getting child products info of configurable product on category request
17+
* Test of getting URL rewrites data from products
1818
*/
1919
class UrlRewritesTest extends GraphQlAbstract
2020
{
@@ -72,6 +72,60 @@ public function testProductWithNoCategoriesAssigned()
7272
);
7373
}
7474

75+
/**
76+
*
77+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
78+
* @throws \Magento\Framework\Exception\NoSuchEntityException
79+
*/
80+
public function testProductWithOneCategoryAssigned()
81+
{
82+
83+
$query
84+
= <<<QUERY
85+
{
86+
products (search:"Simple Product") {
87+
items {
88+
name,
89+
sku,
90+
description,
91+
url_rewrites {
92+
url,
93+
parameters {
94+
name,
95+
value
96+
}
97+
}
98+
}
99+
}
100+
}
101+
QUERY;
102+
103+
$response = $this->graphQlQuery($query);
104+
105+
/** @var ProductRepositoryInterface $productRepository */
106+
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
107+
$product = $productRepository->get('simple', false, null, true);
108+
109+
$urlFinder = ObjectManager::getInstance()->get(UrlFinderInterface::class);
110+
111+
$rewritesCollection = $urlFinder->findAllByData([UrlRewriteDTO::ENTITY_ID => $product->getId()]);
112+
$rewritesCount = count($rewritesCollection);
113+
114+
$this->assertArrayHasKey('url_rewrites', $response['products']['items'][0]);
115+
$this->assertCount($rewritesCount, $response['products']['items'][0]['url_rewrites']);
116+
117+
for ($i = 0; $i < $rewritesCount; $i++) {
118+
$urlRewrite = $rewritesCollection[$i];
119+
$this->assertResponseFields(
120+
$response['products']['items'][0]['url_rewrites'][$i],
121+
[
122+
"url" => $urlRewrite->getRequestPath(),
123+
"parameters" => $this->getUrlParameters($urlRewrite->getTargetPath())
124+
]
125+
);
126+
}
127+
}
128+
75129
/**
76130
* Parses target path and extracts parameters
77131
*

0 commit comments

Comments
 (0)