Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 366e0b7

Browse files
committed
GraphQL - added functional test, removed unnecessary empty lines
1 parent 3ec840c commit 366e0b7

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Store\Model\StoreManagerInterface;
1616
use Magento\UrlRewrite\Model\UrlFinderInterface;
1717
use Magento\Store\Model\ScopeInterface;
18+
use Magento\Cms\Helper\Page;
1819

1920
/**
2021
* UrlRewrite field resolver, used for GraphQL request processing.
@@ -41,7 +42,6 @@ class UrlRewrite implements ResolverInterface
4142
*/
4243
private $scopeConfig;
4344

44-
4545
/**
4646
* @param UrlFinderInterface $urlFinder
4747
* @param StoreManagerInterface $storeManager
@@ -80,7 +80,7 @@ public function resolve(
8080
$url = ltrim($url, '/');
8181
} else if ($url === '/') {
8282
$homePageIdentifier = $this->scopeConfig->getValue(
83-
\Magento\Cms\Helper\Page::XML_PATH_HOME_PAGE,
83+
Page::XML_PATH_HOME_PAGE,
8484
ScopeInterface::SCOPE_STORE
8585
);
8686
$url = $homePageIdentifier;

dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,46 @@ public function testInvalidUrlResolverInput()
272272
$this->assertArrayHasKey('urlResolver', $response);
273273
$this->assertNull($response['urlResolver']);
274274
}
275+
276+
/**
277+
* Test for category entity with leading slash
278+
*/
279+
public function testCategoryUrlWithLeadingSlash()
280+
{
281+
$productSku = 'p002';
282+
$urlPath2 = 'cat-1.html';
283+
/** @var ProductRepositoryInterface $productRepository */
284+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
285+
$product = $productRepository->get($productSku, false, null, true);
286+
$storeId = $product->getStoreId();
287+
288+
/** @var UrlFinderInterface $urlFinder */
289+
$urlFinder = $this->objectManager->get(UrlFinderInterface::class);
290+
$actualUrls = $urlFinder->findOneByData(
291+
[
292+
'request_path' => $urlPath,
293+
'store_id' => $storeId
294+
]
295+
);
296+
$categoryId = $actualUrls->getEntityId();
297+
$targetPath = $actualUrls->getTargetPath();
298+
$expectedType = $actualUrls->getEntityType();
299+
300+
$query
301+
= <<<QUERY
302+
{
303+
urlResolver(url:"/{$urlPath2}")
304+
{
305+
id
306+
canonical_url
307+
type
308+
}
309+
}
310+
QUERY;
311+
$response = $this->graphQlQuery($query);
312+
$this->assertArrayHasKey('urlResolver', $response);
313+
$this->assertEquals($categoryId, $response['urlResolver']['id']);
314+
$this->assertEquals($targetPath, $response['urlResolver']['canonical_url']);
315+
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
316+
}
275317
}

0 commit comments

Comments
 (0)