7
7
8
8
namespace Magento \GraphQl \PageCache ;
9
9
10
+ use Magento \PageCache \Model \Cache \Type as PageCache ;
10
11
use Magento \TestFramework \ObjectManager ;
11
12
use Magento \TestFramework \TestCase \GraphQlAbstract ;
12
13
@@ -242,6 +243,8 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
242
243
'Currency code EUR in fixture ' . $ storeCodeFromFixture . ' is unexpected '
243
244
);
244
245
246
+ $ this ->flushPageCache ();
247
+
245
248
// test cached store + currency header in Euros
246
249
$ headerMap = ['Store ' => $ storeCodeFromFixture , 'Content-Currency ' => 'EUR ' ];
247
250
$ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
@@ -256,6 +259,8 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
256
259
'Currency code EUR in fixture ' . $ storeCodeFromFixture . ' is unexpected '
257
260
);
258
261
262
+ $ this ->flushPageCache ();
263
+
259
264
// test non cached store + currency header in USD
260
265
$ headerMap = ['Store ' => $ storeCodeFromFixture , 'Content-Currency ' => 'USD ' ];
261
266
$ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
@@ -270,42 +275,41 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
270
275
'Currency code USD in fixture ' . $ storeCodeFromFixture . ' is unexpected '
271
276
);
272
277
278
+ $ this ->flushPageCache ();
279
+
273
280
// test non cached store + currency header in USD not cached
274
- $ headerMap = ['Store ' => 'default ' , 'Content-Currency ' => 'EUR ' ];
281
+ $ headerMap = ['Store ' => 'default ' , 'Content-Currency ' => 'USD ' ];
275
282
$ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
276
283
$ this ->assertEquals (
277
284
'Simple Product ' ,
278
285
$ response ['products ' ]['items ' ][0 ]['name ' ],
279
286
'Product name in fixture store is invalid. '
280
287
);
281
288
$ this ->assertEquals (
282
- 'EUR ' ,
289
+ 'USD ' ,
283
290
$ response ['products ' ]['items ' ][0 ]['price ' ]['minimalPrice ' ]['amount ' ]['currency ' ],
284
- 'Currency code EUR in fixture store default is unexpected '
291
+ 'Currency code USD in fixture store default is unexpected '
285
292
);
286
293
287
- // test cached response store + currency header with non existing currency, and no valid response, no cache
288
- $ headerMap = ['Store ' => $ storeCodeFromFixture , 'Content-Currency ' => 'SOMECURRENCY ' ];
289
- $ this ->expectExceptionMessage (
290
- 'GraphQL response contains errors: Please correct the target currency '
291
- );
292
- $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
294
+ $ this ->flushPageCache ();
293
295
294
296
// test non cached store + currency header in USD not cached
295
- $ headerMap = ['Store ' => 'default ' , 'Content-Currency ' => 'USD ' ];
297
+ $ headerMap = ['Store ' => 'default ' , 'Content-Currency ' => 'EUR ' ];
296
298
$ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
297
299
$ this ->assertEquals (
298
300
'Simple Product ' ,
299
301
$ response ['products ' ]['items ' ][0 ]['name ' ],
300
302
'Product name in fixture store is invalid. '
301
303
);
302
304
$ this ->assertEquals (
303
- 'USD ' ,
305
+ 'EUR ' ,
304
306
$ response ['products ' ]['items ' ][0 ]['price ' ]['minimalPrice ' ]['amount ' ]['currency ' ],
305
- 'Currency code USD in fixture store default is unexpected '
307
+ 'Currency code EUR in fixture store default is unexpected '
306
308
);
307
309
308
- // test non cached store + currency header in USD cached
310
+ $ this ->flushPageCache ();
311
+
312
+ // test non cached store + currency header in USD cached
309
313
$ headerMap = ['Store ' => 'default ' ];
310
314
$ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
311
315
$ this ->assertEquals (
@@ -318,5 +322,22 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
318
322
$ response ['products ' ]['items ' ][0 ]['price ' ]['minimalPrice ' ]['amount ' ]['currency ' ],
319
323
'Currency code USD in fixture store default is unexpected '
320
324
);
325
+
326
+ $ this ->flushPageCache ();
327
+
328
+ // test cached response store + currency header with non existing currency, and no valid response, no cache
329
+ $ headerMap = ['Store ' => $ storeCodeFromFixture , 'Content-Currency ' => 'SOMECURRENCY ' ];
330
+ $ this ->expectExceptionMessage (
331
+ 'GraphQL response contains errors: Please correct the target currency '
332
+ );
333
+
334
+ $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
335
+ }
336
+
337
+ protected function flushPageCache (): void
338
+ {
339
+ /** @var PageCache $fullPageCache */
340
+ $ fullPageCache = ObjectManager::getInstance ()->get (PageCache::class);
341
+ $ fullPageCache ->clean ();
321
342
}
322
343
}
0 commit comments