14
14
use Magento \Store \Api \StoreConfigManagerInterface ;
15
15
use Magento \Store \Api \StoreRepositoryInterface ;
16
16
use Magento \Store \Api \StoreResolverInterface ;
17
+ use Magento \Store \Model \Group ;
17
18
use Magento \Store \Model \ScopeInterface ;
18
19
use Magento \Store \Model \Store ;
19
20
use Magento \TestFramework \App \ApiMutableScopeConfig ;
@@ -152,7 +153,7 @@ public function testGetStoreConfig(): void
152
153
* Store scoped config change triggers purging only the cache of the changed store.
153
154
*
154
155
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
155
- * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores .php
156
+ * @magentoApiDataFixture Magento/Store/_files/store .php
156
157
* @throws NoSuchEntityException
157
158
*/
158
159
public function testCachePurgedWithStoreScopeConfigChange (): void
@@ -177,11 +178,11 @@ public function testCachePurgedWithStoreScopeConfigChange(): void
177
178
$ this ->assertEquals ($ defaultStoreCode , $ defaultStoreResponseResult ['code ' ]);
178
179
$ this ->assertEquals ($ defaultLocale , $ defaultStoreResponseResult ['locale ' ]);
179
180
180
- // Query test store config
181
- $ secondStoreCode = 'second_store_view ' ;
182
- $ responseTestStore = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , ['Store ' => $ secondStoreCode ]);
183
- $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseTestStore ['headers ' ]);
184
- $ secondStoreCacheId = $ responseTestStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
181
+ // Query second store config
182
+ $ secondStoreCode = 'test ' ;
183
+ $ responseSecondStore = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , ['Store ' => $ secondStoreCode ]);
184
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseSecondStore ['headers ' ]);
185
+ $ secondStoreCacheId = $ responseSecondStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
185
186
$ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
186
187
// Verify we obtain a cache MISS at the 1st time
187
188
$ secondStoreResponse = $ this ->assertCacheMissAndReturnResponse (
@@ -244,7 +245,7 @@ public function testCachePurgedWithStoreScopeConfigChange(): void
244
245
* Store change triggers purging only the cache of the changed store.
245
246
*
246
247
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
247
- * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores .php
248
+ * @magentoApiDataFixture Magento/Store/_files/store .php
248
249
* @throws NoSuchEntityException
249
250
*/
250
251
public function testCachePurgedWithStoreChange (): void
@@ -270,10 +271,10 @@ public function testCachePurgedWithStoreChange(): void
270
271
$ this ->assertEquals ($ defaultLocale , $ defaultStoreResponseResult ['locale ' ]);
271
272
272
273
// Query second store config
273
- $ secondStoreCode = 'second_store_view ' ;
274
- $ responseTestStore = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , ['Store ' => $ secondStoreCode ]);
275
- $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseTestStore ['headers ' ]);
276
- $ secondStoreCacheId = $ responseTestStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
274
+ $ secondStoreCode = 'test ' ;
275
+ $ responseSecondStore = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , ['Store ' => $ secondStoreCode ]);
276
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseSecondStore ['headers ' ]);
277
+ $ secondStoreCacheId = $ responseSecondStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
277
278
$ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
278
279
// Verify we obtain a cache MISS at the 1st time
279
280
$ secondStoreResponse = $ this ->assertCacheMissAndReturnResponse (
@@ -286,18 +287,18 @@ public function testCachePurgedWithStoreChange(): void
286
287
$ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponse ['body ' ]);
287
288
$ secondStoreResponseResult = $ secondStoreResponse ['body ' ]['storeConfig ' ];
288
289
$ this ->assertEquals ($ secondStoreCode , $ secondStoreResponseResult ['code ' ]);
289
- $ secondStoreName = 'Second Store View ' ;
290
+ $ secondStoreName = 'Test Store ' ;
290
291
$ this ->assertEquals ($ secondStoreName , $ secondStoreResponseResult ['store_name ' ]);
291
292
292
- // Change store name
293
+ // Change second store name
293
294
/** @var Store $store */
294
295
$ store = $ this ->objectManager ->create (Store::class);
295
296
$ store ->load ($ secondStoreCode , 'code ' );
296
297
$ secondStoreNewName = $ secondStoreName . ' 2 ' ;
297
298
$ store ->setName ($ secondStoreNewName );
298
299
$ store ->save ();
299
300
300
- // Query default store config after test store config change
301
+ // Query default store config after second store is changed
301
302
// Verify we obtain a cache HIT at the 2nd time, the cache is not purged
302
303
$ defaultStoreResponseHit = $ this ->assertCacheHitAndReturnResponse (
303
304
$ query ,
@@ -310,7 +311,7 @@ public function testCachePurgedWithStoreChange(): void
310
311
$ this ->assertEquals ($ defaultLocale , $ defaultStoreResponseHitResult ['locale ' ]);
311
312
$ this ->assertEquals ($ defaultStoreResponseResult ['store_name ' ], $ defaultStoreResponseHitResult ['store_name ' ]);
312
313
313
- // Query second store config after second store config is changed
314
+ // Query second store config after second store is changed
314
315
// Verify we obtain a cache MISS at the 2nd time, the cache is purged
315
316
$ secondStoreResponseMiss = $ this ->assertCacheMissAndReturnResponse (
316
317
$ query ,
@@ -337,6 +338,152 @@ public function testCachePurgedWithStoreChange(): void
337
338
$ this ->assertEquals ($ secondStoreNewName , $ secondStoreResponseHitResult ['store_name ' ]);
338
339
}
339
340
341
+ /**
342
+ * Store group change triggers purging only the cache of the stores associated with the changed store group.
343
+ *
344
+ * @magentoConfigFixture default/system/full_page_cache/caching_application 2
345
+ * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
346
+ * @throws NoSuchEntityException
347
+ */
348
+ public function testCachePurgedWithStoreGroupChange (): void
349
+ {
350
+ $ this ->changeToOneWebsiteTwoStoreGroupsThreeStores ();
351
+ $ query = $ this ->getQuery ();
352
+
353
+ // Query default store config
354
+ $ responseDefaultStore = $ this ->graphQlQueryWithResponseHeaders ($ query );
355
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseDefaultStore ['headers ' ]);
356
+ $ defaultStoreCacheId = $ responseDefaultStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
357
+ // Verify we obtain a cache MISS at the 1st time
358
+ $ this ->assertCacheMissAndReturnResponse (
359
+ $ query ,
360
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
361
+ );
362
+
363
+ // Query second store config
364
+ $ secondStoreCode = 'second_store_view ' ;
365
+ $ responseThirdStore = $ this ->graphQlQueryWithResponseHeaders (
366
+ $ query ,
367
+ [],
368
+ '' ,
369
+ ['Store ' => $ secondStoreCode ]
370
+ );
371
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseThirdStore ['headers ' ]);
372
+ $ secondStoreCacheId = $ responseThirdStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
373
+ $ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
374
+ // Verify we obtain a cache MISS at the 1st time
375
+ $ secondStoreResponse = $ this ->assertCacheMissAndReturnResponse (
376
+ $ query ,
377
+ [
378
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
379
+ 'Store ' => $ secondStoreCode
380
+ ]
381
+ );
382
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponse ['body ' ]);
383
+ $ secondStoreResponseResult = $ secondStoreResponse ['body ' ]['storeConfig ' ];
384
+ $ secondStoreGroupName = 'Second store group ' ;
385
+ $ this ->assertEquals ($ secondStoreGroupName , $ secondStoreResponseResult ['store_group_name ' ]);
386
+
387
+ // Query third store config
388
+ $ thirdStoreCode = 'third_store_view ' ;
389
+ $ responseThirdStore = $ this ->graphQlQueryWithResponseHeaders (
390
+ $ query ,
391
+ [],
392
+ '' ,
393
+ ['Store ' => $ thirdStoreCode ]
394
+ );
395
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseThirdStore ['headers ' ]);
396
+ $ thirdStoreCacheId = $ responseThirdStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
397
+ // Verify we obtain a cache MISS at the 1st time
398
+ $ thirdStoreResponse = $ this ->assertCacheMissAndReturnResponse (
399
+ $ query ,
400
+ [
401
+ CacheIdCalculator::CACHE_ID_HEADER => $ thirdStoreCacheId ,
402
+ 'Store ' => $ thirdStoreCode
403
+ ]
404
+ );
405
+ $ this ->assertArrayHasKey ('storeConfig ' , $ thirdStoreResponse ['body ' ]);
406
+ $ thirdStoreResponseResult = $ thirdStoreResponse ['body ' ]['storeConfig ' ];
407
+ $ this ->assertEquals ($ secondStoreGroupName , $ thirdStoreResponseResult ['store_group_name ' ]);
408
+
409
+ // Change store group name
410
+ /** @var Group $storeGroup */
411
+ $ storeGroup = $ this ->objectManager ->create (Group::class);
412
+ $ storeGroup ->load ('second_store ' , 'code ' );
413
+ $ secondStoreGroupNewName = $ secondStoreGroupName . ' 2 ' ;
414
+ $ storeGroup ->setName ($ secondStoreGroupNewName );
415
+ $ storeGroup ->save ();
416
+
417
+ // Query default store config after second store group is changed
418
+ // Verify we obtain a cache HIT at the 2nd time, the cache is not purged
419
+ $ this ->assertCacheHitAndReturnResponse (
420
+ $ query ,
421
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
422
+ );
423
+
424
+ // Query second store config after its associated second store group is changed
425
+ // Verify we obtain a cache MISS at the 2nd time, the cache is purged
426
+ $ secondStoreResponseMiss = $ this ->assertCacheMissAndReturnResponse (
427
+ $ query ,
428
+ [
429
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
430
+ 'Store ' => $ secondStoreCode
431
+ ]
432
+ );
433
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponseMiss ['body ' ]);
434
+ $ secondStoreResponseMissResult = $ secondStoreResponseMiss ['body ' ]['storeConfig ' ];
435
+ $ this ->assertEquals ($ secondStoreGroupNewName , $ secondStoreResponseMissResult ['store_group_name ' ]);
436
+ // Verify we obtain a cache HIT at the 3rd time
437
+ $ this ->assertCacheHitAndReturnResponse (
438
+ $ query ,
439
+ [
440
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
441
+ 'Store ' => $ secondStoreCode
442
+ ]
443
+ );
444
+
445
+ // Query third store config after its associated second store group is changed
446
+ // Verify we obtain a cache MISS at the 2nd time, the cache is purged
447
+ $ thirdStoreResponseMiss = $ this ->assertCacheMissAndReturnResponse (
448
+ $ query ,
449
+ [
450
+ CacheIdCalculator::CACHE_ID_HEADER => $ thirdStoreCacheId ,
451
+ 'Store ' => $ thirdStoreCode
452
+ ]
453
+ );
454
+ $ this ->assertArrayHasKey ('storeConfig ' , $ thirdStoreResponseMiss ['body ' ]);
455
+ $ thirdStoreResponseMissResult = $ thirdStoreResponseMiss ['body ' ]['storeConfig ' ];
456
+ $ this ->assertEquals ($ secondStoreGroupNewName , $ thirdStoreResponseMissResult ['store_group_name ' ]);
457
+ // Verify we obtain a cache HIT at the 3rd time
458
+ $ this ->assertCacheHitAndReturnResponse (
459
+ $ query ,
460
+ [
461
+ CacheIdCalculator::CACHE_ID_HEADER => $ thirdStoreCacheId ,
462
+ 'Store ' => $ thirdStoreCode
463
+ ]
464
+ );
465
+ }
466
+
467
+ private function changeToOneWebsiteTwoStoreGroupsThreeStores ()
468
+ {
469
+ // Change second store to the same website of the default store
470
+ /** @var Store $store2 */
471
+ $ store2 = $ this ->objectManager ->create (Store::class);
472
+ $ store2 ->load ('second_store_view ' , 'code ' );
473
+ $ store2GroupId = $ store2 ->getStoreGroupId ();
474
+ /** @var Group $store2Group */
475
+ $ store2Group = $ this ->objectManager ->create (Group::class);
476
+ $ store2Group ->load ($ store2GroupId );
477
+ $ store2Group ->setWebsiteId (1 )->save ();
478
+ $ store2 ->setWebsiteId (1 )->save ();
479
+
480
+ // Change third store to the same store group and website of second store
481
+ /** @var Store $store3 */
482
+ $ store3 = $ this ->objectManager ->create (Store::class);
483
+ $ store3 ->load ('third_store_view ' , 'code ' );
484
+ $ store3 ->setGroupId ($ store2GroupId )->setWebsiteId (1 )->save ();
485
+ }
486
+
340
487
/**
341
488
* Get query
342
489
*
0 commit comments