Skip to content

Commit 665ec85

Browse files
committed
Api-functional test added
1 parent 83dc64e commit 665ec85

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Api\Data\CategoryInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\TestFramework\ObjectManager;
14+
use Magento\TestFramework\TestCase\GraphQlAbstract;
15+
16+
/**
17+
* Test for checking that category description directives are rendered correctly
18+
*/
19+
class CategoryWithDescriptionDirectivesTest extends GraphQlAbstract
20+
{
21+
/**
22+
* @var \Magento\TestFramework\ObjectManager
23+
*/
24+
private $objectManager;
25+
26+
protected function setUp()
27+
{
28+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
29+
}
30+
31+
/**
32+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
33+
*/
34+
public function testHtmlDirectivesRendered()
35+
{
36+
$categoryId = 333;
37+
$mediaFilePath = '/path/to/mediafile';
38+
/** @var StoreManagerInterface $storeManager */
39+
$storeManager = ObjectManager::getInstance()->get(StoreManagerInterface::class);
40+
$storeBaseUrl = $storeManager->getStore()->getBaseUrl();
41+
42+
/* Remove index.php from base URL */
43+
$storeBaseUrlParts = explode('/index.php', $storeBaseUrl);
44+
$storeBaseUrl = $storeBaseUrlParts[0];
45+
46+
/** @var CategoryRepositoryInterface $categoryRepository */
47+
$categoryRepository = ObjectManager::getInstance()->get(CategoryRepositoryInterface::class);
48+
/** @var CategoryInterface $category */
49+
$category = $categoryRepository->get($categoryId);
50+
$category->setDescription('Test: {{media url="' . $mediaFilePath . '"}}');
51+
$categoryRepository->save($category);
52+
53+
$query = <<<QUERY
54+
{
55+
category(id: {$categoryId}) {
56+
description
57+
}
58+
}
59+
QUERY;
60+
$response = $this->graphQlQuery($query);
61+
62+
self::assertNotContains('media url', $response['category']['description']);
63+
self::assertContains($storeBaseUrl, $response['category']['description']);
64+
}
65+
}

0 commit comments

Comments
 (0)