13
13
use Magento \Framework \Api \SearchCriteriaBuilder ;
14
14
use Magento \Framework \App \Cache \Frontend \Factory as CacheFrontendFactory ;
15
15
use Magento \Framework \App \Cache \StateInterface as CacheState ;
16
- use Magento \Framework \ObjectManagerInterface ;
17
- use Magento \GraphQlCache \Model \Cache \Query \Resolver \Result \Type as GraphQlCache ;
16
+ use Magento \GraphQlCache \Model \Cache \Query \Resolver \Result \Type as GraphQlResolverCache ;
18
17
use Magento \GraphQlCache \Model \CacheId \CacheIdCalculator ;
19
18
use Magento \Integration \Api \CustomerTokenServiceInterface ;
20
19
use Magento \Store \Model \StoreManagerInterface ;
28
27
class PageTest extends GraphQlAbstract
29
28
{
30
29
/**
31
- * @var ObjectManagerInterface
30
+ * @var GraphQlResolverCache
32
31
*/
33
- private $ objectManager ;
34
-
35
- /**
36
- * @var GraphQlCache
37
- */
38
- private $ graphqlCache ;
32
+ private $ graphQlResolverCache ;
39
33
40
34
/**
41
35
* @var PageRepository
@@ -69,25 +63,25 @@ class PageTest extends GraphQlAbstract
69
63
70
64
protected function setUp (): void
71
65
{
72
- $ this -> objectManager = $ objectManager = ObjectManager::getInstance ();
66
+ $ objectManager = ObjectManager::getInstance ();
73
67
74
- $ this ->graphqlCache = $ objectManager ->get (GraphQlCache ::class);
68
+ $ this ->graphQlResolverCache = $ objectManager ->get (GraphQlResolverCache ::class);
75
69
$ this ->pageRepository = $ objectManager ->get (PageRepository::class);
76
70
$ this ->searchCriteriaBuilder = $ objectManager ->get (SearchCriteriaBuilder::class);
77
71
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
78
72
$ this ->storeManager = $ objectManager ->get (StoreManagerInterface::class);
79
73
80
74
$ this ->cacheState = $ objectManager ->get (CacheState::class);
81
- $ this ->originalCacheStateEnabledStatus = $ this ->cacheState ->isEnabled (GraphQlCache ::TYPE_IDENTIFIER );
82
- $ this ->cacheState ->setEnabled (GraphQlCache ::TYPE_IDENTIFIER , true );
75
+ $ this ->originalCacheStateEnabledStatus = $ this ->cacheState ->isEnabled (GraphQlResolverCache ::TYPE_IDENTIFIER );
76
+ $ this ->cacheState ->setEnabled (GraphQlResolverCache ::TYPE_IDENTIFIER , true );
83
77
}
84
78
85
79
protected function tearDown (): void
86
80
{
87
81
// clean graphql resolver cache and reset to original enablement status
88
- $ this ->graphqlCache ->clean ();
82
+ $ this ->graphQlResolverCache ->clean ();
89
83
$ this ->cacheState ->setEnabled (
90
- GraphQlCache ::TYPE_IDENTIFIER ,
84
+ GraphQlResolverCache ::TYPE_IDENTIFIER ,
91
85
$ this ->originalCacheStateEnabledStatus
92
86
);
93
87
@@ -108,7 +102,7 @@ public function testCmsPageResolverCacheAndInvalidationAsGuest()
108
102
109
103
$ cacheIdentityString = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page );
110
104
111
- $ cacheEntry = $ this ->graphqlCache ->load ($ cacheIdentityString );
105
+ $ cacheEntry = $ this ->graphQlResolverCache ->load ($ cacheIdentityString );
112
106
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
113
107
114
108
$ this ->assertEqualsCanonicalizing (
@@ -123,7 +117,7 @@ public function testCmsPageResolverCacheAndInvalidationAsGuest()
123
117
$ this ->pageRepository ->save ($ page );
124
118
125
119
$ this ->assertFalse (
126
- $ this ->graphqlCache ->test ($ cacheIdentityString ),
120
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityString ),
127
121
'Cache entry still exists for CMS page '
128
122
);
129
123
}
@@ -154,7 +148,7 @@ public function testCmsPageResolverCacheAndInvalidationAsCustomer()
154
148
155
149
$ cacheIdentityString = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page );
156
150
157
- $ cacheEntry = $ this ->graphqlCache ->load ($ cacheIdentityString );
151
+ $ cacheEntry = $ this ->graphQlResolverCache ->load ($ cacheIdentityString );
158
152
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
159
153
160
154
$ this ->assertEqualsCanonicalizing (
@@ -169,7 +163,7 @@ public function testCmsPageResolverCacheAndInvalidationAsCustomer()
169
163
$ this ->pageRepository ->save ($ page );
170
164
171
165
$ this ->assertFalse (
172
- $ this ->graphqlCache ->test ($ cacheIdentityString ),
166
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityString ),
173
167
'Cache entry still exists for CMS page '
174
168
);
175
169
}
@@ -192,7 +186,7 @@ public function testCmsPageResolverCacheWithPostRequest()
192
186
193
187
$ cacheIdentityString = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page );
194
188
195
- $ cacheEntry = $ this ->graphqlCache ->load ($ cacheIdentityString );
189
+ $ cacheEntry = $ this ->graphQlResolverCache ->load ($ cacheIdentityString );
196
190
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
197
191
198
192
$ this ->assertEqualsCanonicalizing (
@@ -227,7 +221,7 @@ public function testCmsPageResolverCacheGeneratesSeparateEntriesBasedOnArguments
227
221
228
222
$ resolverCacheKeyForGuestQuery = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page );
229
223
230
- $ cacheEntry = $ this ->graphqlCache ->load ($ resolverCacheKeyForGuestQuery );
224
+ $ cacheEntry = $ this ->graphQlResolverCache ->load ($ resolverCacheKeyForGuestQuery );
231
225
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
232
226
233
227
$ this ->assertEqualsCanonicalizing (
@@ -250,7 +244,7 @@ public function testCmsPageResolverCacheGeneratesSeparateEntriesBasedOnArguments
250
244
251
245
$ resolverCacheKeyForUserQuery = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page );
252
246
253
- $ cacheEntry = $ this ->graphqlCache ->load ($ resolverCacheKeyForUserQuery );
247
+ $ cacheEntry = $ this ->graphQlResolverCache ->load ($ resolverCacheKeyForUserQuery );
254
248
$ cacheEntryDecoded = json_decode ($ cacheEntry , true );
255
249
256
250
$ this ->assertEqualsCanonicalizing (
@@ -267,7 +261,7 @@ public function testCmsPageResolverCacheGeneratesSeparateEntriesBasedOnArguments
267
261
$ this ->assertCount (count ($ resolverCacheKeys ), array_unique ($ resolverCacheKeys ));
268
262
269
263
foreach ($ resolverCacheKeys as $ cacheIdentityString ) {
270
- $ this ->assertNotFalse ($ this ->graphqlCache ->load ($ cacheIdentityString ));
264
+ $ this ->assertNotFalse ($ this ->graphQlResolverCache ->load ($ cacheIdentityString ));
271
265
}
272
266
273
267
// invalidate first page and assert first two cache identities (guest and user) are invalidated,
@@ -278,11 +272,11 @@ public function testCmsPageResolverCacheGeneratesSeparateEntriesBasedOnArguments
278
272
279
273
list ($ page1GuestKey , $ page1UserKey , $ page2GuestKey , $ page2UserKey ) = $ resolverCacheKeys ;
280
274
281
- $ this ->assertFalse ($ this ->graphqlCache ->load ($ page1GuestKey ));
282
- $ this ->assertFalse ($ this ->graphqlCache ->load ($ page1UserKey ));
275
+ $ this ->assertFalse ($ this ->graphQlResolverCache ->load ($ page1GuestKey ));
276
+ $ this ->assertFalse ($ this ->graphQlResolverCache ->load ($ page1UserKey ));
283
277
284
- $ this ->assertNotFalse ($ this ->graphqlCache ->load ($ page2GuestKey ));
285
- $ this ->assertNotFalse ($ this ->graphqlCache ->load ($ page2UserKey ));
278
+ $ this ->assertNotFalse ($ this ->graphQlResolverCache ->load ($ page2GuestKey ));
279
+ $ this ->assertNotFalse ($ this ->graphQlResolverCache ->load ($ page2UserKey ));
286
280
}
287
281
288
282
/**
@@ -302,7 +296,7 @@ public function testCmsPageResolverCacheInvalidatesWhenPageGetsDeleted()
302
296
$ cacheIdentityStringPage1 = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page1 );
303
297
304
298
$ this ->assertIsNumeric (
305
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage1 )
299
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage1 )
306
300
);
307
301
308
302
// cache page2
@@ -314,20 +308,20 @@ public function testCmsPageResolverCacheInvalidatesWhenPageGetsDeleted()
314
308
$ cacheIdentityStringPage2 = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page2 );
315
309
316
310
$ this ->assertIsNumeric (
317
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage2 )
311
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage2 )
318
312
);
319
313
320
314
// delete page1 and assert cache is invalidated
321
315
$ this ->pageRepository ->delete ($ page1 );
322
316
323
317
$ this ->assertFalse (
324
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage1 ),
318
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage1 ),
325
319
'Cache entry still exists for deleted CMS page '
326
320
);
327
321
328
322
// assert page2 cache entry still exists
329
323
$ this ->assertIsNumeric (
330
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage2 )
324
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage2 )
331
325
);
332
326
}
333
327
@@ -347,7 +341,7 @@ public function testCmsPageResolverCacheInvalidatesWhenPageGetsDisabled()
347
341
$ cacheIdentityStringPage1 = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page1 );
348
342
349
343
$ this ->assertIsNumeric (
350
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage1 )
344
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage1 )
351
345
);
352
346
353
347
// cache page2
@@ -359,21 +353,21 @@ public function testCmsPageResolverCacheInvalidatesWhenPageGetsDisabled()
359
353
$ cacheIdentityStringPage2 = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ page2 );
360
354
361
355
$ this ->assertIsNumeric (
362
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage2 )
356
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage2 )
363
357
);
364
358
365
359
// disable page 1
366
360
$ page1 ->setIsActive (false );
367
361
$ this ->pageRepository ->save ($ page1 );
368
362
369
363
$ this ->assertFalse (
370
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage1 ),
364
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage1 ),
371
365
'Cache entry still exists for disabled CMS page '
372
366
);
373
367
374
368
// assert page2 cache entry still exists
375
369
$ this ->assertIsNumeric (
376
- $ this ->graphqlCache ->test ($ cacheIdentityStringPage2 )
370
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityStringPage2 )
377
371
);
378
372
}
379
373
@@ -401,7 +395,7 @@ public function testCmsPageResolverCacheDoesNotSaveNonExistentCmsPage()
401
395
$ cacheIdentityString = $ this ->getResolverCacheKeyFromResponseAndPage ($ response , $ nonExistentPage );
402
396
403
397
$ this ->assertFalse (
404
- $ this ->graphqlCache ->load ($ cacheIdentityString )
398
+ $ this ->graphQlResolverCache ->load ($ cacheIdentityString )
405
399
);
406
400
}
407
401
@@ -429,7 +423,7 @@ public function testCmsResolverCacheIsInvalidatedAfterChangingItsStoreView()
429
423
);
430
424
431
425
$ this ->assertIsNumeric (
432
- $ this ->graphqlCache ->test ($ cacheIdentityString )
426
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityString )
433
427
);
434
428
435
429
// change store id of page
@@ -439,7 +433,7 @@ public function testCmsResolverCacheIsInvalidatedAfterChangingItsStoreView()
439
433
440
434
// assert cache entry is invalidated
441
435
$ this ->assertFalse (
442
- $ this ->graphqlCache ->test ($ cacheIdentityString )
436
+ $ this ->graphQlResolverCache ->test ($ cacheIdentityString )
443
437
);
444
438
}
445
439
@@ -462,7 +456,7 @@ public function testCacheExpirationTimeUsesDefaultDirective()
462
456
$ page
463
457
);
464
458
465
- $ lowLevelFrontendCache = $ this ->graphqlCache ->getLowLevelFrontend ();
459
+ $ lowLevelFrontendCache = $ this ->graphQlResolverCache ->getLowLevelFrontend ();
466
460
$ metadatas = $ lowLevelFrontendCache ->getMetadatas ($ cacheIdentityString );
467
461
468
462
$ this ->assertEquals (
@@ -489,15 +483,15 @@ private function generateExpectedDataFromPage(PageInterface $page): array
489
483
490
484
private function assertTagsByCacheIdentityAndPage (string $ cacheIdentityString , PageInterface $ page ): void
491
485
{
492
- $ lowLevelFrontendCache = $ this ->graphqlCache ->getLowLevelFrontend ();
486
+ $ lowLevelFrontendCache = $ this ->graphQlResolverCache ->getLowLevelFrontend ();
493
487
$ cacheIdPrefix = $ lowLevelFrontendCache ->getOption ('cache_id_prefix ' );
494
488
$ metadatas = $ lowLevelFrontendCache ->getMetadatas ($ cacheIdentityString );
495
489
$ tags = $ metadatas ['tags ' ];
496
490
497
491
$ this ->assertEqualsCanonicalizing (
498
492
[
499
493
$ cacheIdPrefix . strtoupper (CmsPage::CACHE_TAG ) . '_ ' . $ page ->getId (),
500
- $ cacheIdPrefix . strtoupper (GraphQlCache ::CACHE_TAG ),
494
+ $ cacheIdPrefix . strtoupper (GraphQlResolverCache ::CACHE_TAG ),
501
495
$ cacheIdPrefix . 'MAGE ' ,
502
496
],
503
497
$ tags
@@ -538,7 +532,7 @@ private function getResolverCacheKeyFromResponseAndPage(array $response, PageInt
538
532
]));
539
533
540
534
$ cacheIdParts = [
541
- GraphQlCache ::CACHE_TAG ,
535
+ GraphQlResolverCache ::CACHE_TAG ,
542
536
$ cacheIdValue ,
543
537
sha1 ($ cacheIdQueryPayloadMetadata )
544
538
];
0 commit comments