|
14 | 14 | use Magento\UrlRewrite\Service\V1\Data\UrlRewrite as UrlRewriteDTO;
|
15 | 15 |
|
16 | 16 | /**
|
17 |
| - * Test of getting child products info of configurable product on category request |
| 17 | + * Test of getting URL rewrites data from products |
18 | 18 | */
|
19 | 19 | class UrlRewritesTest extends GraphQlAbstract
|
20 | 20 | {
|
@@ -72,6 +72,60 @@ public function testProductWithNoCategoriesAssigned()
|
72 | 72 | );
|
73 | 73 | }
|
74 | 74 |
|
| 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 | + |
75 | 129 | /**
|
76 | 130 | * Parses target path and extracts parameters
|
77 | 131 | *
|
|
0 commit comments