|
8 | 8 | namespace Magento\GraphQl\PageCache;
|
9 | 9 |
|
10 | 10 | use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
|
11 |
| -use Magento\TestFramework\TestCase\GraphQlAbstract; |
12 | 11 |
|
13 | 12 | /**
|
14 | 13 | * Test that caching works properly for Varnish when using the X-Magento-Cache-Id
|
15 | 14 | */
|
16 |
| -class VarnishTest extends GraphQlAbstract |
| 15 | +class VarnishTest extends GraphQLPageCacheAbstract |
17 | 16 | {
|
18 | 17 | /**
|
19 | 18 | * Test that we obtain cache MISS/HIT when expected for a guest.
|
@@ -54,7 +53,10 @@ public function testCacheResultForGuestWithStoreHeader()
|
54 | 53 | $response = $this->graphQlQueryWithResponseHeaders($query);
|
55 | 54 | $this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
|
56 | 55 | $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 |
57 | 58 | $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 |
58 | 60 | $this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultStoreCacheId]);
|
59 | 61 |
|
60 | 62 | // Obtain a new X-Magento-Cache-Id using after updating the Store header
|
@@ -101,7 +103,10 @@ public function testCacheResultForGuestWithCurrencyHeader()
|
101 | 103 | $response = $this->graphQlQueryWithResponseHeaders($query);
|
102 | 104 | $this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
|
103 | 105 | $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 |
104 | 108 | $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 |
105 | 110 | $this->assertCacheHit($query, [CacheIdCalculator::CACHE_ID_HEADER => $defaultCurrencyCacheId]);
|
106 | 111 |
|
107 | 112 | // Obtain a new X-Magento-Cache-Id using after updating the Content-Currency header
|
@@ -236,32 +241,6 @@ public function testCacheResultForCustomer()
|
236 | 241 | $this->assertCacheMiss($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheIdCustomer]);
|
237 | 242 | }
|
238 | 243 |
|
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 |
| - |
265 | 244 | /**
|
266 | 245 | * Get product query
|
267 | 246 | *
|
|
0 commit comments