Skip to content

Commit 256ff9b

Browse files
committed
MC-21811: Canonical_url displays the backend domain instead of relative
- added test for category canonical_url
1 parent 2a54601 commit 256ff9b

File tree

2 files changed

+96
-13
lines changed

2 files changed

+96
-13
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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\Model\ResourceModel\Category\Collection as CategoryCollection;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\ObjectManager;
13+
use Magento\TestFramework\TestCase\GraphQlAbstract;
14+
use Magento\Catalog\Api\Data\CategoryInterface;
15+
16+
/**
17+
* Test for getting canonical url data from category
18+
*/
19+
class CategoryCanonicalUrlTest extends GraphQlAbstract
20+
{
21+
/** @var ObjectManager $objectManager */
22+
private $objectManager;
23+
24+
/**
25+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
26+
* @magentoConfigFixture default_store catalog/seo/category_canonical_tag 1
27+
*/
28+
public function testCategoryWithCanonicalLinksMetaTagSettingsEnabled()
29+
{
30+
$this->objectManager = Bootstrap::getObjectManager();
31+
/** @var CategoryCollection $categoryCollection */
32+
$categoryCollection = $this->objectManager->create(CategoryCollection::class);
33+
$categoryCollection->addFieldToFilter('name', 'Category 1.1.1');
34+
/** @var CategoryInterface $category */
35+
$category = $categoryCollection->getFirstItem();
36+
$categoryId = $category->getId();
37+
$query = <<<QUERY
38+
{
39+
categoryList(filters: {ids: {in: ["$categoryId"]}}) {
40+
id
41+
name
42+
url_key
43+
url_suffix
44+
canonical_url
45+
}
46+
}
47+
QUERY;
48+
49+
$response = $this->graphQlQuery($query);
50+
$this->assertNotEmpty($response['categoryList'], 'Category list should not be empty');
51+
$this->assertEquals('.html', $response['categoryList'][0]['url_suffix']);
52+
$this->assertEquals(
53+
'category-1/category-1-1/category-1-1-1.html',
54+
$response['categoryList'][0]['canonical_url']
55+
);
56+
}
57+
58+
/**
59+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
60+
* @magentoConfigFixture default_store catalog/seo/category_canonical_tag 0
61+
*/
62+
public function testCategoryWithCanonicalLinksMetaTagSettingsDisabled()
63+
{
64+
$this->objectManager = Bootstrap::getObjectManager();
65+
/** @var CategoryCollection $categoryCollection */
66+
$categoryCollection = $this->objectManager->create(CategoryCollection::class);
67+
$categoryCollection->addFieldToFilter('name', 'Category 1.1');
68+
/** @var CategoryInterface $category */
69+
$category = $categoryCollection->getFirstItem();
70+
$categoryId = $category->getId();
71+
$query = <<<QUERY
72+
{
73+
categoryList(filters: {ids: {in: ["$categoryId"]}}) {
74+
id
75+
name
76+
url_key
77+
canonical_url
78+
}
79+
}
80+
QUERY;
81+
82+
$response = $this->graphQlQuery($query);
83+
$this->assertNotEmpty($response['categoryList'], 'Category list should not be empty');
84+
$this->assertNull(
85+
$response['categoryList'][0]['canonical_url']
86+
);
87+
$this->assertEquals('category-1-1', $response['categoryList'][0]['url_key']);
88+
}
89+
}

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,17 @@
77

88
namespace Magento\GraphQl\Catalog;
99

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
11-
use Magento\TestFramework\ObjectManager;
1210
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;
1611

1712
/**
18-
* Test of getting URL rewrites data from products
13+
* Test for getting canonical_url for products
1914
*/
2015
class ProductCanonicalUrlTest extends GraphQlAbstract
2116
{
22-
/** @var ObjectManager $objectManager */
23-
private $objectManager;
24-
2517
/**
2618
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
2719
* @magentoConfigFixture default_store catalog/seo/product_canonical_tag 1
20+
*
2821
*/
2922
public function testProductWithCanonicalLinksMetaTagSettingsEnabled()
3023
{
@@ -43,12 +36,13 @@ public function testProductWithCanonicalLinksMetaTagSettingsEnabled()
4336
QUERY;
4437

4538
$response = $this->graphQlQuery($query);
39+
$this->assertNotEmpty($response['products']['items']);
4640

4741
$this->assertEquals(
48-
$response['products']['items'][0]['canonical_url'],
49-
'simple-product.html'
42+
'simple-product.html',
43+
$response['products']['items'][0]['canonical_url']
5044
);
51-
$this->assertEquals($response['products']['items'][0]['sku'], 'simple');
45+
$this->assertEquals('simple', $response['products']['items'][0]['sku']);
5246
}
5347

5448
/**
@@ -75,6 +69,6 @@ public function testProductWithCanonicalLinksMetaTagSettingsDisabled()
7569
$this->assertNull(
7670
$response['products']['items'][0]['canonical_url']
7771
);
78-
$this->assertEquals($response['products']['items'][0]['sku'], 'simple');
72+
$this->assertEquals('simple', $response['products']['items'][0]['sku']);
7973
}
8074
}

0 commit comments

Comments
 (0)