15
15
use Magento \Store \Api \StoreRepositoryInterface ;
16
16
use Magento \Store \Api \StoreResolverInterface ;
17
17
use Magento \Store \Model \ScopeInterface ;
18
+ use Magento \Store \Model \Store ;
18
19
use Magento \TestFramework \App \ApiMutableScopeConfig ;
19
20
use Magento \TestFramework \Config \Model \ConfigStorage ;
20
21
use Magento \TestFramework \Helper \Bootstrap ;
@@ -151,7 +152,7 @@ public function testGetStoreConfig(): void
151
152
* Store scoped config change triggers purging only the cache of the changed store.
152
153
*
153
154
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
154
- * @magentoApiDataFixture Magento/Store/_files/store .php
155
+ * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores .php
155
156
* @throws NoSuchEntityException
156
157
*/
157
158
public function testCachePurgedWithStoreScopeConfigChange (): void
@@ -177,30 +178,30 @@ public function testCachePurgedWithStoreScopeConfigChange(): void
177
178
$ this ->assertEquals ($ defaultLocale , $ defaultStoreResponseResult ['locale ' ]);
178
179
179
180
// Query test store config
180
- $ testStoreCode = 'test ' ;
181
- $ responseTestStore = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , ['Store ' => $ testStoreCode ]);
181
+ $ secondStoreCode = 'second_store_view ' ;
182
+ $ responseTestStore = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , ['Store ' => $ secondStoreCode ]);
182
183
$ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseTestStore ['headers ' ]);
183
- $ testStoreCacheId = $ responseTestStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
184
- $ this ->assertNotEquals ($ testStoreCacheId , $ defaultStoreCacheId );
184
+ $ secondStoreCacheId = $ responseTestStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
185
+ $ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
185
186
// Verify we obtain a cache MISS at the 1st time
186
- $ testStoreResponse = $ this ->assertCacheMissAndReturnResponse (
187
+ $ secondStoreResponse = $ this ->assertCacheMissAndReturnResponse (
187
188
$ query ,
188
189
[
189
- CacheIdCalculator::CACHE_ID_HEADER => $ testStoreCacheId ,
190
- 'Store ' => $ testStoreCode
190
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
191
+ 'Store ' => $ secondStoreCode
191
192
]
192
193
);
193
- $ this ->assertArrayHasKey ('storeConfig ' , $ testStoreResponse ['body ' ]);
194
- $ testStoreResponseResult = $ testStoreResponse ['body ' ]['storeConfig ' ];
195
- $ this ->assertEquals ($ testStoreCode , $ testStoreResponseResult ['code ' ]);
196
- $ this ->assertEquals ($ defaultLocale , $ testStoreResponseResult ['locale ' ]);
194
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponse ['body ' ]);
195
+ $ secondStoreResponseResult = $ secondStoreResponse ['body ' ]['storeConfig ' ];
196
+ $ this ->assertEquals ($ secondStoreCode , $ secondStoreResponseResult ['code ' ]);
197
+ $ this ->assertEquals ($ defaultLocale , $ secondStoreResponseResult ['locale ' ]);
197
198
198
- // Change test store locale
199
+ // Change second store locale
199
200
$ localeConfigPath = 'general/locale/code ' ;
200
201
$ newLocale = 'de_DE ' ;
201
- $ this ->setConfig ($ localeConfigPath , $ newLocale , ScopeInterface::SCOPE_STORE , $ testStoreCode );
202
+ $ this ->setConfig ($ localeConfigPath , $ newLocale , ScopeInterface::SCOPE_STORE , $ secondStoreCode );
202
203
203
- // Query default store config after test store config change
204
+ // Query default store config after second store config is changed
204
205
// Verify we obtain a cache HIT at the 2nd time, the cache is not purged
205
206
$ defaultStoreResponseHit = $ this ->assertCacheHitAndReturnResponse (
206
207
$ query ,
@@ -212,31 +213,128 @@ public function testCachePurgedWithStoreScopeConfigChange(): void
212
213
$ this ->assertEquals ($ defaultStoreCode , $ defaultStoreResponseHitResult ['code ' ]);
213
214
$ this ->assertEquals ($ defaultLocale , $ defaultStoreResponseHitResult ['locale ' ]);
214
215
215
- // Query test store config after test store config change
216
+ // Query second store config after second store config is changed
216
217
// Verify we obtain a cache MISS at the 2nd time, the cache is purged
217
- $ testStoreResponseMiss = $ this ->assertCacheMissAndReturnResponse (
218
+ $ secondStoreResponseMiss = $ this ->assertCacheMissAndReturnResponse (
218
219
$ query ,
219
220
[
220
- CacheIdCalculator::CACHE_ID_HEADER => $ testStoreCacheId ,
221
- 'Store ' => $ testStoreCode
221
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
222
+ 'Store ' => $ secondStoreCode
222
223
]
223
224
);
224
- $ this ->assertArrayHasKey ('storeConfig ' , $ testStoreResponseMiss ['body ' ]);
225
- $ testStoreResponseMissResult = $ testStoreResponseMiss ['body ' ]['storeConfig ' ];
226
- $ this ->assertEquals ($ testStoreCode , $ testStoreResponseMissResult ['code ' ]);
227
- $ this ->assertEquals ($ newLocale , $ testStoreResponseMissResult ['locale ' ]);
225
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponseMiss ['body ' ]);
226
+ $ secondStoreResponseMissResult = $ secondStoreResponseMiss ['body ' ]['storeConfig ' ];
227
+ $ this ->assertEquals ($ secondStoreCode , $ secondStoreResponseMissResult ['code ' ]);
228
+ $ this ->assertEquals ($ newLocale , $ secondStoreResponseMissResult ['locale ' ]);
228
229
// Verify we obtain a cache HIT at the 3rd time
229
- $ testStoreResponseHit = $ this ->assertCacheHitAndReturnResponse (
230
+ $ secondStoreResponseHit = $ this ->assertCacheHitAndReturnResponse (
230
231
$ query ,
231
232
[
232
- CacheIdCalculator::CACHE_ID_HEADER => $ testStoreCacheId ,
233
- 'Store ' => $ testStoreCode
233
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
234
+ 'Store ' => $ secondStoreCode
234
235
]
235
236
);
236
- $ this ->assertArrayHasKey ('storeConfig ' , $ testStoreResponseHit ['body ' ]);
237
- $ testStoreResponseHitResult = $ testStoreResponseHit ['body ' ]['storeConfig ' ];
238
- $ this ->assertEquals ($ testStoreCode , $ testStoreResponseHitResult ['code ' ]);
239
- $ this ->assertEquals ($ newLocale , $ testStoreResponseHitResult ['locale ' ]);
237
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponseHit ['body ' ]);
238
+ $ secondStoreResponseHitResult = $ secondStoreResponseHit ['body ' ]['storeConfig ' ];
239
+ $ this ->assertEquals ($ secondStoreCode , $ secondStoreResponseHitResult ['code ' ]);
240
+ $ this ->assertEquals ($ newLocale , $ secondStoreResponseHitResult ['locale ' ]);
241
+ }
242
+
243
+ /**
244
+ * Store change triggers purging only the cache of the changed store.
245
+ *
246
+ * @magentoConfigFixture default/system/full_page_cache/caching_application 2
247
+ * @magentoApiDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php
248
+ * @throws NoSuchEntityException
249
+ */
250
+ public function testCachePurgedWithStoreChange (): void
251
+ {
252
+ $ defaultStoreId = $ this ->defaultStoreConfig ->getId ();
253
+ $ defaultStoreCode = $ this ->defaultStoreConfig ->getCode ();
254
+ $ defaultLocale = $ this ->defaultStoreConfig ->getLocale ();
255
+ $ query = $ this ->getQuery ();
256
+
257
+ // Query default store config
258
+ $ responseDefaultStore = $ this ->graphQlQueryWithResponseHeaders ($ query );
259
+ $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseDefaultStore ['headers ' ]);
260
+ $ defaultStoreCacheId = $ responseDefaultStore ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
261
+ // Verify we obtain a cache MISS at the 1st time
262
+ $ defaultStoreResponse = $ this ->assertCacheMissAndReturnResponse (
263
+ $ query ,
264
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
265
+ );
266
+ $ this ->assertArrayHasKey ('storeConfig ' , $ defaultStoreResponse ['body ' ]);
267
+ $ defaultStoreResponseResult = $ defaultStoreResponse ['body ' ]['storeConfig ' ];
268
+ $ this ->assertEquals ($ defaultStoreId , $ defaultStoreResponseResult ['id ' ]);
269
+ $ this ->assertEquals ($ defaultStoreCode , $ defaultStoreResponseResult ['code ' ]);
270
+ $ this ->assertEquals ($ defaultLocale , $ defaultStoreResponseResult ['locale ' ]);
271
+
272
+ // 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 ];
277
+ $ this ->assertNotEquals ($ secondStoreCacheId , $ defaultStoreCacheId );
278
+ // Verify we obtain a cache MISS at the 1st time
279
+ $ secondStoreResponse = $ this ->assertCacheMissAndReturnResponse (
280
+ $ query ,
281
+ [
282
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
283
+ 'Store ' => $ secondStoreCode
284
+ ]
285
+ );
286
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponse ['body ' ]);
287
+ $ secondStoreResponseResult = $ secondStoreResponse ['body ' ]['storeConfig ' ];
288
+ $ this ->assertEquals ($ secondStoreCode , $ secondStoreResponseResult ['code ' ]);
289
+ $ secondStoreName = 'Second Store View ' ;
290
+ $ this ->assertEquals ($ secondStoreName , $ secondStoreResponseResult ['store_name ' ]);
291
+
292
+ // Change store name
293
+ /** @var Store $store */
294
+ $ store = $ this ->objectManager ->create (Store::class);
295
+ $ store ->load ($ secondStoreCode , 'code ' );
296
+ $ secondStoreNewName = $ secondStoreName . ' 2 ' ;
297
+ $ store ->setName ($ secondStoreNewName );
298
+ $ store ->save ();
299
+
300
+ // Query default store config after test store config change
301
+ // Verify we obtain a cache HIT at the 2nd time, the cache is not purged
302
+ $ defaultStoreResponseHit = $ this ->assertCacheHitAndReturnResponse (
303
+ $ query ,
304
+ [CacheIdCalculator::CACHE_ID_HEADER => $ defaultStoreCacheId ]
305
+ );
306
+ $ this ->assertArrayHasKey ('storeConfig ' , $ defaultStoreResponseHit ['body ' ]);
307
+ $ defaultStoreResponseHitResult = $ defaultStoreResponseHit ['body ' ]['storeConfig ' ];
308
+ $ this ->assertEquals ($ defaultStoreId , $ defaultStoreResponseHitResult ['id ' ]);
309
+ $ this ->assertEquals ($ defaultStoreCode , $ defaultStoreResponseHitResult ['code ' ]);
310
+ $ this ->assertEquals ($ defaultLocale , $ defaultStoreResponseHitResult ['locale ' ]);
311
+ $ this ->assertEquals ($ defaultStoreResponseResult ['store_name ' ], $ defaultStoreResponseHitResult ['store_name ' ]);
312
+
313
+ // Query second store config after second store config is changed
314
+ // Verify we obtain a cache MISS at the 2nd time, the cache is purged
315
+ $ secondStoreResponseMiss = $ this ->assertCacheMissAndReturnResponse (
316
+ $ query ,
317
+ [
318
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
319
+ 'Store ' => $ secondStoreCode
320
+ ]
321
+ );
322
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponseMiss ['body ' ]);
323
+ $ secondStoreResponseMissResult = $ secondStoreResponseMiss ['body ' ]['storeConfig ' ];
324
+ $ this ->assertEquals ($ secondStoreCode , $ secondStoreResponseMissResult ['code ' ]);
325
+ $ this ->assertEquals ($ secondStoreNewName , $ secondStoreResponseMissResult ['store_name ' ]);
326
+ // Verify we obtain a cache HIT at the 3rd time
327
+ $ secondStoreResponseHit = $ this ->assertCacheHitAndReturnResponse (
328
+ $ query ,
329
+ [
330
+ CacheIdCalculator::CACHE_ID_HEADER => $ secondStoreCacheId ,
331
+ 'Store ' => $ secondStoreCode
332
+ ]
333
+ );
334
+ $ this ->assertArrayHasKey ('storeConfig ' , $ secondStoreResponseHit ['body ' ]);
335
+ $ secondStoreResponseHitResult = $ secondStoreResponseHit ['body ' ]['storeConfig ' ];
336
+ $ this ->assertEquals ($ secondStoreCode , $ secondStoreResponseHitResult ['code ' ]);
337
+ $ this ->assertEquals ($ secondStoreNewName , $ secondStoreResponseHitResult ['store_name ' ]);
240
338
}
241
339
242
340
/**
0 commit comments