|
17 | 17 | use Magento\Store\Model\Group;
|
18 | 18 | use Magento\Store\Model\ScopeInterface;
|
19 | 19 | use Magento\Store\Model\Store;
|
| 20 | +use Magento\Store\Model\Website; |
20 | 21 | use Magento\TestFramework\App\ApiMutableScopeConfig;
|
21 | 22 | use Magento\TestFramework\Config\Model\ConfigStorage;
|
22 | 23 | use Magento\TestFramework\Helper\Bootstrap;
|
@@ -422,7 +423,7 @@ public function testCachePurgedWithStoreGroupChange(): void
|
422 | 423 | );
|
423 | 424 | $this->assertEquals($secondStoreGroupName, $thirdStoreResponse['body']['storeConfig']['store_group_name']);
|
424 | 425 |
|
425 |
| - // Change store group name |
| 426 | + // Change second store group name |
426 | 427 | /** @var Group $storeGroup */
|
427 | 428 | $storeGroup = $this->objectManager->create(Group::class);
|
428 | 429 | $storeGroup->load('second_store', 'code');
|
@@ -482,6 +483,120 @@ public function testCachePurgedWithStoreGroupChange(): void
|
482 | 483 | );
|
483 | 484 | }
|
484 | 485 |
|
| 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 | + |
485 | 600 | private function changeToOneWebsiteTwoStoreGroupsThreeStores()
|
486 | 601 | {
|
487 | 602 | // Change second store to the same website of the default store
|
|
0 commit comments