1717use Magento \GraphQlCache \Model \Cache \Query \Resolver \Result \Type as GraphQlCache ;
1818use Magento \GraphQlCache \Model \CacheId \CacheIdCalculator ;
1919use Magento \Integration \Api \CustomerTokenServiceInterface ;
20+ use Magento \Store \Model \StoreManagerInterface ;
2021use Magento \TestFramework \ObjectManager ;
2122use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
2223use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -56,6 +57,11 @@ class PageTest extends GraphQlAbstract
5657 */
5758 private $ cacheState ;
5859
60+ /**
61+ * @var StoreManagerInterface
62+ */
63+ private $ storeManager ;
64+
5965 /**
6066 * @var bool
6167 */
@@ -69,6 +75,7 @@ protected function setUp(): void
6975 $ this ->pageRepository = $ objectManager ->get (PageRepository::class);
7076 $ this ->searchCriteriaBuilder = $ objectManager ->get (SearchCriteriaBuilder::class);
7177 $ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
78+ $ this ->storeManager = $ objectManager ->get (StoreManagerInterface::class);
7279
7380 $ this ->cacheState = $ objectManager ->get (CacheState::class);
7481 $ this ->originalCacheStateEnabledStatus = $ this ->cacheState ->isEnabled (GraphQlCache::TYPE_IDENTIFIER );
@@ -396,6 +403,44 @@ public function testCmsPageResolverCacheDoesNotSaveNonExistentCmsPage()
396403 );
397404 }
398405
406+ /**
407+ * @magentoConfigFixture default/system/full_page_cache/caching_application 2
408+ * @magentoDataFixture Magento/Store/_files/second_store.php
409+ * @magentoDataFixture Magento/Cms/Fixtures/page_list.php
410+ * @return void
411+ */
412+ public function testCmsResolverCacheIsInvalidatedAfterSwitchingStoreView ()
413+ {
414+ /** @var \Magento\Cms\Model\Page $page */
415+ $ page = $ this ->getPageByTitle ('Page with 1column layout ' );
416+
417+ // query first page in default store and assert cache entry is created; use default store header
418+ $ query = $ this ->getQuery ($ page ->getIdentifier ());
419+
420+ $ response = $ this ->graphQlQueryWithResponseHeaders (
421+ $ query
422+ );
423+
424+ $ cacheIdentityString = $ this ->getResolverCacheKeyFromResponseAndPage (
425+ $ response ,
426+ $ page
427+ );
428+
429+ $ this ->assertIsNumeric (
430+ $ this ->graphqlCache ->test ($ cacheIdentityString )
431+ );
432+
433+ // change store id of page
434+ $ secondStoreViewId = $ this ->storeManager ->getStore ('fixture_second_store ' )->getId ();
435+ $ page ->setStoreId ($ secondStoreViewId );
436+ $ this ->pageRepository ->save ($ page );
437+
438+ // assert cache entry is invalidated
439+ $ this ->assertFalse (
440+ $ this ->graphqlCache ->test ($ cacheIdentityString )
441+ );
442+ }
443+
399444 /**
400445 * Test that resolver cache is saved with default TTL
401446 *
0 commit comments