1212use Magento \TestFramework \ObjectManager ;
1313use Magento \TestFramework \TestCase \GraphQlAbstract ;
1414use Magento \UrlRewrite \Model \UrlFinderInterface ;
15+ use Magento \Cms \Helper \Page as PageHelper ;
16+ use Magento \Store \Model \ScopeInterface ;
17+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1518
1619/**
1720 * Test the GraphQL endpoint's URLResolver query to verify canonical URL's are correctly returned.
@@ -28,7 +31,7 @@ protected function setUp()
2831 }
2932
3033 /**
31- * Tests if target_path(canonical_url ) is resolved for Product entity
34+ * Tests if target_path(relative_url ) is resolved for Product entity
3235 *
3336 * @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
3437 */
@@ -57,20 +60,20 @@ public function testProductUrlResolver()
5760 urlResolver(url:" {$ urlPath }")
5861 {
5962 id
60- canonical_url
63+ relative_url
6164 type
6265 }
6366}
6467QUERY ;
6568 $ response = $ this ->graphQlQuery ($ query );
6669 $ this ->assertArrayHasKey ('urlResolver ' , $ response );
6770 $ this ->assertEquals ($ product ->getEntityId (), $ response ['urlResolver ' ]['id ' ]);
68- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
71+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
6972 $ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
7073 }
7174
7275 /**
73- * Tests the use case where canonical_url is provided as resolver input in the Query
76+ * Tests the use case where relative_url is provided as resolver input in the Query
7477 *
7578 * @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
7679 */
@@ -101,15 +104,15 @@ public function testProductUrlWithCanonicalUrlInput()
101104 urlResolver(url:" {$ canonicalPath }")
102105 {
103106 id
104- canonical_url
107+ relative_url
105108 type
106109 }
107110}
108111QUERY ;
109112 $ response = $ this ->graphQlQuery ($ query );
110113 $ this ->assertArrayHasKey ('urlResolver ' , $ response );
111114 $ this ->assertEquals ($ product ->getEntityId (), $ response ['urlResolver ' ]['id ' ]);
112- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
115+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
113116 $ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
114117 }
115118
@@ -144,15 +147,15 @@ public function testCategoryUrlResolver()
144147 urlResolver(url:" {$ urlPath2 }")
145148 {
146149 id
147- canonical_url
150+ relative_url
148151 type
149152 }
150153}
151154QUERY ;
152155 $ response = $ this ->graphQlQuery ($ query );
153156 $ this ->assertArrayHasKey ('urlResolver ' , $ response );
154157 $ this ->assertEquals ($ categoryId , $ response ['urlResolver ' ]['id ' ]);
155- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
158+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
156159 $ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
157160 }
158161
@@ -180,14 +183,14 @@ public function testCMSPageUrlResolver()
180183 urlResolver(url:" {$ requestPath }")
181184 {
182185 id
183- canonical_url
186+ relative_url
184187 type
185188 }
186189}
187190QUERY ;
188191 $ response = $ this ->graphQlQuery ($ query );
189192 $ this ->assertEquals ($ cmsPageId , $ response ['urlResolver ' ]['id ' ]);
190- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
193+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
191194 $ this ->assertEquals (strtoupper (str_replace ('- ' , '_ ' , $ expectedEntityType )), $ response ['urlResolver ' ]['type ' ]);
192195 }
193196
@@ -223,15 +226,15 @@ public function testProductUrlRewriteResolver()
223226 urlResolver(url:" {$ urlPath }")
224227 {
225228 id
226- canonical_url
229+ relative_url
227230 type
228231 }
229232}
230233QUERY ;
231234 $ response = $ this ->graphQlQuery ($ query );
232235 $ this ->assertArrayHasKey ('urlResolver ' , $ response );
233236 $ this ->assertEquals ($ product ->getEntityId (), $ response ['urlResolver ' ]['id ' ]);
234- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
237+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
235238 $ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
236239 }
237240
@@ -263,7 +266,7 @@ public function testInvalidUrlResolverInput()
263266 urlResolver(url:" {$ urlPath }")
264267 {
265268 id
266- canonical_url
269+ relative_url
267270 type
268271 }
269272}
@@ -304,15 +307,15 @@ public function testCategoryUrlWithLeadingSlash()
304307 urlResolver(url:"/ {$ urlPath }")
305308 {
306309 id
307- canonical_url
310+ relative_url
308311 type
309312 }
310313}
311314QUERY ;
312315 $ response = $ this ->graphQlQuery ($ query );
313316 $ this ->assertArrayHasKey ('urlResolver ' , $ response );
314317 $ this ->assertEquals ($ categoryId , $ response ['urlResolver ' ]['id ' ]);
315- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
318+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
316319 $ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
317320 }
318321
@@ -321,22 +324,37 @@ public function testCategoryUrlWithLeadingSlash()
321324 */
322325 public function testResolveSlash ()
323326 {
327+ /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface */
328+ $ scopeConfigInterface = $ this ->objectManager ->get (ScopeConfigInterface::class);
329+ $ homePageIdentifier = $ scopeConfigInterface ->getValue (PageHelper::XML_PATH_HOME_PAGE , ScopeInterface::SCOPE_STORE );
330+
331+ /** @var \Magento\Cms\Model\Page $page */
332+ $ page = $ this ->objectManager ->get (\Magento \Cms \Model \Page::class);
333+ $ page ->load ($ homePageIdentifier );
334+ $ homePageId = $ page ->getId ();
335+
336+ /** @var \Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator $urlPathGenerator */
337+ $ urlPathGenerator = $ this ->objectManager ->get (\Magento \CmsUrlRewrite \Model \CmsPageUrlPathGenerator::class);
338+
339+ /** @param \Magento\Cms\Api\Data\PageInterface $page */
340+ $ targetPath = $ urlPathGenerator ->getCanonicalUrlPath ($ page );
341+
324342 $ query
325343 = <<<QUERY
326344{
327345 urlResolver(url:"/")
328346 {
329347 id
330- canonical_url
348+ relative_url
331349 type
332350 }
333351}
334352QUERY ;
335353 $ response = $ this ->graphQlQuery ($ query );
336354
337355 $ this ->assertArrayHasKey ('urlResolver ' , $ response );
338- $ this ->assertEquals (2 , $ response ['urlResolver ' ]['id ' ]);
339- $ this ->assertEquals (' cms/page/view/page_id/2 ' , $ response ['urlResolver ' ]['canonical_url ' ]);
356+ $ this ->assertEquals ($ homePageId , $ response ['urlResolver ' ]['id ' ]);
357+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
340358 $ this ->assertEquals ('CMS_PAGE ' , $ response ['urlResolver ' ]['type ' ]);
341359 }
342360}
0 commit comments