@@ -1532,6 +1532,184 @@ public function testCachePurgedWithNewStoreWithNewStoreGroupSecondWebsite(): voi
15321532 $ registry ->register ('isSecureArea ' , false );
15331533 }
15341534
1535+ /**
1536+ * Creating new inactive store with second website and new store group will not purge the cache of availableStores
1537+ * for all stores of second website, will purge the cache of availableStores for all stores of second website when
1538+ * the new store is activated
1539+ *
1540+ * Test stores set up:
1541+ * STORE - WEBSITE - STORE GROUP
1542+ * default - base - main_website_store
1543+ * second_store_view - second - second_store
1544+ * third_store_view - second - third_store
1545+ *
1546+ * @magentoConfigFixture default/system/full_page_cache/caching_application 2
1547+ * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
1548+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1549+ */
1550+ public function testCacheNotPurgedWithNewInactiveStoreWithNewStoreGroupSecondWebsitePurgedWhenActivated (): void
1551+ {
1552+ $ this ->changeToTwoWebsitesThreeStoreGroupsThreeStores ();
1553+ $ query = $ this ->getQuery ();
1554+
1555+ // Query available stores of default store's website
1556+ $ responseDefaultStore = $ this ->graphQlQueryWithResponseHeaders ($ query );
1557+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseDefaultStore ['headers ' ]);
1558+ $ defaultStoreCacheId = $ responseDefaultStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
1559+ // Verify we obtain a cache MISS at the 1st time
1560+ $ this ->assertCacheMissAndReturnResponse (
1561+ $ query ,
1562+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
1563+ );
1564+
1565+ // Query available stores of second store's website and any store groups of the website
1566+ $ secondStoreCode = 'second_store_view ' ;
1567+ $ responseSecondStore = $ this ->graphQlQueryWithResponseHeaders (
1568+ $ query ,
1569+ [],
1570+ '' ,
1571+ ['Store ' => $ secondStoreCode ]
1572+ );
1573+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseSecondStore ['headers ' ]);
1574+ $ secondStoreCacheId = $ responseSecondStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
1575+ $ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
1576+ // Verify we obtain a cache MISS at the 1st time
1577+ $ this ->assertCacheMissAndReturnResponse (
1578+ $ query ,
1579+ [
1580+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
1581+ 'Store ' => $ secondStoreCode
1582+ ]
1583+ );
1584+
1585+ // Query available stores of second store's website and store group
1586+ $ currentStoreGroupQuery = $ this ->getQuery ('true ' );
1587+ $ responseSecondStoreCurrentStoreGroup = $ this ->graphQlQueryWithResponseHeaders (
1588+ $ currentStoreGroupQuery ,
1589+ [],
1590+ '' ,
1591+ ['Store ' => $ secondStoreCode ]
1592+ );
1593+ $ this ->assertArrayHasKey (
1594+ CacheIdCalculator::CACHE_ID_HEADER ,
1595+ $ responseSecondStoreCurrentStoreGroup ['headers ' ]
1596+ );
1597+ $ secondStoreCurrentStoreGroupCacheId =
1598+ $ responseSecondStoreCurrentStoreGroup ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
1599+ $ this ->assertNotEquals ($ secondStoreCurrentStoreGroupCacheId , $ defaultStoreCacheId );
1600+ // Verify we obtain a cache MISS at the 1st time
1601+ $ this ->assertCacheMissAndReturnResponse (
1602+ $ currentStoreGroupQuery ,
1603+ [
1604+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
1605+ 'Store ' => $ secondStoreCode
1606+ ]
1607+ );
1608+
1609+ // Get second website
1610+ $ website = $ this ->objectManager ->create (Website::class);
1611+ $ website ->load ('second ' , 'code ' );
1612+
1613+ // Create new store group
1614+ $ storeGroup = $ this ->objectManager ->create (Group::class);
1615+ $ storeGroup ->setCode ('new_store ' )
1616+ ->setName ('New store group ' )
1617+ ->setWebsite ($ website );
1618+ $ storeGroup ->save ();
1619+
1620+ // Create new inactive store with new store group and second website
1621+ $ store = $ this ->objectManager ->create (Store::class);
1622+ $ store ->setData ([
1623+ 'code ' => 'new_store_view ' ,
1624+ 'website_id ' => $ website ->getId (),
1625+ 'group_id ' => $ storeGroup ->getId (),
1626+ 'name ' => 'new Store View ' ,
1627+ 'sort_order ' => 10 ,
1628+ 'is_active ' => 0 ,
1629+ ]);
1630+ $ store ->save ();
1631+
1632+ // Query available stores of default store's website
1633+ // after new inactive store with second website and new store group is created
1634+ // Verify we obtain a cache HIT at the 2nd time
1635+ $ this ->assertCacheHitAndReturnResponse (
1636+ $ query ,
1637+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
1638+ );
1639+
1640+ // Query available stores of second store's website (second website) and any store groups of the website
1641+ // after new inactive store with second website and new store group is created
1642+ // Verify we obtain a cache Hit at the 2nd time
1643+ $ this ->assertCacheHitAndReturnResponse (
1644+ $ query ,
1645+ [
1646+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
1647+ 'Store ' => $ secondStoreCode
1648+ ]
1649+ );
1650+
1651+ // Query available stores of second store's website (second website) and store group
1652+ // after new inactive store with second website and new store group is created
1653+ // Verify we obtain a cache HIT at the 2nd time
1654+ $ this ->assertCacheHitAndReturnResponse (
1655+ $ currentStoreGroupQuery ,
1656+ [
1657+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
1658+ 'Store ' => $ secondStoreCode
1659+ ]
1660+ );
1661+
1662+ // Activate the store
1663+ $ store ->setIsActive (1 );
1664+ $ store ->save ();
1665+
1666+ // Query available stores of default store's website after the store is activated
1667+ // Verify we obtain a cache HIT at the 3rd time
1668+ $ this ->assertCacheHitAndReturnResponse (
1669+ $ query ,
1670+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
1671+ );
1672+
1673+ // Query available stores of second store's website (second website) and any store groups of the website
1674+ // after the store is activated
1675+ // Verify we obtain a cache MISS at the 3rd time
1676+ $ this ->assertCacheMissAndReturnResponse (
1677+ $ query ,
1678+ [
1679+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
1680+ 'Store ' => $ secondStoreCode
1681+ ]
1682+ );
1683+ // Verify we obtain a cache HIT at the 4th time
1684+ $ this ->assertCacheHitAndReturnResponse (
1685+ $ query ,
1686+ [
1687+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
1688+ 'Store ' => $ secondStoreCode
1689+ ]
1690+ );
1691+
1692+ // Query available stores of second store's website (second website) and store group
1693+ // after the store is activated
1694+ // Verify we obtain a cache HIT at the 3rd time
1695+ $ this ->assertCacheHitAndReturnResponse (
1696+ $ currentStoreGroupQuery ,
1697+ [
1698+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
1699+ 'Store ' => $ secondStoreCode
1700+ ]
1701+ );
1702+
1703+ // remove new store, new store group
1704+ $ registry = $ this ->objectManager ->get (\Magento \Framework \Registry::class);
1705+ $ registry ->unregister ('isSecureArea ' );
1706+ $ registry ->register ('isSecureArea ' , true );
1707+ $ store ->delete ();
1708+ $ storeGroup ->delete ();
1709+ $ registry ->unregister ('isSecureArea ' );
1710+ $ registry ->register ('isSecureArea ' , false );
1711+ }
1712+
15351713 /**
15361714 * Creating new store with second website and second store group will only purge the cache of availableStores for
15371715 * all stores of second website or second website with second store group
@@ -1680,6 +1858,189 @@ public function testCachePurgedWithNewStoreWithSecondStoreGroupSecondWebsite():
16801858 $ registry ->register ('isSecureArea ' , false );
16811859 }
16821860
1861+ /**
1862+ * Creating new inactive store with second website and second store group will not purge the cache of
1863+ * availableStores for all stores of second website or second website with second store group, will purge the
1864+ * cache of availableStores for all stores of second website or second website with second store group
1865+ * after the store is activated
1866+ *
1867+ * Test stores set up:
1868+ * STORE - WEBSITE - STORE GROUP
1869+ * default - base - main_website_store
1870+ * second_store_view - second - second_store
1871+ * third_store_view - second - third_store
1872+ *
1873+ * @magentoConfigFixture default/system/full_page_cache/caching_application 2
1874+ * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
1875+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1876+ */
1877+ public function testCacheNotPurgedWithNewInactiveStoreWithSecondStoreGroupSecondWebsitePurgedAfterActivated (): void
1878+ {
1879+ $ this ->changeToTwoWebsitesThreeStoreGroupsThreeStores ();
1880+ $ query = $ this ->getQuery ();
1881+
1882+ // Query available stores of default store's website
1883+ $ responseDefaultStore = $ this ->graphQlQueryWithResponseHeaders ($ query );
1884+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseDefaultStore ['headers ' ]);
1885+ $ defaultStoreCacheId = $ responseDefaultStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
1886+ // Verify we obtain a cache MISS at the 1st time
1887+ $ this ->assertCacheMissAndReturnResponse (
1888+ $ query ,
1889+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
1890+ );
1891+
1892+ // Query available stores of second store's website and any store groups of the website
1893+ $ secondStoreCode = 'second_store_view ' ;
1894+ $ responseSecondStore = $ this ->graphQlQueryWithResponseHeaders (
1895+ $ query ,
1896+ [],
1897+ '' ,
1898+ ['Store ' => $ secondStoreCode ]
1899+ );
1900+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseSecondStore ['headers ' ]);
1901+ $ secondStoreCacheId = $ responseSecondStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
1902+ $ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
1903+ // Verify we obtain a cache MISS at the 1st time
1904+ $ this ->assertCacheMissAndReturnResponse (
1905+ $ query ,
1906+ [
1907+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
1908+ 'Store ' => $ secondStoreCode
1909+ ]
1910+ );
1911+
1912+ // Query available stores of second store's website and store group
1913+ $ currentStoreGroupQuery = $ this ->getQuery ('true ' );
1914+ $ responseSecondStoreCurrentStoreGroup = $ this ->graphQlQueryWithResponseHeaders (
1915+ $ currentStoreGroupQuery ,
1916+ [],
1917+ '' ,
1918+ ['Store ' => $ secondStoreCode ]
1919+ );
1920+ $ this ->assertArrayHasKey (
1921+ CacheIdCalculator::CACHE_ID_HEADER ,
1922+ $ responseSecondStoreCurrentStoreGroup ['headers ' ]
1923+ );
1924+ $ secondStoreCurrentStoreGroupCacheId =
1925+ $ responseSecondStoreCurrentStoreGroup ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
1926+ $ this ->assertNotEquals ($ secondStoreCurrentStoreGroupCacheId , $ defaultStoreCacheId );
1927+ // Verify we obtain a cache MISS at the 1st time
1928+ $ this ->assertCacheMissAndReturnResponse (
1929+ $ currentStoreGroupQuery ,
1930+ [
1931+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
1932+ 'Store ' => $ secondStoreCode
1933+ ]
1934+ );
1935+
1936+ // Get second website
1937+ $ website = $ this ->objectManager ->create (Website::class);
1938+ $ website ->load ('second ' , 'code ' );
1939+
1940+ // Get second store group
1941+ $ storeGroup = $ this ->objectManager ->create (Group::class);
1942+ $ storeGroup ->load ('second_store ' , 'code ' );
1943+
1944+ // Create new inactive store with second store group and second website
1945+ $ store = $ this ->objectManager ->create (Store::class);
1946+ $ store ->setData ([
1947+ 'code ' => 'new_store_view ' ,
1948+ 'website_id ' => $ website ->getId (),
1949+ 'group_id ' => $ storeGroup ->getId (),
1950+ 'name ' => 'new Store View ' ,
1951+ 'sort_order ' => 10 ,
1952+ 'is_active ' => 0 ,
1953+ ]);
1954+ $ store ->save ();
1955+
1956+ // Query available stores of default store's website
1957+ // after new inactive store with second website and second store group is created
1958+ // Verify we obtain a cache HIT at the 2nd time
1959+ $ this ->assertCacheHitAndReturnResponse (
1960+ $ query ,
1961+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
1962+ );
1963+
1964+ // Query available stores of second store's website (second website) and any store groups of the website
1965+ // after new inactive store with second website and second store group is created
1966+ // Verify we obtain a cache HIT at the 2nd time
1967+ $ this ->assertCacheHitAndReturnResponse (
1968+ $ query ,
1969+ [
1970+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
1971+ 'Store ' => $ secondStoreCode
1972+ ]
1973+ );
1974+
1975+ // Query available stores of second store's website (second website) and store group
1976+ // after new inactive store with second website and second store group is created
1977+ // Verify we obtain a cache HIT at the 2nd time
1978+ $ this ->assertCacheHitAndReturnResponse (
1979+ $ currentStoreGroupQuery ,
1980+ [
1981+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
1982+ 'Store ' => $ secondStoreCode
1983+ ]
1984+ );
1985+
1986+ // Activate the store
1987+ $ store ->setIsActive (1 );
1988+ $ store ->save ();
1989+
1990+ // Query available stores of default store's website after the store is activated
1991+ // Verify we obtain a cache HIT at the 3rd time
1992+ $ this ->assertCacheHitAndReturnResponse (
1993+ $ query ,
1994+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
1995+ );
1996+
1997+ // Query available stores of second store's website (second website) and any store groups of the website
1998+ // after the store is activated
1999+ // Verify we obtain a cache MISS at the 3rd time
2000+ $ this ->assertCacheMissAndReturnResponse (
2001+ $ query ,
2002+ [
2003+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
2004+ 'Store ' => $ secondStoreCode
2005+ ]
2006+ );
2007+ // Verify we obtain a cache HIT at the 4th time
2008+ $ this ->assertCacheHitAndReturnResponse (
2009+ $ query ,
2010+ [
2011+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
2012+ 'Store ' => $ secondStoreCode
2013+ ]
2014+ );
2015+
2016+ // Query available stores of second store's website (second website) and store group
2017+ // after the store is activated
2018+ // Verify we obtain a cache MISS at the 3rd time
2019+ $ this ->assertCacheMissAndReturnResponse (
2020+ $ currentStoreGroupQuery ,
2021+ [
2022+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
2023+ 'Store ' => $ secondStoreCode
2024+ ]
2025+ );
2026+ // Verify we obtain a cache HIT at the 4th time
2027+ $ this ->assertCacheHitAndReturnResponse (
2028+ $ currentStoreGroupQuery ,
2029+ [
2030+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
2031+ 'Store ' => $ secondStoreCode
2032+ ]
2033+ );
2034+
2035+ // remove new store
2036+ $ registry = $ this ->objectManager ->get (\Magento \Framework \Registry::class);
2037+ $ registry ->unregister ('isSecureArea ' );
2038+ $ registry ->register ('isSecureArea ' , true );
2039+ $ store ->delete ();
2040+ $ registry ->unregister ('isSecureArea ' );
2041+ $ registry ->register ('isSecureArea ' , false );
2042+ }
2043+
16832044 private function changeToTwoWebsitesThreeStoreGroupsThreeStores ()
16842045 {
16852046 /** @var $website2 \Magento\Store\Model\Website */
0 commit comments