Skip to content

Commit fafa1d5

Browse files
committed
MC-15959: Implement caching for url resolver
- refactor test
1 parent d5a9629 commit fafa1d5

File tree

2 files changed

+55
-78
lines changed

2 files changed

+55
-78
lines changed

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Cms/CmsPageCacheTest.php

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Cms\Model\PageRepository;
1212
use Magento\GraphQl\Controller\GraphQl;
1313
use Magento\GraphQlCache\Controller\AbstractGraphqlCacheTest;
14+
use Magento\Tests\NamingConvention\true\string;
1415

1516
/**
1617
* Test caching works for CMS page
@@ -49,37 +50,8 @@ public function testToCheckCmsPageRequestCacheTags(): void
4950
$cmsPageBlank = $this->objectManager->get(GetPageByIdentifier::class)->execute('page_design_blank', 0);
5051
$pageIdBlank = $cmsPageBlank->getId();
5152

52-
$queryCmsPage100 =
53-
<<<QUERY
54-
{
55-
cmsPage(id: $pageId100) {
56-
url_key
57-
title
58-
content
59-
content_heading
60-
page_layout
61-
meta_title
62-
meta_description
63-
meta_keywords
64-
}
65-
}
66-
QUERY;
67-
68-
$queryCmsPageBlank =
69-
<<<QUERY
70-
{
71-
cmsPage(id: $pageIdBlank) {
72-
url_key
73-
title
74-
content
75-
content_heading
76-
page_layout
77-
meta_title
78-
meta_description
79-
meta_keywords
80-
}
81-
}
82-
QUERY;
53+
$queryCmsPage100 = $this->getQuery($pageId100);
54+
$queryCmsPageBlank = $this->getQuery($pageIdBlank);
8355

8456
// check to see that the first entity gets a MISS when called the first time
8557
$request = $this->prepareRequest($queryCmsPage100);
@@ -129,7 +101,6 @@ public function testToCheckCmsPageRequestCacheTags(): void
129101
$expectedCacheTags = ['cms_p', 'cms_p_' .$pageIdBlank , 'FPC'];
130102
$this->assertEquals($expectedCacheTags, $requestedCacheTags);
131103

132-
133104
/** @var PageRepository $pageRepository */
134105
$pageRepository = $this->objectManager->get(PageRepository::class);
135106

@@ -161,4 +132,29 @@ public function testToCheckCmsPageRequestCacheTags(): void
161132
$expectedCacheTags = ['cms_p', 'cms_p_' .$pageId100 , 'FPC'];
162133
$this->assertEquals($expectedCacheTags, $requestedCacheTags);
163134
}
135+
136+
/**
137+
* Get cms query
138+
*
139+
* @param string $id
140+
* @return string
141+
*/
142+
private function getQuery(string $id) : string
143+
{
144+
$queryCmsPage = <<<QUERY
145+
{
146+
cmsPage(id: $id) {
147+
url_key
148+
title
149+
content
150+
content_heading
151+
page_layout
152+
meta_title
153+
meta_description
154+
meta_keywords
155+
}
156+
}
157+
QUERY;
158+
return $queryCmsPage;
159+
}
164160
}

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/UrlRewrite/AllEntitiesUrlResolverCacheTest.php

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -64,49 +64,18 @@ public function testAllEntitiesUrlResolverRequestHasCorrectTags()
6464
]
6565
);
6666
$categoryId = $actualUrls->getEntityId();
67-
$categoryQuery
68-
= <<<QUERY
69-
{
70-
urlResolver(url:"{$categoryUrlKey}")
71-
{
72-
id
73-
relative_url,
74-
canonical_url
75-
type
76-
}
77-
}
78-
QUERY;
67+
$categoryQuery = $this->getQuery($categoryUrlKey);
7968

80-
$productQuery = <<<QUERY
81-
{
82-
urlResolver(url:"{$productUrlKey}")
83-
{
84-
id
85-
relative_url
86-
canonical_url
87-
type
88-
}
89-
}
90-
QUERY;
69+
$productQuery = $this->getQuery($productUrlKey);
9170

9271
/** @var GetPageByIdentifierInterface $page */
9372
$page = $this->objectManager->get(GetPageByIdentifierInterface::class);
9473
/** @var PageInterface $cmsPage */
9574
$cmsPage = $page->execute('page100', 0);
9675
$cmsPageId = $cmsPage->getId();
9776
$requestPath = $cmsPage->getIdentifier();
98-
$pageQuery
99-
= <<<QUERY
100-
{
101-
urlResolver(url:"{$requestPath}")
102-
{
103-
id
104-
relative_url
105-
canonical_url
106-
type
107-
}
108-
}
109-
QUERY;
77+
$pageQuery = $this->getQuery($requestPath);
78+
11079
// query category for MISS
11180
$request = $this->prepareRequest($categoryQuery);
11281
$response = $this->graphqlController->dispatch($request);
@@ -163,17 +132,7 @@ public function testAllEntitiesUrlResolverRequestHasCorrectTags()
163132

164133
$product->setUrlKey('something-else-that-invalidates-the-cache');
165134
$productRepository->save($product);
166-
$productQuery = <<<QUERY
167-
{
168-
urlResolver(url:"something-else-that-invalidates-the-cache.html")
169-
{
170-
id
171-
relative_url
172-
canonical_url
173-
type
174-
}
175-
}
176-
QUERY;
135+
$productQuery = $this->getQuery('something-else-that-invalidates-the-cache.html');
177136

178137
// query category for MISS
179138
$request = $this->prepareRequest($categoryQuery);
@@ -193,4 +152,26 @@ public function testAllEntitiesUrlResolverRequestHasCorrectTags()
193152
$actualCacheTags = explode(',', $rawActualCacheTags);
194153
$this->assertEquals($expectedCacheTags, $actualCacheTags);
195154
}
155+
156+
/**
157+
* Get urlResolver query
158+
*
159+
* @param string $id
160+
* @return string
161+
*/
162+
private function getQuery(string $requestPath) : string
163+
{
164+
$resolverQuery = <<<QUERY
165+
{
166+
urlResolver(url:"{$requestPath}")
167+
{
168+
id
169+
relative_url
170+
canonical_url
171+
type
172+
}
173+
}
174+
QUERY;
175+
return $resolverQuery;
176+
}
196177
}

0 commit comments

Comments
 (0)