8000 minor #58011 [HttpKernel] Improve and add tests for `Last-Modified` c… · symfony/symfony@b25a8d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b25a8d5

Browse files
minor #58011 [HttpKernel] Improve and add tests for Last-Modified computation with ESI responses (mpdude)
This PR was merged into the 6.4 branch. Discussion ---------- [HttpKernel] Improve and add tests for `Last-Modified` computation with ESI responses | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT This PR slightly improves the test cases for #42355 (which fixed #41666). It adds two tests for the cases where `Last-Modified` should _not_ be added, and updates the existing test to make it more obvious that we only look at the existence of `Last-Modified` headers, whereas the `ETag` is not relevant. Commits ------- 40d5455 Improve and add tests for Last-Modified computation with ESI responses
2 parents e1bbaf2 + 40d5455 commit b25a8d5

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

src/Symfony/Component/HttpKernel/Tests/HttpCache/ResponseCacheStrategyTest.php

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,48 @@ public function testLastModifiedIsMergedWithEmbeddedResponse()
138138
{
139139
$cacheStrategy = new ResponseCacheStrategy();
140140

141+
$mainResponse = new Response();
142+
$mainResponse->setLastModified(new \DateTimeImmutable('-2 hour'));
143+
141144
$embeddedDate = new \DateTimeImmutable('-1 hour');
145+
$embeddedResponse = new Response();
146+
$embeddedResponse->setLastModified($embeddedDate);
142147

143-
// This master response uses the "validation" model
144-
$masterResponse = new Response();
145-
$masterResponse->setLastModified(new \DateTimeImmutable('-2 hour'));
146-
$masterResponse->setEtag('foo');
148+
$cacheStrategy->add($embeddedResponse);
149+
$cacheStrategy->update($mainResponse);
150+
151+
$this->assertTrue($mainResponse->headers->has('Last-Modified'));
152+
$this->assertSame($embeddedDate->getTimestamp(), $mainResponse->getLastModified()->getTimestamp());
153+
}
154+
155+
public function testLastModifiedIsRemovedWhenEmbeddedResponseHasNoLastModified()
156+
{
157+
$cacheStrategy = new ResponseCacheStrategy();
158+
159+
$mainResponse = new Response();
160+
$mainResponse->setLastModified(new \DateTimeImmutable('-2 hour'));
147161

148-
// Embedded response uses "expiry" model
149162
$embeddedResponse = new Response();
150-
$embeddedResponse->setLastModified($embeddedDate);
163+
151164
$cacheStrategy->add($embeddedResponse);
165+
$cacheStrategy->update($mainResponse);
166+
167+
$this->assertFalse($mainResponse->headers->has('Last-Modified'));
168+
}
152169

153-
$cacheStrategy->update($masterResponse);
170+
public function testLastModifiedIsNotAddedWhenMainResponseHasNoLastModified()
171+
{
172+
$cacheStrategy = new ResponseCacheStrategy();
154173

155-
$this->assertTrue($masterResponse->isValidateable());
156-
$this->assertSame($embeddedDate->getTimestamp(), $masterResponse->getLastModified()->getTimestamp());
174+
$mainResponse = new Response();
175+
176+
$embeddedResponse = new Response();
177+
$embeddedResponse->setLastModified(new \DateTimeImmutable('-2 hour'));
178+
179+
$cacheStrategy->add($embeddedResponse);
180+
$cacheStrategy->update($mainResponse);
181+
182+
$this->assertFalse($mainResponse->headers->has('Last-Modified'));
157183
}
158184

159185
public function testMainResponseIsNotCacheableWhenEmbeddedResponseIsNotCacheable()

0 commit comments

Comments
 (0)
0