Skip to content

Commit c5e8a15

Browse files
committed
MC-20158: [GraphQL] Redirects are not supported in urlResolver
- added few validations for redirectType
1 parent 73cded1 commit c5e8a15

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogUrlRewrite/UrlResolverTest.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ public function testProductUrlResolver()
6767
);
6868
$relativePath = $actualUrls->getRequestPath();
6969
$expectedType = $actualUrls->getEntityType();
70+
$redirectCode = $actualUrls->getRedirectType();
7071

7172
$this->queryUrlAndAssertResponse(
7273
(int) $product->getEntityId(),
7374
$urlPath,
7475
$relativePath,
75-
$expectedType
76+
$expectedType,
77+
$redirectCode
7678
);
7779
}
7880

@@ -116,12 +118,14 @@ public function testProductUrlWithNonSeoFriendlyUrlInput()
116118
$relativePath = $actualUrls->getRequestPath();
117119
$expectedType = $actualUrls->getEntityType();
118120
$nonSeoFriendlyPath = $actualUrls->getTargetPath();
121+
$redirectCode = $actualUrls->getRedirectType();
119122

120123
$this->queryUrlAndAssertResponse(
121124
(int) $product->getEntityId(),
122125
$nonSeoFriendlyPath,
123126
$relativePath,
124-
$expectedType
127+
$expectedType,
128+
$redirectCode
125129
);
126130
}
127131

@@ -172,15 +176,17 @@ public function testRedirectsAndCustomInput()
172176
(int) $product->getEntityId(),
173177
$renamedKey . $suffix,
174178
$actualUrls->getRequestPath(),
175-
$actualUrls->getEntityType()
179+
$actualUrls->getEntityType(),
180+
0
176181
);
177182

178183
// querying a url that's a redirect the active redirected final url
179184
$this->queryUrlAndAssertResponse(
180185
(int) $product->getEntityId(),
181186
$productSku . $suffix,
182187
$actualUrls->getRequestPath(),
183-
$actualUrls->getEntityType()
188+
$actualUrls->getEntityType(),
189+
301
184190
);
185191

186192
// create custom url that doesn't redirect
@@ -209,7 +215,8 @@ public function testRedirectsAndCustomInput()
209215
(int) $product->getEntityId(),
210216
$customUrl,
211217
$customUrl,
212-
$actualUrls->getEntityType()
218+
$actualUrls->getEntityType(),
219+
0
213220
);
214221

215222
// change custom url that does redirect
@@ -224,7 +231,8 @@ public function testRedirectsAndCustomInput()
224231
(int) $product->getEntityId(),
225232
$customUrl,
226233
$actualUrls->getRequestPath(),
227-
strtoupper($actualUrls->getEntityType())
234+
strtoupper($actualUrls->getEntityType()),
235+
301
228236
);
229237
$urlRewriteModel->delete();
230238
}
@@ -271,7 +279,8 @@ public function testCategoryUrlResolver()
271279
(int) $categoryId,
272280
$urlPath,
273281
$relativePath,
274-
$expectedType
282+
$expectedType,
283+
0
275284
);
276285
}
277286

@@ -321,7 +330,8 @@ public function testProductUrlRewriteResolver()
321330
(int) $product->getEntityId(),
322331
$urlPath,
323332
$relativePath,
324-
$expectedType
333+
$expectedType,
334+
0
325335
);
326336
}
327337

@@ -355,6 +365,7 @@ public function testInvalidUrlResolverInput()
355365
id
356366
relative_url
357367
type
368+
redirectCode
358369
}
359370
}
360371
QUERY;
@@ -400,12 +411,13 @@ public function testCategoryUrlWithLeadingSlash()
400411
QUERY;
401412
$response = $this->graphQlQuery($query);
402413
$urlPath = $response['category']['url_key'] . $response['category']['url_suffix'];
403-
414+
$urlPathWithLeadingSlash = "/{$urlPath}";
404415
$this->queryUrlAndAssertResponse(
405416
(int) $categoryId,
406-
$urlPath,
417+
$urlPathWithLeadingSlash,
407418
$relativePath,
408-
$expectedType
419+
$expectedType,
420+
0
409421
);
410422
}
411423

@@ -438,13 +450,15 @@ public function testGetNonExistentUrlRewrite()
438450
id
439451
relative_url
440452
type
453+
redirectCode
441454
}
442455
}
443456
QUERY;
444457
$response = $this->graphQlQuery($query);
445458
$this->assertArrayHasKey('urlResolver', $response);
446459
$this->assertEquals('PRODUCT', $response['urlResolver']['type']);
447460
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
461+
$this->assertEquals(0, $response['urlResolver']['redirectCode']);
448462
}
449463

450464
/**
@@ -454,12 +468,14 @@ public function testGetNonExistentUrlRewrite()
454468
* @param string $urlKey
455469
* @param string $relativePath
456470
* @param string $expectedType
471+
* @param int $redirectCode
457472
*/
458473
private function queryUrlAndAssertResponse(
459474
int $productId,
460475
string $urlKey,
461476
string $relativePath,
462-
string $expectedType
477+
string $expectedType,
478+
int $redirectCode
463479
): void {
464480
$query
465481
= <<<QUERY
@@ -469,6 +485,7 @@ private function queryUrlAndAssertResponse(
469485
id
470486
relative_url
471487
type
488+
redirectCode
472489
}
473490
}
474491
QUERY;
@@ -477,5 +494,6 @@ private function queryUrlAndAssertResponse(
477494
$this->assertEquals($productId, $response['urlResolver']['id']);
478495
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
479496
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
497+
$this->assertEquals($redirectCode, $response['urlResolver']['redirectCode']);
480498
}
481499
}

dev/tests/api-functional/testsuite/Magento/GraphQl/CmsUrlRewrite/UrlResolverTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ public function testCMSPageUrlResolver()
5353
id
5454
relative_url
5555
type
56+
redirectCode
5657
}
5758
}
5859
QUERY;
5960
$response = $this->graphQlQuery($query);
6061
$this->assertEquals($cmsPageId, $response['urlResolver']['id']);
6162
$this->assertEquals($requestPath, $response['urlResolver']['relative_url']);
6263
$this->assertEquals(strtoupper(str_replace('-', '_', $expectedEntityType)), $response['urlResolver']['type']);
64+
$this->assertEquals(0, $response['urlResolver']['redirectCode']);
6365

6466
// querying by non seo friendly url path should return seo friendly relative url
6567
$query
@@ -70,13 +72,15 @@ public function testCMSPageUrlResolver()
7072
id
7173
relative_url
7274
type
75+
redirectCode
7376
}
7477
}
7578
QUERY;
7679
$response = $this->graphQlQuery($query);
7780
$this->assertEquals($cmsPageId, $response['urlResolver']['id']);
7881
$this->assertEquals($requestPath, $response['urlResolver']['relative_url']);
7982
$this->assertEquals(strtoupper(str_replace('-', '_', $expectedEntityType)), $response['urlResolver']['type']);
83+
$this->assertEquals(0, $response['urlResolver']['redirectCode']);
8084
}
8185

8286
/**
@@ -102,6 +106,7 @@ public function testResolveSlash()
102106
id
103107
relative_url
104108
type
109+
redirectCode
105110
}
106111
}
107112
QUERY;
@@ -110,5 +115,6 @@ public function testResolveSlash()
110115
$this->assertEquals($homePageId, $response['urlResolver']['id']);
111116
$this->assertEquals($homePageIdentifier, $response['urlResolver']['relative_url']);
112117
$this->assertEquals('CMS_PAGE', $response['urlResolver']['type']);
118+
$this->assertEquals(0, $response['urlResolver']['redirectCode']);
113119
}
114120
}

dev/tests/api-functional/testsuite/Magento/GraphQl/UrlRewrite/UrlResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testNonExistentEntityUrlRewrite()
3939
id
4040
relative_url
4141
type
42+
redirectCode
4243
}
4344
}
4445
QUERY;

0 commit comments

Comments
 (0)