Skip to content

Commit ecf78e2

Browse files
committed
B2B-2659: Implement GraphQL Resolver Cache for cmsBlocks query
1 parent 19583eb commit ecf78e2

File tree

1 file changed

+19
-23
lines changed
  • dev/tests/api-functional/testsuite/Magento/CmsGraphQl/Model/Resolver

1 file changed

+19
-23
lines changed

dev/tests/api-functional/testsuite/Magento/CmsGraphQl/Model/Resolver/BlockTest.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Cms\Api\BlockRepositoryInterface;
1111
use Magento\Cms\Api\Data\BlockInterface;
1212
use Magento\Cms\Model\Block;
13-
use Magento\GraphQlCache\Model\Cache\Query\Resolver\Result\Type as GraphQlCache;
13+
use Magento\GraphQlCache\Model\Cache\Query\Resolver\Result\Type as GraphQlResolverCache;
1414
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
1515
use Magento\Store\Model\StoreManagerInterface;
1616
use Magento\TestFramework\ObjectManager;
@@ -26,9 +26,9 @@ class BlockTest extends GraphQlAbstract
2626
private $blockRepository;
2727

2828
/**
29-
* @var GraphQlCache
29+
* @var GraphQlResolverCache
3030
*/
31-
private $graphqlCache;
31+
private $graphQlResolverCache;
3232

3333
/**
3434
* @var FilterEmulate
@@ -44,14 +44,14 @@ protected function setUp(): void
4444
{
4545
$objectManager = ObjectManager::getInstance();
4646
$this->blockRepository = $objectManager->get(BlockRepositoryInterface::class);
47-
$this->graphqlCache = $objectManager->get(GraphQlCache::class);
47+
$this->graphQlResolverCache = $objectManager->get(GraphQlResolverCache::class);
4848
$this->widgetFilter = $objectManager->get(FilterEmulate::class);
4949
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
5050
}
5151

5252
protected function tearDown(): void
5353
{
54-
$this->graphqlCache->clean();
54+
$this->graphQlResolverCache->clean();
5555

5656
parent::tearDown();
5757
}
@@ -71,7 +71,7 @@ public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest()
7171

7272
$cacheIdentityString = $this->getResolverCacheKeyFromResponseAndBlocks($response, [$block]);
7373

74-
$cacheEntry = $this->graphqlCache->load($cacheIdentityString);
74+
$cacheEntry = $this->graphQlResolverCache->load($cacheIdentityString);
7575
$cacheEntryDecoded = json_decode($cacheEntry, true);
7676

7777
$this->assertEqualsCanonicalizing(
@@ -89,7 +89,7 @@ public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest()
8989
$this->blockRepository->save($block);
9090

9191
$this->assertFalse(
92-
$this->graphqlCache->test($cacheIdentityString),
92+
$this->graphQlResolverCache->test($cacheIdentityString),
9393
'Cache entry should be invalidated after block content change'
9494
);
9595
}
@@ -115,7 +115,7 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
115115
$block2,
116116
]);
117117

118-
$cacheEntry = $this->graphqlCache->load($cacheIdentityString);
118+
$cacheEntry = $this->graphQlResolverCache->load($cacheIdentityString);
119119
$cacheEntryDecoded = json_decode($cacheEntry, true);
120120

121121
$this->assertEqualsCanonicalizing(
@@ -133,7 +133,7 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
133133
$this->blockRepository->save($block2);
134134

135135
$this->assertFalse(
136-
$this->graphqlCache->test($cacheIdentityString),
136+
$this->graphQlResolverCache->test($cacheIdentityString),
137137
'Cache entry should be invalidated after block content change'
138138
);
139139
}
@@ -153,7 +153,7 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
153153

154154
$cacheIdentityString = $this->getResolverCacheKeyFromResponseAndBlocks($response, [$block]);
155155

156-
$cacheEntry = $this->graphqlCache->load($cacheIdentityString);
156+
$cacheEntry = $this->graphQlResolverCache->load($cacheIdentityString);
157157
$cacheEntryDecoded = json_decode($cacheEntry, true);
158158

159159
$this->assertEqualsCanonicalizing(
@@ -170,7 +170,7 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
170170
$this->blockRepository->delete($block);
171171

172172
$this->assertFalse(
173-
$this->graphqlCache->test($cacheIdentityString),
173+
$this->graphQlResolverCache->test($cacheIdentityString),
174174
'Cache entry should be invalidated after block deletion'
175175
);
176176
}
@@ -190,7 +190,7 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
190190

191191
$cacheIdentityString = $this->getResolverCacheKeyFromResponseAndBlocks($response, [$block]);
192192

193-
$cacheEntry = $this->graphqlCache->load($cacheIdentityString);
193+
$cacheEntry = $this->graphQlResolverCache->load($cacheIdentityString);
194194
$cacheEntryDecoded = json_decode($cacheEntry, true);
195195

196196
$this->assertEqualsCanonicalizing(
@@ -208,7 +208,7 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
208208
$this->blockRepository->save($block);
209209

210210
$this->assertFalse(
211-
$this->graphqlCache->test($cacheIdentityString),
211+
$this->graphQlResolverCache->test($cacheIdentityString),
212212
'Cache entry should be invalidated after block disablement'
213213
);
214214
}
@@ -230,7 +230,7 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
230230

231231
$cacheIdentityString = $this->getResolverCacheKeyFromResponseAndBlocks($response, [$block]);
232232

233-
$cacheEntry = $this->graphqlCache->load($cacheIdentityString);
233+
$cacheEntry = $this->graphQlResolverCache->load($cacheIdentityString);
234234
$cacheEntryDecoded = json_decode($cacheEntry, true);
235235

236236
$this->assertEqualsCanonicalizing(
@@ -249,7 +249,7 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
249249
$this->blockRepository->save($block);
250250

251251
$this->assertFalse(
252-
$this->graphqlCache->test($cacheIdentityString),
252+
$this->graphQlResolverCache->test($cacheIdentityString),
253253
'Cache entry should be invalidated after changing block\'s store view'
254254
);
255255
}
@@ -279,7 +279,7 @@ public function testCmsBlockResolverCacheDoesNotSaveNonExistentCmsBlock()
279279
$cacheIdentityString = $this->getResolverCacheKeyFromResponseAndBlocks($response, [$nonExistentBlock]);
280280

281281
$this->assertFalse(
282-
$this->graphqlCache->load($cacheIdentityString)
282+
$this->graphQlResolverCache->load($cacheIdentityString)
283283
);
284284
}
285285

@@ -341,14 +341,14 @@ private function generateExpectedDataFromBlocks(array $blocks): array
341341
*/
342342
private function assertTagsByCacheIdentityAndBlocks(string $cacheIdentityString, array $blocks): void
343343
{
344-
$lowLevelFrontendCache = $this->graphqlCache->getLowLevelFrontend();
344+
$lowLevelFrontendCache = $this->graphQlResolverCache->getLowLevelFrontend();
345345
$cacheIdPrefix = $lowLevelFrontendCache->getOption('cache_id_prefix');
346346
$metadatas = $lowLevelFrontendCache->getMetadatas($cacheIdentityString);
347347
$tags = $metadatas['tags'];
348348

349349
$expectedTags = [
350350
$cacheIdPrefix . strtoupper(Block::CACHE_TAG),
351-
$cacheIdPrefix . strtoupper(GraphQlCache::CACHE_TAG),
351+
$cacheIdPrefix . strtoupper(GraphQlResolverCache::CACHE_TAG),
352352
$cacheIdPrefix . 'MAGE',
353353
];
354354

@@ -376,16 +376,12 @@ private function getResolverCacheKeyFromResponseAndBlocks(array $response, array
376376
return $block->getIdentifier();
377377
}, $blocks);
378378

379-
print_r($this->getBlockIdentifiersListAsString($blockIdentifiers));
380-
381379
$cacheIdQueryPayloadMetadata = sprintf('CmsBlocks%s', json_encode([
382380
'identifiers' => $blockIdentifiers,
383381
]));
384382

385-
echo $cacheIdQueryPayloadMetadata, PHP_EOL;
386-
387383
$cacheIdParts = [
388-
GraphQlCache::CACHE_TAG,
384+
GraphQlResolverCache::CACHE_TAG,
389385
$cacheIdValue,
390386
sha1($cacheIdQueryPayloadMetadata)
391387
];

0 commit comments

Comments
 (0)