Skip to content

Commit d2bdf92

Browse files
committed
B2B-2471: Defects in CatalogUrlResolverIdentity and CmsUrlResolverIdentity prevent caching
1 parent 32cfe9a commit d2bdf92

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/GraphQLPageCacheAbstract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GraphQLPageCacheAbstract extends GraphQlAbstract
2121
* @param array $headers
2222
* @return array
2323
*/
24-
protected function assertCacheMiss(string $query, array $headers) :array
24+
protected function assertCacheMissAndReturnResponse(string $query, array $headers) :array
2525
{
2626
$responseMiss = $this->graphQlQueryWithResponseHeaders($query, [], '', $headers);
2727
$this->assertArrayHasKey('X-Magento-Cache-Debug', $responseMiss['headers']);
@@ -36,7 +36,7 @@ protected function assertCacheMiss(string $query, array $headers) :array
3636
* @param array $headers
3737
* @return array
3838
*/
39-
protected function assertCacheHit(string $query, array $headers) :array
39+
protected function assertCacheHitAndReturnResponse(string $query, array $headers) :array
4040
{
4141
$responseHit = $this->graphQlQueryWithResponseHeaders($query, [], '', $headers);
4242
$this->assertArrayHasKey('X-Magento-Cache-Debug', $responseHit['headers']);

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/UrlRewrite/RouteCacheTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public function testProductUrlResolver()
5555
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
5656

5757
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
58-
$this->assertCacheMiss($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
58+
$this->assertCacheMissAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
5959

6060
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
61-
$this->assertCacheHit($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
61+
$this->assertCacheHitAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
6262
}
6363

6464
/**
@@ -83,10 +83,10 @@ public function testProductUrlWithNonSeoFriendlyUrlInput()
8383
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
8484

8585
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
86-
$this->assertCacheMiss($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
86+
$this->assertCacheMissAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
8787

8888
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
89-
$this->assertCacheHit($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
89+
$this->assertCacheHitAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
9090
}
9191

9292
/**
@@ -113,10 +113,10 @@ public function testProductUrlRewriteResolver()
113113
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
114114

115115
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
116-
$this->assertCacheMiss($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
116+
$this->assertCacheMissAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
117117

118118
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
119-
$this->assertCacheHit($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
119+
$this->assertCacheHitAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
120120
}
121121

122122
/**
@@ -144,10 +144,10 @@ public function testGetNonExistentUrlRewrite()
144144
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
145145

146146
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
147-
$this->assertCacheMiss($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
147+
$this->assertCacheMissAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
148148

149149
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
150-
$this->assertCacheHit($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
150+
$this->assertCacheHitAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
151151
}
152152

153153
/**
@@ -191,10 +191,10 @@ public function testCategoryUrlResolver()
191191
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
192192

193193
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
194-
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
194+
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
195195

196196
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
197-
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
197+
$this->assertCacheHitAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
198198
}
199199

200200
/**
@@ -220,10 +220,10 @@ public function testCMSPageUrlResolver()
220220
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
221221

222222
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
223-
$this->assertCacheMiss($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
223+
$this->assertCacheMissAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
224224

225225
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
226-
$this->assertCacheHit($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
226+
$this->assertCacheHitAndReturnResponse($routeQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
227227
}
228228

229229
/**
@@ -353,10 +353,10 @@ public function testUrlRewriteCleansCacheOnChange(string $requestPath)
353353
$cacheId = $apiResponse['headers'][CacheIdCalculator::CACHE_ID_HEADER];
354354

355355
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
356-
$this->assertCacheMiss($query($requestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
356+
$this->assertCacheMissAndReturnResponse($query($requestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
357357

358358
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
359-
$this->assertCacheHit($query($requestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
359+
$this->assertCacheHitAndReturnResponse($query($requestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
360360

361361
$this->assertEquals($requestPath, $apiResponse['body']['route']['relative_url']);
362362

@@ -365,7 +365,7 @@ public function testUrlRewriteCleansCacheOnChange(string $requestPath)
365365
// renaming entity request path and validating that API will not return cached response
366366
$urlRewrite->setRequestPath('test' . $requestPath);
367367
$urlRewriteResourceModel->save($urlRewrite);
368-
$apiResponse = $this->assertCacheMiss($query($requestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
368+
$apiResponse = $this->assertCacheMissAndReturnResponse($query($requestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
369369
$this->assertNull($apiResponse['body']['route']);
370370

371371
// rolling back changes
@@ -457,10 +457,10 @@ public function testUrlRewriteCleansCacheForCustomRewrites()
457457
$cacheId = $apiResponse['headers'][CacheIdCalculator::CACHE_ID_HEADER];
458458

459459
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
460-
$this->assertCacheMiss($query($customRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
460+
$this->assertCacheMissAndReturnResponse($query($customRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
461461

462462
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
463-
$this->assertCacheHit($query($customRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
463+
$this->assertCacheHitAndReturnResponse($query($customRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
464464

465465
// confirm that API returns non-cached response for the second custom rewrite
466466
$apiResponse = $this->graphQlQueryWithResponseHeaders($query($customSecondRequestPath));
@@ -469,17 +469,17 @@ public function testUrlRewriteCleansCacheForCustomRewrites()
469469
$cacheId = $apiResponse['headers'][CacheIdCalculator::CACHE_ID_HEADER];
470470

471471
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
472-
$this->assertCacheMiss($query($customSecondRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
472+
$this->assertCacheMissAndReturnResponse($query($customSecondRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
473473

474474
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
475-
$this->assertCacheHit($query($customSecondRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
475+
$this->assertCacheHitAndReturnResponse($query($customSecondRequestPath), [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
476476
}
477477

478478
$urlRewriteResourceModel->delete($secondUrlRewriteModel);
479479

480480
// delete custom rewrite and validate that API will not return cached response
481481
$urlRewriteResourceModel->delete($urlRewriteModel);
482-
$apiResponse = $this->assertCacheMiss(
482+
$apiResponse = $this->assertCacheMissAndReturnResponse(
483483
$query($customRequestPath),
484484
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
485485
);

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/VarnishTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public function testCacheResultForGuest()
3131
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
3232

3333
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
34-
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
34+
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
3535

3636
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
37-
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
37+
$this->assertCacheHitAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
3838
}
3939

4040
/**
@@ -55,9 +55,9 @@ public function testCacheResultForGuestWithStoreHeader()
5555
$defaultStoreCacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
5656

5757
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
58-
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
58+
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
5959
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
60-
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
60+
$this->assertCacheHitAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
6161

6262
// Obtain a new X-Magento-Cache-Id using after updating the Store header
6363
$secondStoreResponse = $this->graphQlQueryWithResponseHeaders(
@@ -72,19 +72,19 @@ public function testCacheResultForGuestWithStoreHeader()
7272
$secondStoreCacheId = $secondStoreResponse['headers'][CacheIdCalculator::CACHE_ID_HEADER];
7373

7474
// Verify we obtain a cache MISS the first time we search by this X-Magento-Cache-Id
75-
$this->assertCacheMiss($query, [
75+
$this->assertCacheMissAndReturnResponse($query, [
7676
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
7777
'Store' => 'fixture_second_store'
7878
]);
7979

8080
// Verify we obtain a cache HIT the second time around with the Store header
81-
$this->assertCacheHit($query, [
81+
$this->assertCacheHitAndReturnResponse($query, [
8282
CacheIdCalculator::CACHE_ID_HEADER => $secondStoreCacheId,
8383
'Store' => 'fixture_second_store'
8484
]);
8585

8686
// Verify we still obtain a cache HIT for the default store
87-
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
87+
$this->assertCacheHitAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
8888
}
8989

9090
/**
@@ -105,9 +105,9 @@ public function testCacheResultForGuestWithCurrencyHeader()
105105
$defaultCurrencyCacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
106106

107107
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
108-
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
108+
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
109109
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
110-
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
110+
$this->assertCacheHitAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
111111

112112
// Obtain a new X-Magento-Cache-Id using after updating the Content-Currency header
113113
$secondCurrencyResponse = $this->graphQlQueryWithResponseHeaders(
@@ -122,19 +122,19 @@ public function testCacheResultForGuestWithCurrencyHeader()
122122
$secondCurrencyCacheId = $secondCurrencyResponse['headers'][CacheIdCalculator::CACHE_ID_HEADER];
123123

124124
// Verify we obtain a cache MISS the first time we search by this X-Magento-Cache-Id
125-
$this->assertCacheMiss($query, [
125+
$this->assertCacheMissAndReturnResponse($query, [
126126
CacheIdCalculator::CACHE_ID_HEADER => $secondCurrencyCacheId,
127127
'Content-Currency' => 'EUR'
128128
]);
129129

130130
// Verify we obtain a cache HIT the second time around with the changed currency header
131-
$this->assertCacheHit($query, [
131+
$this->assertCacheHitAndReturnResponse($query, [
132132
CacheIdCalculator::CACHE_ID_HEADER => $secondCurrencyCacheId,
133133
'Content-Currency' => 'EUR'
134134
]);
135135

136136
// Verify we still obtain a cache HIT for the default currency ( no Content-Currency header)
137-
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
137+
$this->assertCacheHitAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
138138
}
139139

140140
/**
@@ -153,8 +153,8 @@ public function testCacheResultForGuestWithOutdatedCacheId()
153153
$response = $this->graphQlQueryWithResponseHeaders($query);
154154
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
155155
$defaultCacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
156-
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCacheId]);
157-
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCacheId]);
156+
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCacheId]);
157+
$this->assertCacheHitAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCacheId]);
158158

159159
// Obtain a new X-Magento-Cache-Id using after updating the request with Store header
160160
$responseWithStore = $this->graphQlQueryWithResponseHeaders(
@@ -169,19 +169,19 @@ public function testCacheResultForGuestWithOutdatedCacheId()
169169
$storeCacheId = $responseWithStore['headers'][CacheIdCalculator::CACHE_ID_HEADER];
170170

171171
// Verify we still get a cache MISS since the cache id in the request doesn't match the cache id from response
172-
$this->assertCacheMiss($query, [
172+
$this->assertCacheMissAndReturnResponse($query, [
173173
CacheIdCalculator::CACHE_ID_HEADER => $defaultCacheId,
174174
'Store' => 'fixture_second_store'
175175
]);
176176

177177
// Verify we get a cache MISS first time with the updated cache id
178-
$this->assertCacheMiss($query, [
178+
$this->assertCacheMissAndReturnResponse($query, [
179179
CacheIdCalculator::CACHE_ID_HEADER => $storeCacheId,
180180
'Store' => 'fixture_second_store'
181181
]);
182182

183183
// Verify we obtain a cache HIT second time around with the updated cache id
184-
$this->assertCacheHit($query, [
184+
$this->assertCacheHitAndReturnResponse($query, [
185185
CacheIdCalculator::CACHE_ID_HEADER => $storeCacheId,
186186
'Store' => 'fixture_second_store'
187187
]);
@@ -210,13 +210,13 @@ public function testCacheResultForCustomer()
210210
$customerToken = $tokenResponse['body']['generateCustomerToken']['token'];
211211

212212
// Verify we obtain cache MISS the first time we search by this X-Magento-Cache-Id
213-
$this->assertCacheMiss($query, [
213+
$this->assertCacheMissAndReturnResponse($query, [
214214
CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer,
215215
'Authorization' => 'Bearer ' . $customerToken
216216
]);
217217

218218
// Verify we obtain cache HIT second time using the same X-Magento-Cache-Id
219-
$this->assertCacheHit($query, [
219+
$this->assertCacheHitAndReturnResponse($query, [
220220
CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer,
221221
'Authorization' => 'Bearer ' . $customerToken
222222
]);
@@ -237,8 +237,8 @@ public function testCacheResultForCustomer()
237237
$this->assertNotEquals($cacheIdCustomer, $cacheIdGuest);
238238

239239
//Verify that omitting the Auth token doesn't send cached content for a logged-in customer
240-
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer]);
241-
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer]);
240+
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer]);
241+
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer]);
242242
}
243243

244244
/**

0 commit comments

Comments
 (0)