Skip to content

Commit d572f70

Browse files
committed
B2B-2471: Defects in CatalogUrlResolverIdentity and CmsUrlResolverIdentity prevent caching
1 parent 528ed74 commit d572f70

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\PageCache;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
12+
/**
13+
* Abstract class for GraphQL page cache test
14+
*/
15+
class GraphQLPageCacheAbstract extends GraphQlAbstract
16+
{
17+
/**
18+
* Assert that we obtain a cache MISS when sending the provided query & headers.
19+
*
20+
* @param string $query
21+
* @param array $headers
22+
* @return array
23+
*/
24+
protected function assertCacheMiss(string $query, array $headers) :array
25+
{
26+
$responseMiss = $this->graphQlQueryWithResponseHeaders($query, [], '', $headers);
27+
$this->assertArrayHasKey('X-Magento-Cache-Debug', $responseMiss['headers']);
28+
$this->assertEquals('MISS', $responseMiss['headers']['X-Magento-Cache-Debug']);
29+
return $responseMiss;
30+
}
31+
32+
/**
33+
* Assert that we obtain a cache HIT when sending the provided query & headers.
34+
*
35+
* @param string $query
36+
* @param array $headers
37+
* @return array
38+
*/
39+
protected function assertCacheHit(string $query, array $headers) :array
40+
{
41+
$responseHit = $this->graphQlQueryWithResponseHeaders($query, [], '', $headers);
42+
$this->assertArrayHasKey('X-Magento-Cache-Debug', $responseHit['headers']);
43+
$this->assertEquals('HIT', $responseHit['headers']['X-Magento-Cache-Debug']);
44+
return $responseHit;
45+
}
46+
}

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
namespace Magento\GraphQl\PageCache;
99

1010
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
11-
use Magento\TestFramework\TestCase\GraphQlAbstract;
1211

1312
/**
1413
* Test that caching works properly for Varnish when using the X-Magento-Cache-Id
1514
*/
16-
class VarnishTest extends GraphQlAbstract
15+
class VarnishTest extends GraphQLPageCacheAbstract
1716
{
1817
/**
1918
* Test that we obtain cache MISS/HIT when expected for a guest.
@@ -54,7 +53,10 @@ public function testCacheResultForGuestWithStoreHeader()
5453
$response = $this->graphQlQueryWithResponseHeaders($query);
5554
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
5655
$defaultStoreCacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
56+
57+
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
5758
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
59+
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
5860
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
5961

6062
// Obtain a new X-Magento-Cache-Id using after updating the Store header
@@ -101,7 +103,10 @@ public function testCacheResultForGuestWithCurrencyHeader()
101103
$response = $this->graphQlQueryWithResponseHeaders($query);
102104
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
103105
$defaultCurrencyCacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
106+
107+
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
104108
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
109+
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
105110
$this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
106111

107112
// Obtain a new X-Magento-Cache-Id using after updating the Content-Currency header
@@ -236,32 +241,6 @@ public function testCacheResultForCustomer()
236241
$this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer]);
237242
}
238243

239-
/**
240-
* Assert that we obtain a cache MISS when sending the provided query & headers.
241-
*
242-
* @param string $query
243-
* @param array $headers
244-
*/
245-
private function assertCacheMiss(string $query, array $headers)
246-
{
247-
$responseMiss = $this->graphQlQueryWithResponseHeaders($query, [], '', $headers);
248-
$this->assertArrayHasKey('X-Magento-Cache-Debug', $responseMiss['headers']);
249-
$this->assertEquals('MISS', $responseMiss['headers']['X-Magento-Cache-Debug']);
250-
}
251-
252-
/**
253-
* Assert that we obtain a cache HIT when sending the provided query & headers.
254-
*
255-
* @param string $query
256-
* @param array $headers
257-
*/
258-
private function assertCacheHit(string $query, array $headers)
259-
{
260-
$responseHit = $this->graphQlQueryWithResponseHeaders($query, [], '', $headers);
261-
$this->assertArrayHasKey('X-Magento-Cache-Debug', $responseHit['headers']);
262-
$this->assertEquals('HIT', $responseHit['headers']['X-Magento-Cache-Debug']);
263-
}
264-
265244
/**
266245
* Get product query
267246
*

0 commit comments

Comments
 (0)