12
12
use Magento \TestFramework \ObjectManager ;
13
13
use Magento \TestFramework \TestCase \GraphQlAbstract ;
14
14
use 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 ;
15
18
16
19
/**
17
20
* Test the GraphQL endpoint's URLResolver query to verify canonical URL's are correctly returned.
@@ -28,7 +31,7 @@ protected function setUp()
28
31
}
29
32
30
33
/**
31
- * Tests if target_path(canonical_url ) is resolved for Product entity
34
+ * Tests if target_path(relative_url ) is resolved for Product entity
32
35
*
33
36
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
34
37
*/
@@ -57,20 +60,20 @@ public function testProductUrlResolver()
57
60
urlResolver(url:" {$ urlPath }")
58
61
{
59
62
id
60
- canonical_url
63
+ relative_url
61
64
type
62
65
}
63
66
}
64
67
QUERY ;
65
68
$ response = $ this ->graphQlQuery ($ query );
66
69
$ this ->assertArrayHasKey ('urlResolver ' , $ response );
67
70
$ this ->assertEquals ($ product ->getEntityId (), $ response ['urlResolver ' ]['id ' ]);
68
- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
71
+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
69
72
$ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
70
73
}
71
74
72
75
/**
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
74
77
*
75
78
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
76
79
*/
@@ -101,15 +104,15 @@ public function testProductUrlWithCanonicalUrlInput()
101
104
urlResolver(url:" {$ canonicalPath }")
102
105
{
103
106
id
104
- canonical_url
107
+ relative_url
105
108
type
106
109
}
107
110
}
108
111
QUERY ;
109
112
$ response = $ this ->graphQlQuery ($ query );
110
113
$ this ->assertArrayHasKey ('urlResolver ' , $ response );
111
114
$ this ->assertEquals ($ product ->getEntityId (), $ response ['urlResolver ' ]['id ' ]);
112
- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
115
+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
113
116
$ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
114
117
}
115
118
@@ -144,15 +147,15 @@ public function testCategoryUrlResolver()
144
147
urlResolver(url:" {$ urlPath2 }")
145
148
{
146
149
id
147
- canonical_url
150
+ relative_url
148
151
type
149
152
}
150
153
}
151
154
QUERY ;
152
155
$ response = $ this ->graphQlQuery ($ query );
153
156
$ this ->assertArrayHasKey ('urlResolver ' , $ response );
154
157
$ this ->assertEquals ($ categoryId , $ response ['urlResolver ' ]['id ' ]);
155
- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
158
+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
156
159
$ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
157
160
}
158
161
@@ -180,14 +183,14 @@ public function testCMSPageUrlResolver()
180
183
urlResolver(url:" {$ requestPath }")
181
184
{
182
185
id
183
- canonical_url
186
+ relative_url
184
187
type
185
188
}
186
189
}
187
190
QUERY ;
188
191
$ response = $ this ->graphQlQuery ($ query );
189
192
$ this ->assertEquals ($ cmsPageId , $ response ['urlResolver ' ]['id ' ]);
190
- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
193
+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
191
194
$ this ->assertEquals (strtoupper (str_replace ('- ' , '_ ' , $ expectedEntityType )), $ response ['urlResolver ' ]['type ' ]);
192
195
}
193
196
@@ -223,15 +226,15 @@ public function testProductUrlRewriteResolver()
223
226
urlResolver(url:" {$ urlPath }")
224
227
{
225
228
id
226
- canonical_url
229
+ relative_url
227
230
type
228
231
}
229
232
}
230
233
QUERY ;
231
234
$ response = $ this ->graphQlQuery ($ query );
232
235
$ this ->assertArrayHasKey ('urlResolver ' , $ response );
233
236
$ this ->assertEquals ($ product ->getEntityId (), $ response ['urlResolver ' ]['id ' ]);
234
- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
237
+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
235
238
$ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
236
239
}
237
240
@@ -263,7 +266,7 @@ public function testInvalidUrlResolverInput()
263
266
urlResolver(url:" {$ urlPath }")
264
267
{
265
268
id
266
- canonical_url
269
+ relative_url
267
270
type
268
271
}
269
272
}
@@ -304,15 +307,15 @@ public function testCategoryUrlWithLeadingSlash()
304
307
urlResolver(url:"/ {$ urlPath }")
305
308
{
306
309
id
307
- canonical_url
310
+ relative_url
308
311
type
309
312
}
310
313
}
311
314
QUERY ;
312
315
$ response = $ this ->graphQlQuery ($ query );
313
316
$ this ->assertArrayHasKey ('urlResolver ' , $ response );
314
317
$ this ->assertEquals ($ categoryId , $ response ['urlResolver ' ]['id ' ]);
315
- $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['canonical_url ' ]);
318
+ $ this ->assertEquals ($ targetPath , $ response ['urlResolver ' ]['relative_url ' ]);
316
319
$ this ->assertEquals (strtoupper ($ expectedType ), $ response ['urlResolver ' ]['type ' ]);
317
320
}
318
321
@@ -321,22 +324,37 @@ public function testCategoryUrlWithLeadingSlash()
321
324
*/
322
325
public function testResolveSlash ()
323
326
{
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
+
324
342
$ query
325
343
= <<<QUERY
326
344
{
327
345
urlResolver(url:"/")
328
346
{
329
347
id
330
- canonical_url
348
+ relative_url
331
349
type
332
350
}
333
351
}
334
352
QUERY ;
335
353
$ response = $ this ->graphQlQuery ($ query );
336
354
337
355
$ 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 ' ]);
340
358
$ this ->assertEquals ('CMS_PAGE ' , $ response ['urlResolver ' ]['type ' ]);
341
359
}
342
360
}
0 commit comments