Skip to content

Commit bcd548c

Browse files
committed
B2B-2677: [MediaGallery]Implement data caching for GraphQL results on resolver level
- Refactor
1 parent 209c7f5 commit bcd548c

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

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

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -350,35 +350,11 @@ public function testThatThereAreNoOrphanedCacheIdsInTagFileAfterInvalidation()
350350
$this->graphQlQuery($this->getProductWithMediaGalleryQuery($product));
351351
$this->assertMediaGalleryResolverCacheRecordExists($product);
352352

353-
$cacheKey = $this->getCacheKeyForMediaGalleryResolver($product);
354-
355353
// update media gallery-related field and assert cache is invalidated
356354
$this->actionMechanismProvider()['update media label'][0]($product);
357355
$this->assertMediaGalleryResolverCacheRecordDoesNotExist($product);
358356

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_' . strtoupper($product->getSku()),
376-
]),
377-
sprintf(
378-
'Cache id is still present in GQL_MEDIA_GALLERY_%s tag file after invalidation',
379-
strtoupper($product->getSku())
380-
)
381-
);
357+
$this->assertCacheIdIsNotOrphanedInTagsForProduct($product);
382358
}
383359

384360
/**
@@ -406,6 +382,40 @@ public function testCacheIsInvalidatedOnProductDeletion()
406382
$this->assertMediaGalleryResolverCacheRecordDoesNotExist($product);
407383
}
408384

385+
/**
386+
* Assert that cache id is not present in any of the cache tag files for the $product.
387+
*
388+
* @param ProductInterface $product
389+
* @return void
390+
* @throws \Zend_Cache_Exception
391+
*/
392+
private function assertCacheIdIsNotOrphanedInTagsForProduct(ProductInterface $product)
393+
{
394+
$cacheKey = $this->getCacheKeyForMediaGalleryResolver($product);
395+
$cacheLowLevelFrontend = $this->graphQlResolverCache->getLowLevelFrontend();
396+
$cacheIdPrefix = $cacheLowLevelFrontend->getOption('cache_id_prefix');
397+
$cacheBackend = $cacheLowLevelFrontend->getBackend();
398+
399+
$this->assertNotContains(
400+
$cacheIdPrefix . $cacheKey,
401+
$cacheBackend->getIdsMatchingTags([
402+
$cacheIdPrefix . 'GRAPHQL_QUERY_RESOLVER_RESULT'
403+
]),
404+
'Cache id is still present in GRAPHQL_QUERY_RESOLVER_RESULT tag file after invalidation'
405+
);
406+
407+
$this->assertNotContains(
408+
$cacheIdPrefix . $cacheKey,
409+
$cacheBackend->getIdsMatchingTags([
410+
$cacheIdPrefix . 'GQL_MEDIA_GALLERY_' . strtoupper($product->getSku()),
411+
]),
412+
sprintf(
413+
'Cache id is still present in GQL_MEDIA_GALLERY_%s tag file after invalidation',
414+
strtoupper($product->getSku())
415+
)
416+
);
417+
}
418+
409419
/**
410420
* Assert that media gallery cache record exists for the $product.
411421
*

0 commit comments

Comments
 (0)