19
19
class UrlResolverCacheTest extends GraphQLPageCacheAbstract
20
20
{
21
21
/**
22
- * Tests cache invalidation for product urlResolver
22
+ * Tests cache works properly for product urlResolver
23
23
*
24
24
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
25
25
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
@@ -32,13 +32,16 @@ public function testUrlResolverCachingForProducts()
32
32
// Obtain the X-Magento-Cache-Id from the response which will be used as the cache key
33
33
$ response = $ this ->graphQlQueryWithResponseHeaders ($ urlResolverQuery );
34
34
$ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ response ['headers ' ]);
35
- $ cacheId = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
35
+ $ cacheIdForProducts = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
36
36
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
37
- $ this ->assertCacheMissAndReturnResponse ($ urlResolverQuery , [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]);
37
+ $ this ->assertCacheMissAndReturnResponse (
38
+ $ urlResolverQuery ,
39
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForProducts ]
40
+ );
38
41
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
39
42
$ cachedResponse = $ this ->assertCacheHitAndReturnResponse (
40
43
$ urlResolverQuery ,
41
- [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]
44
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForProducts ]
42
45
);
43
46
44
47
//cached data should be correct
@@ -60,13 +63,16 @@ public function testUrlResolverCachingForCategory()
60
63
61
64
$ response = $ this ->graphQlQueryWithResponseHeaders ($ query );
62
65
$ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ response ['headers ' ]);
63
- $ cacheId = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
66
+ $ cacheIdForCategory = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
64
67
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
65
- $ this ->assertCacheMissAndReturnResponse ($ query , [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]);
68
+ $ this ->assertCacheMissAndReturnResponse (
69
+ $ query ,
70
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForCategory ]
71
+ );
66
72
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
67
73
$ cachedResponse = $ this ->assertCacheHitAndReturnResponse (
68
74
$ query ,
69
- [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]
75
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForCategory ]
70
76
);
71
77
72
78
//verify cached data is correct
@@ -91,13 +97,16 @@ public function testUrlResolverCachingForCMSPage()
91
97
$ query = $ this ->getUrlResolverQuery ($ requestPath );
92
98
$ response = $ this ->graphQlQueryWithResponseHeaders ($ query );
93
99
$ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ response ['headers ' ]);
94
- $ cacheId = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
100
+ $ cacheIdForCmsPage = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
95
101
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
96
- $ this ->assertCacheMissAndReturnResponse ($ query , [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]);
102
+ $ this ->assertCacheMissAndReturnResponse (
103
+ $ query ,
104
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForCmsPage ]
105
+ );
97
106
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
98
107
$ cachedResponse = $ this ->assertCacheHitAndReturnResponse (
99
108
$ query ,
100
- [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]
109
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForCmsPage ]
101
110
);
102
111
103
112
//verify cached data is correct
@@ -122,11 +131,17 @@ public function testCacheIsInvalidatedForUrlResolver()
122
131
// Obtain the X-Magento-Cache-Id from the response which will be used as the cache key
123
132
$ response = $ this ->graphQlQueryWithResponseHeaders ($ urlResolverQuery );
124
133
$ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ response ['headers ' ]);
125
- $ cacheId = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
134
+ $ cacheIdForUrlResolver = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
126
135
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
127
- $ this ->assertCacheMissAndReturnResponse ($ urlResolverQuery , [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]);
136
+ $ this ->assertCacheMissAndReturnResponse (
137
+ $ urlResolverQuery ,
138
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForUrlResolver ]
139
+ );
128
140
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
129
- $ this ->assertCacheHitAndReturnResponse ($ urlResolverQuery , [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]);
141
+ $ this ->assertCacheHitAndReturnResponse (
142
+ $ urlResolverQuery ,
143
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForUrlResolver ]
144
+ );
130
145
131
146
/** @var ProductRepositoryInterface $productRepository */
132
147
$ productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
@@ -135,7 +150,10 @@ public function testCacheIsInvalidatedForUrlResolver()
135
150
$ product ->setUrlKey ('p002-new.html ' )->save ();
136
151
137
152
// Verify we obtain a cache MISS the third time after product url key is updated
138
- $ this ->assertCacheMissAndReturnResponse ($ urlResolverQuery , [CacheIdCalculator::CACHE_ID_HEADER => $ cacheId ]);
153
+ $ this ->assertCacheMissAndReturnResponse (
154
+ $ urlResolverQuery ,
155
+ [CacheIdCalculator::CACHE_ID_HEADER => $ cacheIdForUrlResolver ]
156
+ );
139
157
}
140
158
141
159
/**
0 commit comments