|
| 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\ProductRepositoryInterface; |
| 11 | +use Magento\TestFramework\ObjectManager; |
| 12 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 13 | +use Magento\UrlRewrite\Model\UrlFinderInterface; |
| 14 | +use Magento\TestFramework\Helper\Bootstrap; |
| 15 | +use Magento\UrlRewrite\Service\V1\Data\UrlRewrite as UrlRewriteDTO; |
| 16 | + |
| 17 | +/** |
| 18 | + * Test of getting URL rewrites data from products |
| 19 | + */ |
| 20 | +class ProductCanonicalUrlTest extends GraphQlAbstract |
| 21 | +{ |
| 22 | + /** @var ObjectManager $objectManager */ |
| 23 | + private $objectManager; |
| 24 | + |
| 25 | + /** |
| 26 | + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php |
| 27 | + * @magentoConfigFixture default_store catalog/seo/product_canonical_tag 1 |
| 28 | + */ |
| 29 | + public function testProductWithCanonicalLinksMetaTagSettingsEnabled() |
| 30 | + { |
| 31 | + $productSku = 'simple'; |
| 32 | + $query |
| 33 | + = <<<QUERY |
| 34 | +{ |
| 35 | + products (filter: {sku: {eq: "{$productSku}"}}) { |
| 36 | + items { |
| 37 | + name |
| 38 | + sku |
| 39 | + canonical_url |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | +QUERY; |
| 44 | + |
| 45 | + $response = $this->graphQlQuery($query); |
| 46 | + |
| 47 | + $this->assertEquals( |
| 48 | + $response['products']['items'][0]['canonical_url'], |
| 49 | + 'simple-product.html' |
| 50 | + ); |
| 51 | + $this->assertEquals($response['products']['items'][0]['sku'], 'simple'); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php |
| 56 | + * @magentoConfigFixture default_store catalog/seo/product_canonical_tag 0 |
| 57 | + */ |
| 58 | + public function testProductWithCanonicalLinksMetaTagSettingsDisabled() |
| 59 | + { |
| 60 | + $productSku = 'simple'; |
| 61 | + $query |
| 62 | + = <<<QUERY |
| 63 | +{ |
| 64 | + products (filter: {sku: {eq: "{$productSku}"}}) { |
| 65 | + items { |
| 66 | + name |
| 67 | + sku |
| 68 | + canonical_url |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +QUERY; |
| 73 | + |
| 74 | + $response = $this->graphQlQuery($query); |
| 75 | + $this->assertNull( |
| 76 | + $response['products']['items'][0]['canonical_url'] |
| 77 | + ); |
| 78 | + $this->assertEquals($response['products']['items'][0]['sku'], 'simple'); |
| 79 | + } |
| 80 | +} |
0 commit comments