Skip to content

Commit 8baea72

Browse files
committed
MC-21491: Pricing :: FPT display settings
- fix test
1 parent d5d7003 commit 8baea72

File tree

1 file changed

+93
-142
lines changed

1 file changed

+93
-142
lines changed

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

Lines changed: 93 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Magento\TestFramework\TestCase\GraphQlAbstract;
1313
use Magento\UrlRewrite\Model\UrlFinderInterface;
1414
use Magento\UrlRewrite\Model\UrlRewrite;
15-
use Magento\UrlRewrite\Model\UrlPersistInterface;
1615

1716
/**
1817
* Test the GraphQL endpoint's URLResolver query to verify canonical URL's are correctly returned.
@@ -69,26 +68,16 @@ public function testProductUrlResolver()
6968
$relativePath = $actualUrls->getRequestPath();
7069
$expectedType = $actualUrls->getEntityType();
7170

72-
$query
73-
= <<<QUERY
74-
{
75-
urlResolver(url:"{$urlPath}")
76-
{
77-
id
78-
relative_url
79-
type
80-
}
81-
}
82-
QUERY;
83-
$response = $this->graphQlQuery($query);
84-
$this->assertArrayHasKey('urlResolver', $response);
85-
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
86-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
87-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
71+
$this->assertResponseFromGraphQl(
72+
(int) $product->getEntityId(),
73+
$urlPath,
74+
$relativePath,
75+
$expectedType
76+
);
8877
}
8978

9079
/**
91-
* Tests the use case where non seo friendly is provided as resolver input in the Query
80+
* Test the use case where non seo friendly is provided as resolver input in the Query
9281
*
9382
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
9483
*/
@@ -127,27 +116,17 @@ public function testProductUrlWithNonSeoFriendlyUrlInput()
127116
$relativePath = $actualUrls->getRequestPath();
128117
$expectedType = $actualUrls->getEntityType();
129118
$nonSeoFriendlyPath = $actualUrls->getTargetPath();
130-
$query
131-
= <<<QUERY
132-
{
133-
urlResolver(url:"{$nonSeoFriendlyPath}")
134-
{
135-
id
136-
relative_url
137-
type
138-
}
139-
}
140-
QUERY;
141-
$response = $this->graphQlQuery($query);
142-
$this->assertArrayHasKey('urlResolver', $response);
143-
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
144-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
145-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
146-
}
147119

120+
$this->assertResponseFromGraphQl(
121+
(int) $product->getEntityId(),
122+
$nonSeoFriendlyPath,
123+
$relativePath,
124+
$expectedType
125+
);
126+
}
148127

149128
/**
150-
* Tests the use case where non seo friendly is provided as resolver input in the Query
129+
* Test the use case where non seo friendly is provided as resolver input in the Query
151130
*
152131
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
153132
*/
@@ -180,6 +159,7 @@ public function testRedirectsAndCustomInput()
180159
QUERY;
181160
$response = $this->graphQlQuery($query);
182161
$urlPath = $response['products']['items'][0]['url_key'] . $response['products']['items'][0]['url_suffix'];
162+
$suffix = $response['products']['items'][0]['url_suffix'];
183163

184164
/** @var UrlFinderInterface $urlFinder */
185165
$urlFinder = $this->objectManager->get(UrlFinderInterface::class);
@@ -190,44 +170,20 @@ public function testRedirectsAndCustomInput()
190170
]
191171
);
192172
// querying the end redirect gives the same record
193-
$relativePath = $actualUrls->getRequestPath();
194-
$expectedType = $actualUrls->getEntityType();
195-
$query
196-
= <<<QUERY
197-
{
198-
urlResolver(url:"{$renamedKey}.html")
199-
{
200-
id
201-
relative_url
202-
type
203-
}
204-
}
205-
QUERY;
206-
$response = $this->graphQlQuery($query);
207-
$this->assertArrayHasKey('urlResolver', $response);
208-
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
209-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
210-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
211-
173+
$this->assertResponseFromGraphQl(
174+
(int) $product->getEntityId(),
175+
$renamedKey . $suffix,
176+
$actualUrls->getRequestPath(),
177+
$actualUrls->getEntityType()
178+
);
212179

213180
// querying a url that's a redirect the active redirected final url
214-
$query
215-
= <<<QUERY
216-
{
217-
urlResolver(url:"{$productSku}.html")
218-
{
219-
id
220-
relative_url
221-
type
222-
}
223-
}
224-
QUERY;
225-
$response = $this->graphQlQuery($query);
226-
$this->assertArrayHasKey('urlResolver', $response);
227-
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
228-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
229-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
230-
181+
$this->assertResponseFromGraphQl(
182+
(int) $product->getEntityId(),
183+
$productSku . $suffix,
184+
$actualUrls->getRequestPath(),
185+
$actualUrls->getEntityType()
186+
);
231187

232188
// create custom url that doesn't redirect
233189
/** @var UrlRewrite $urlRewriteModel */
@@ -251,44 +207,35 @@ public function testRedirectsAndCustomInput()
251207
$urlRewriteModel->save();
252208

253209
// querying a custom url that should return the target entity but relative should be the custom url
254-
$query
255-
= <<<QUERY
256-
{
257-
urlResolver(url:"{$customUrl}")
258-
{
259-
id
260-
relative_url
261-
type
262-
}
263-
}
264-
QUERY;
265-
$response = $this->graphQlQuery($query);
266-
$this->assertArrayHasKey('urlResolver', $response);
267-
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
268-
$this->assertEquals($customUrl, $response['urlResolver']['relative_url']);
269-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
270-
210+
$this->assertResponseFromGraphQl(
211+
(int) $product->getEntityId(),
212+
$customUrl,
213+
$customUrl,
214+
$actualUrls->getEntityType()
215+
);
271216

272217
// change custom url that does redirect
273218
$urlRewriteModel->setRedirectType('301');
274219
$urlRewriteModel->setId($urlRewriteModel->getId());
275220
$urlRewriteModel->save();
276221

277-
//modifying query to avoid getting cached values.
222+
//modifying query by adding spaces to avoid getting cached values.
278223
$query
279224
= <<<QUERY
280-
{
225+
{
281226
urlResolver(url:"{$customUrl}")
282227
{
283-
id relative_url type
228+
id
229+
relative_url
230+
type
284231
}
285232
}
286233
QUERY;
287234
$response = $this->graphQlQuery($query);
288235
$this->assertArrayHasKey('urlResolver', $response);
289236
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
290-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
291-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
237+
$this->assertEquals($actualUrls->getRequestPath(), $response['urlResolver']['relative_url']);
238+
$this->assertEquals(strtoupper($actualUrls->getEntityType()), $response['urlResolver']['type']);
292239

293240
$urlRewriteModel->delete();
294241
}
@@ -331,26 +278,16 @@ public function testCategoryUrlResolver()
331278
$response = $this->graphQlQuery($query);
332279
$urlPath = $response['category']['url_key'] . $response['category']['url_suffix'];
333280

334-
$query
335-
= <<<QUERY
336-
{
337-
urlResolver(url:"{$urlPath}")
338-
{
339-
id
340-
relative_url
341-
type
342-
}
343-
}
344-
QUERY;
345-
$response = $this->graphQlQuery($query);
346-
$this->assertArrayHasKey('urlResolver', $response);
347-
$this->assertEquals($categoryId, $response['urlResolver']['id']);
348-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
349-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
281+
$this->assertResponseFromGraphQl(
282+
(int) $categoryId,
283+
$urlPath,
284+
$relativePath,
285+
$expectedType
286+
);
350287
}
351288

352289
/**
353-
* Tests the use case where the url_key of the existing product is changed
290+
* Test the use case where the url_key of the existing product is changed
354291
*
355292
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
356293
*/
@@ -390,22 +327,13 @@ public function testProductUrlRewriteResolver()
390327
);
391328
$relativePath = $actualUrls->getRequestPath();
392329
$expectedType = $actualUrls->getEntityType();
393-
$query
394-
= <<<QUERY
395-
{
396-
urlResolver(url:"{$urlPath}")
397-
{
398-
id
399-
relative_url
400-
type
401-
}
402-
}
403-
QUERY;
404-
$response = $this->graphQlQuery($query);
405-
$this->assertArrayHasKey('urlResolver', $response);
406-
$this->assertEquals($product->getEntityId(), $response['urlResolver']['id']);
407-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
408-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
330+
331+
$this->assertResponseFromGraphQl(
332+
(int) $product->getEntityId(),
333+
$urlPath,
334+
$relativePath,
335+
$expectedType
336+
);
409337
}
410338

411339
/**
@@ -484,21 +412,12 @@ public function testCategoryUrlWithLeadingSlash()
484412
$response = $this->graphQlQuery($query);
485413
$urlPath = $response['category']['url_key'] . $response['category']['url_suffix'];
486414

487-
$query = <<<QUERY
488-
{
489-
urlResolver(url:"/{$urlPath}")
490-
{
491-
id
492-
relative_url
493-
type
494-
}
495-
}
496-
QUERY;
497-
$response = $this->graphQlQuery($query);
498-
$this->assertArrayHasKey('urlResolver', $response);
499-
$this->assertEquals($categoryId, $response['urlResolver']['id']);
500-
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
501-
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
415+
$this->assertResponseFromGraphQl(
416+
(int) $categoryId,
417+
$urlPath,
418+
$relativePath,
419+
$expectedType
420+
);
502421
}
503422

504423
/**
@@ -538,4 +457,36 @@ public function testGetNonExistentUrlRewrite()
538457
$this->assertEquals('PRODUCT', $response['urlResolver']['type']);
539458
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
540459
}
460+
461+
/**
462+
* Assert response from GraphQl
463+
*
464+
* @param string $productId
465+
* @param string $urlKey
466+
* @param string $relativePath
467+
* @param string $expectedType
468+
*/
469+
private function assertResponseFromGraphQl(
470+
int $productId,
471+
string $urlKey,
472+
string $relativePath,
473+
string $expectedType
474+
): void {
475+
$query
476+
= <<<QUERY
477+
{
478+
urlResolver(url:"{$urlKey}")
479+
{
480+
id
481+
relative_url
482+
type
483+
}
484+
}
485+
QUERY;
486+
$response = $this->graphQlQuery($query);
487+
$this->assertArrayHasKey('urlResolver', $response);
488+
$this->assertEquals($productId, $response['urlResolver']['id']);
489+
$this->assertEquals($relativePath, $response['urlResolver']['relative_url']);
490+
$this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']);
491+
}
541492
}

0 commit comments

Comments
 (0)