17
17
use Magento \GraphQlCache \Model \Cache \Query \Resolver \Result \Type as GraphQlCache ;
18
18
use Magento \GraphQlCache \Model \CacheId \CacheIdCalculator ;
19
19
use Magento \Integration \Api \CustomerTokenServiceInterface ;
20
+ use Magento \Store \Model \StoreManagerInterface ;
20
21
use Magento \TestFramework \ObjectManager ;
21
22
use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
22
23
use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -56,6 +57,11 @@ class PageTest extends GraphQlAbstract
56
57
*/
57
58
private $ cacheState ;
58
59
60
+ /**
61
+ * @var StoreManagerInterface
62
+ */
63
+ private $ storeManager ;
64
+
59
65
/**
60
66
* @var bool
61
67
*/
@@ -69,6 +75,7 @@ protected function setUp(): void
69
75
$ this ->pageRepository = $ objectManager ->get (PageRepository::class);
70
76
$ this ->searchCriteriaBuilder = $ objectManager ->get (SearchCriteriaBuilder::class);
71
77
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
78
+ $ this ->storeManager = $ objectManager ->get (StoreManagerInterface::class);
72
79
73
80
$ this ->cacheState = $ objectManager ->get (CacheState::class);
74
81
$ this ->originalCacheStateEnabledStatus = $ this ->cacheState ->isEnabled (GraphQlCache::TYPE_IDENTIFIER );
@@ -396,6 +403,44 @@ public function testCmsPageResolverCacheDoesNotSaveNonExistentCmsPage()
396
403
);
397
404
}
398
405
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
+
399
444
/**
400
445
* Test that resolver cache is saved with default TTL
401
446
*
0 commit comments