Skip to content

Commit 246288c

Browse files
committed
B2B-2258: Add caching capability to the storeConfig GraphQl query
1 parent 8a5c882 commit 246288c

File tree

1 file changed

+116
-1
lines changed

1 file changed

+116
-1
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigCacheTest.php

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Store\Model\Group;
1818
use Magento\Store\Model\ScopeInterface;
1919
use Magento\Store\Model\Store;
20+
use Magento\Store\Model\Website;
2021
use Magento\TestFramework\App\ApiMutableScopeConfig;
2122
use Magento\TestFramework\Config\Model\ConfigStorage;
2223
use Magento\TestFramework\Helper\Bootstrap;
@@ -422,7 +423,7 @@ public function testCachePurgedWithStoreGroupChange(): void
422423
);
423424
$this->assertEquals($secondStoreGroupName, $thirdStoreResponse['body']['storeConfig']['store_group_name']);
424425

425-
// Change store group name
426+
// Change second store group name
426427
/** @var Group $storeGroup */
427428
$storeGroup = $this->objectManager->create(Group::class);
428429
$storeGroup->load('second_store', 'code');
@@ -482,6 +483,120 @@ public function testCachePurgedWithStoreGroupChange(): void
482483
);
483484
}
484485

486+
/**
487+
* Store website change triggers purging only the cache of the stores associated with the changed store website.
488+
*
489+
* Test stores set up:
490+
* STORE - WEBSITE - STORE GROUP
491+
* default - base - main_website_store
492+
* second_store_view - second - second_store
493+
* third_store_view - third - third_store
494+
*
495+
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
496+
* @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
497+
* @throws NoSuchEntityException
498+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
499+
*/
500+
public function testCachePurgedWithWebsiteChange(): void
501+
{
502+
$query = $this->getQuery();
503+
504+
// Query default store config
505+
$responseDefaultStore = $this->graphQlQueryWithResponseHeaders($query);
506+
$defaultStoreCacheId = $responseDefaultStore['headers'][CacheIdCalculator::CACHE_ID_HEADER];
507+
// Verify we obtain a cache MISS at the 1st time
508+
$this->assertCacheMissAndReturnResponse(
509+
$query,
510+
[CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]
511+
);
512+
513+
// Query second store config
514+
$secondStoreCode = 'second_store_view';
515+
$responseThirdStore = $this->graphQlQueryWithResponseHeaders(
516+
$query,
517+
[],
518+
'',
519+
['Store' => $secondStoreCode]
520+
);
521+
$secondStoreCacheId = $responseThirdStore['headers'][CacheIdCalculator::CACHE_ID_HEADER];
522+
// Verify we obtain a cache MISS at the 1st time
523+
$secondStoreResponse = $this->assertCacheMissAndReturnResponse(
524+
$query,
525+
[
526+
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
527+
'Store' => $secondStoreCode
528+
]
529+
);
530+
$secondStoreWebsiteName = 'Second Test Website';
531+
$this->assertEquals($secondStoreWebsiteName, $secondStoreResponse['body']['storeConfig']['website_name']);
532+
533+
// Query third store config
534+
$thirdStoreCode = 'third_store_view';
535+
$responseThirdStore = $this->graphQlQueryWithResponseHeaders(
536+
$query,
537+
[],
538+
'',
539+
['Store' => $thirdStoreCode]
540+
);
541+
$thirdStoreCacheId = $responseThirdStore['headers'][CacheIdCalculator::CACHE_ID_HEADER];
542+
// Verify we obtain a cache MISS at the 1st time
543+
$thirdStoreResponse = $this->assertCacheMissAndReturnResponse(
544+
$query,
545+
[
546+
CacheIdCalculator::CACHE_ID_HEADER => $thirdStoreCacheId,
547+
'Store' => $thirdStoreCode
548+
]
549+
);
550+
$this->assertEquals('Third test Website', $thirdStoreResponse['body']['storeConfig']['website_name']);
551+
552+
// Change second store website name
553+
/** @var Website $website */
554+
$website = $this->objectManager->create(Website::class);
555+
$website->load('second', 'code');
556+
$secondStoreWebsiteNewName = $secondStoreWebsiteName . ' 2';
557+
$website->setName($secondStoreWebsiteNewName);
558+
$website->save();
559+
560+
// Query default store config after second store website is changed
561+
// Verify we obtain a cache HIT at the 2nd time, the cache is not purged
562+
$this->assertCacheHitAndReturnResponse(
563+
$query,
564+
[CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]
565+
);
566+
567+
// Query second store config after its associated second store group is changed
568+
// Verify we obtain a cache MISS at the 2nd time, the cache is purged
569+
$secondStoreResponseMiss = $this->assertCacheMissAndReturnResponse(
570+
$query,
571+
[
572+
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
573+
'Store' => $secondStoreCode
574+
]
575+
);
576+
$this->assertEquals(
577+
$secondStoreWebsiteNewName,
578+
$secondStoreResponseMiss['body']['storeConfig']['website_name']
579+
);
580+
// Verify we obtain a cache HIT at the 3rd time
581+
$this->assertCacheHitAndReturnResponse(
582+
$query,
583+
[
584+
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
585+
'Store' => $secondStoreCode
586+
]
587+
);
588+
589+
// Query third store config after second store website is changed
590+
// Verify we obtain a cache HIT at the 2nd time
591+
$this->assertCacheHitAndReturnResponse(
592+
$query,
593+
[
594+
CacheIdCalculator::CACHE_ID_HEADER => $thirdStoreCacheId,
595+
'Store' => $thirdStoreCode
596+
]
597+
);
598+
}
599+
485600
private function changeToOneWebsiteTwoStoreGroupsThreeStores()
486601
{
487602
// Change second store to the same website of the default store

0 commit comments

Comments
 (0)