@@ -2041,6 +2041,173 @@ public function testCacheNotPurgedWithNewInactiveStoreWithSecondStoreGroupSecond
2041
2041
$ registry ->register ('isSecureArea ' , false );
2042
2042
}
2043
2043
2044
+ /**
2045
+ * Creating new store with one store group website will purge the cache of availableStores
2046
+ * no matter for current store group or not
2047
+ *
2048
+ * Test stores set up:
2049
+ * STORE - WEBSITE - STORE GROUP
2050
+ * default - base - main_website_store
2051
+ * second_store_view - second - second_store
2052
+ * third_store_view - second - third_store
2053
+ *
2054
+ * @magentoConfigFixture default/system/full_page_cache/caching_application 2
2055
+ * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
2056
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2057
+ */
2058
+ public function testCachePurgedWithNewStoreCreatedInOneStoreGroupWebsite (): void
2059
+ {
2060
+ $ this ->changeToTwoWebsitesThreeStoreGroupsThreeStores ();
2061
+ $ query = $ this ->getQuery ();
2062
+
2063
+ // Query available stores of default store's website
2064
+ $ responseDefaultStore = $ this ->graphQlQueryWithResponseHeaders ($ query );
2065
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseDefaultStore ['headers ' ]);
2066
+ $ defaultStoreCacheId = $ responseDefaultStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
2067
+ // Verify we obtain a cache MISS at the 1st time
2068
+ $ this ->assertCacheMissAndReturnResponse (
2069
+ $ query ,
2070
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
2071
+ );
2072
+
2073
+ // Query available stores of default store's website and store group
2074
+ $ currentStoreGroupQuery = $ this ->getQuery ('true ' );
2075
+ $ responseDefaultStoreCurrentStoreGroup = $ this ->graphQlQueryWithResponseHeaders ($ currentStoreGroupQuery );
2076
+ $ this ->assertArrayHasKey (
2077
+ CacheIdCalculator::CACHE_ID_HEADER ,
2078
+ $ responseDefaultStoreCurrentStoreGroup ['headers ' ]
2079
+ );
2080
+ $ defaultStoreCurrentStoreGroupCacheId =
2081
+ $ responseDefaultStoreCurrentStoreGroup ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
2082
+ // Verify we obtain a cache MISS at the 1st time
2083
+ $ this ->assertCacheMissAndReturnResponse (
2084
+ $ currentStoreGroupQuery ,
2085
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCurrentStoreGroupCacheId ]
2086
+ );
2087
+
2088
+ // Query available stores of second store's website and any store groups of the website
2089
+ $ secondStoreCode = 'second_store_view ' ;
2090
+ $ responseSecondStore = $ this ->graphQlQueryWithResponseHeaders (
2091
+ $ query ,
2092
+ [],
2093
+ '' ,
2094
+ ['Store ' => $ secondStoreCode ]
2095
+ );
2096
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseSecondStore ['headers ' ]);
2097
+ $ secondStoreCacheId = $ responseSecondStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
2098
+ $ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
2099
+ // Verify we obtain a cache MISS at the 1st time
2100
+ $ this ->assertCacheMissAndReturnResponse (
2101
+ $ query ,
2102
+ [
2103
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
2104
+ 'Store ' => $ secondStoreCode
2105
+ ]
2106
+ );
2107
+
2108
+ // Query available stores of second store's website and store group
2109
+ $ responseSecondStoreCurrentStoreGroup = $ this ->graphQlQueryWithResponseHeaders (
2110
+ $ currentStoreGroupQuery ,
2111
+ [],
2112
+ '' ,
2113
+ ['Store ' => $ secondStoreCode ]
2114
+ );
2115
+ $ this ->assertArrayHasKey (
2116
+ CacheIdCalculator::CACHE_ID_HEADER ,
2117
+ $ responseSecondStoreCurrentStoreGroup ['headers ' ]
2118
+ );
2119
+ $ secondStoreCurrentStoreGroupCacheId =
2120
+ $ responseSecondStoreCurrentStoreGroup ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
2121
+ $ this ->assertNotEquals ($ secondStoreCurrentStoreGroupCacheId , $ defaultStoreCacheId );
2122
+ // Verify we obtain a cache MISS at the 1st time
2123
+ $ this ->assertCacheMissAndReturnResponse (
2124
+ $ currentStoreGroupQuery ,
2125
+ [
2126
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
2127
+ 'Store ' => $ secondStoreCode
2128
+ ]
2129
+ );
2130
+
2131
+ // Get base website
2132
+ $ website = $ this ->objectManager ->create (Website::class);
2133
+ $ website ->load ('base ' , 'code ' );
2134
+
2135
+ // Create new store group
2136
+ $ storeGroup = $ this ->objectManager ->create (Group::class);
2137
+ $ storeGroup ->setCode ('new_store ' )
2138
+ ->setName ('New store group ' )
2139
+ ->setWebsite ($ website );
2140
+ $ storeGroup ->save ();
2141
+
2142
+ // Create new store with new store group and base website
2143
+ $ store = $ this ->objectManager ->create (Store::class);
2144
+ $ store ->setData ([
2145
+ 'code ' => 'new_store_view ' ,
2146
+ 'website_id ' => $ website ->getId (),
2147
+ 'group_id ' => $ storeGroup ->getId (),
2148
+ 'name ' => 'new Store View ' ,
2149
+ 'sort_order ' => 10 ,
2150
+ 'is_active ' => 1 ,
2151
+ ]);
2152
+ $ store ->save ();
2153
+
2154
+ // Query available stores of default store's website
2155
+ // after new store with default website and new store group is created
2156
+ // Verify we obtain a cache MISS at the 2nd time
2157
+ $ this ->assertCacheMissAndReturnResponse (
2158
+ $ query ,
2159
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
2160
+ );
2161
+ // Verify we obtain a cache HIT at the 3rd time
2162
+ $ this ->assertCacheHitAndReturnResponse (
2163
+ $ query ,
2164
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
2165
+ );
2166
+
2167
+ // Query available stores of default store's website and store group
2168
+ // after new store with base website and new store group is created
2169
+ // Verify we obtain a cache MISS at the 2nd time
2170
+ $ this ->assertCacheMissAndReturnResponse (
2171
+ $ currentStoreGroupQuery ,
2172
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCurrentStoreGroupCacheId ]
2173
+ );
2174
+ // Verify we obtain a cache HIT at the 3rd time
2175
+ $ this ->assertCacheHitAndReturnResponse (
2176
+ $ currentStoreGroupQuery ,
2177
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCurrentStoreGroupCacheId ]
2178
+ );
2179
+
2180
+ // Query available stores of second store's website (second website) and any store groups of the website
2181
+ // after new store with base website and new store group is created
2182
+ // Verify we obtain a cache HIT at the 2nd time
2183
+ $ this ->assertCacheHitAndReturnResponse (
2184
+ $ query ,
2185
+ [
2186
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
2187
+ 'Store ' => $ secondStoreCode
2188
+ ]
2189
+ );
2190
+
2191
+ // Query available stores of second store's website (second website) and store group
2192
+ // after new store with base website and new store group is created
2193
+ // Verify we obtain a cache HIT at the 2nd time
2194
+ $ this ->assertCacheHitAndReturnResponse (
2195
+ $ currentStoreGroupQuery ,
2196
+ [
2197
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCurrentStoreGroupCacheId ,
2198
+ 'Store ' => $ secondStoreCode
2199
+ ]
2200
+ );
2201
+
2202
+ // remove new store
2203
+ $ registry = $ this ->objectManager ->get (\Magento \Framework \Registry::class);
2204
+ $ registry ->unregister ('isSecureArea ' );
2205
+ $ registry ->register ('isSecureArea ' , true );
2206
+ $ store ->delete ();
2207
+ $ registry ->unregister ('isSecureArea ' );
2208
+ $ registry ->register ('isSecureArea ' , false );
2209
+ }
2210
+
2044
2211
private function changeToTwoWebsitesThreeStoreGroupsThreeStores ()
2045
2212
{
2046
2213
/** @var $website2 \Magento\Store\Model\Website */
0 commit comments