Skip to content

Commit 512447f

Browse files
committed
B2B-2677: [MediaGallery]Implement data caching for GraphQL results on resolver level
- Add testThatThereAreNoOrphanedCacheIdsInTagFileAfterInvalidation (should fail)
1 parent ff4070b commit 512447f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ResolverCache/MediaGalleryTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,54 @@ public function testMediaGalleryResolverCacheKeyAndTags()
341341
$this->assertNotEquals($simpleProductCacheTags, $simpleProductWithMediaCacheTags);
342342
}
343343

344+
#[
345+
DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'),
346+
]
347+
public function testThatThereAreNoOrphanedCacheIdsInTagFileAfterInvalidation()
348+
{
349+
$product = $this->productRepository->get('product1');
350+
$this->graphQlQuery($this->getProductWithMediaGalleryQuery($product));
351+
$this->assertMediaGalleryResolverCacheRecordExists($product);
352+
353+
$cacheKey = $this->getCacheKeyForMediaGalleryResolver($product);
354+
355+
// update media gallery-related field and assert cache is invalidated
356+
$this->actionMechanismProvider()['update media label'][0]($product);
357+
$this->assertMediaGalleryResolverCacheRecordDoesNotExist($product);
358+
359+
// assert cache id is not in GRAPHQL_QUERY_RESOLVER_RESULT tag file
360+
$cacheLowLevelFrontend = $this->graphQlResolverCache->getLowLevelFrontend();
361+
$cacheIdPrefix = $cacheLowLevelFrontend->getOption('cache_id_prefix');
362+
$cacheBackend = $cacheLowLevelFrontend->getBackend();
363+
364+
$this->assertNotContains(
365+
$cacheIdPrefix . $cacheKey,
366+
$cacheBackend->getIdsMatchingTags([
367+
$cacheIdPrefix . 'GRAPHQL_QUERY_RESOLVER_RESULT'
368+
]),
369+
'Cache id is still present in GRAPHQL_QUERY_RESOLVER_RESULT tag file after invalidation'
370+
);
371+
372+
$this->assertNotContains(
373+
$cacheIdPrefix . $cacheKey,
374+
$cacheBackend->getIdsMatchingTags([
375+
$cacheIdPrefix . 'GQL_MEDIA_GALLERY'
376+
]),
377+
'Cache id is still present in GQL_MEDIA_GALLERY tag file after invalidation'
378+
);
379+
380+
$this->assertNotContains(
381+
$cacheIdPrefix . $cacheKey,
382+
$cacheBackend->getIdsMatchingTags([
383+
$cacheIdPrefix . 'GQL_MEDIA_GALLERY_' . $product->getId(),
384+
]),
385+
sprintf(
386+
'Cache id is still present in GQL_MEDIA_GALLERY_%s tag file after invalidation',
387+
$product->getId()
388+
)
389+
);
390+
}
391+
344392
/**
345393
* @magentoApiDataFixture Magento/Catalog/_files/product_with_media_gallery.php
346394
* @return void

0 commit comments

Comments
 (0)