Skip to content

Commit 7a78b16

Browse files
committed
B2B-2258: Add caching capability to the storeConfig GraphQl query
1 parent e5e271f commit 7a78b16

File tree

1 file changed

+134
-1
lines changed

1 file changed

+134
-1
lines changed

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

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Store;
99

10+
use Magento\Framework\App\Config\ScopeConfigInterface;
1011
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\GraphQl\PageCache\GraphQLPageCacheAbstract;
1213
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
@@ -326,7 +327,7 @@ public function testCachePurgedWithWebsiteScopeConfigChange(): void
326327
$newLocale = 'de_DE';
327328
$this->setConfig($localeConfigPath, $newLocale, ScopeInterface::SCOPE_WEBSITES, 'second');
328329

329-
// Query default store config after second store group is changed
330+
// Query default store config after the config of the second website is changed
330331
// Verify we obtain a cache HIT at the 2nd time, the cache is not purged
331332
$this->assertCacheHitAndReturnResponse(
332333
$query,
@@ -378,6 +379,138 @@ public function testCachePurgedWithWebsiteScopeConfigChange(): void
378379
);
379380
}
380381

382+
/**
383+
* Default scope config change triggers purging the cache of all stores.
384+
*
385+
* Test stores set up:
386+
* STORE - WEBSITE - STORE GROUP
387+
* default - base - main_website_store
388+
* second_store_view - second - second_store
389+
* third_store_view - third - third_store
390+
*
391+
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
392+
* @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
393+
* @throws NoSuchEntityException
394+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
395+
*/
396+
public function testCachePurgedWithDefaultScopeConfigChange(): void
397+
{
398+
$defaultLocale = $this->defaultStoreConfig->getLocale();
399+
$query = $this->getQuery();
400+
401+
// Query default store config
402+
$responseDefaultStore = $this->graphQlQueryWithResponseHeaders($query);
403+
$defaultStoreCacheId = $responseDefaultStore['headers'][CacheIdCalculator::CACHE_ID_HEADER];
404+
// Verify we obtain a cache MISS at the 1st time
405+
$this->assertCacheMissAndReturnResponse(
406+
$query,
407+
[CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]
408+
);
409+
410+
// Query second store config
411+
$secondStoreCode = 'second_store_view';
412+
$responseThirdStore = $this->graphQlQueryWithResponseHeaders(
413+
$query,
414+
[],
415+
'',
416+
['Store' => $secondStoreCode]
417+
);
418+
$secondStoreCacheId = $responseThirdStore['headers'][CacheIdCalculator::CACHE_ID_HEADER];
419+
// Verify we obtain a cache MISS at the 1st time
420+
$secondStoreResponse = $this->assertCacheMissAndReturnResponse(
421+
$query,
422+
[
423+
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
424+
'Store' => $secondStoreCode
425+
]
426+
);
427+
$this->assertEquals($defaultLocale, $secondStoreResponse['body']['storeConfig']['locale']);
428+
429+
// Query third store config
430+
$thirdStoreCode = 'third_store_view';
431+
$responseThirdStore = $this->graphQlQueryWithResponseHeaders(
432+
$query,
433+
[],
434+
'',
435+
['Store' => $thirdStoreCode]
436+
);
437+
$thirdStoreCacheId = $responseThirdStore['headers'][CacheIdCalculator::CACHE_ID_HEADER];
438+
// Verify we obtain a cache MISS at the 1st time
439+
$thirdStoreResponse = $this->assertCacheMissAndReturnResponse(
440+
$query,
441+
[
442+
CacheIdCalculator::CACHE_ID_HEADER => $thirdStoreCacheId,
443+
'Store' => $thirdStoreCode
444+
]
445+
);
446+
$this->assertEquals($defaultLocale, $thirdStoreResponse['body']['storeConfig']['locale']);
447+
448+
// Change default locale
449+
$localeConfigPath = 'general/locale/code';
450+
$newLocale = 'de_DE';
451+
$this->setConfig($localeConfigPath, $newLocale, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
452+
453+
// Query default store config after the default config is changed
454+
// Verify we obtain a cache MISS at the 2nd time, the cache is purged
455+
$defaultStoreResponseMiss = $this->assertCacheMissAndReturnResponse(
456+
$query,
457+
[CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]
458+
);
459+
$this->assertEquals(
460+
$newLocale,
461+
$defaultStoreResponseMiss['body']['storeConfig']['locale']
462+
);
463+
// Verify we obtain a cache HIT at the 3rd time
464+
$this->assertCacheHitAndReturnResponse(
465+
$query,
466+
[CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]
467+
);
468+
469+
// Query second store config after the default config is changed
470+
// Verify we obtain a cache MISS at the 2nd time, the cache is purged
471+
$secondStoreResponseMiss = $this->assertCacheMissAndReturnResponse(
472+
$query,
473+
[
474+
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
475+
'Store' => $secondStoreCode
476+
]
477+
);
478+
$this->assertEquals(
479+
$newLocale,
480+
$secondStoreResponseMiss['body']['storeConfig']['locale']
481+
);
482+
// Verify we obtain a cache HIT at the 3rd time
483+
$this->assertCacheHitAndReturnResponse(
484+
$query,
485+
[
486+
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
487+
'Store' => $secondStoreCode
488+
]
489+
);
490+
491+
// Query third store config after the default config is changed
492+
// Verify we obtain a cache MISS at the 2nd time, the cache is purged
493+
$thirdStoreResponseMiss = $this->assertCacheMissAndReturnResponse(
494+
$query,
495+
[
496+
CacheIdCalculator::CACHE_ID_HEADER => $thirdStoreCacheId,
497+
'Store' => $thirdStoreCode
498+
]
499+
);
500+
$this->assertEquals(
501+
$newLocale,
502+
$thirdStoreResponseMiss['body']['storeConfig']['locale']
503+
);
504+
// Verify we obtain a cache HIT at the 3rd time
505+
$this->assertCacheHitAndReturnResponse(
506+
$query,
507+
[
508+
CacheIdCalculator::CACHE_ID_HEADER => $thirdStoreCacheId,
509+
'Store' => $thirdStoreCode
510+
]
511+
);
512+
}
513+
381514
/**
382515
* Store change triggers purging only the cache of the changed store.
383516
*

0 commit comments

Comments
 (0)