Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #18164 [HttpKernel] set s-maxage only if all responses are cachea…
…ble (xabbuh) This PR was merged into the 2.3 branch. Discussion ---------- [HttpKernel] set s-maxage only if all responses are cacheable | Q | A | ------------- | --- | Branch | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18160 | License | MIT | Doc PR | Commits ------- b7d9338 set s-maxage only if all responses are cacheable
- Loading branch information
Showing
2 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiResponseCacheStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This code is partially based on the Rack-Cache library by Ryan Tomayko, | ||
* which is released under the MIT license. | ||
* (based on commit 02d2b48d75bcb63cf1c0c7149c077ad256542801) | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\Tests\HttpCache; | ||
|
||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\HttpCache\EsiResponseCacheStrategy; | ||
|
||
class EsiResponseCacheStrategyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testMinimumSharedMaxAgeWins() | ||
{ | ||
$cacheStrategy = new EsiResponseCacheStrategy(); | ||
|
||
$response1 = new Response(); | ||
$response1->setSharedMaxAge(60); | ||
$cacheStrategy->add($response1); | ||
|
||
$response2 = new Response(); | ||
$response2->setSharedMaxAge(3600); | ||
$cacheStrategy->add($response2); | ||
|
||
$response = new Response(); | ||
$response->setSharedMaxAge(86400); | ||
$cacheStrategy->update($response); | ||
|
||
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage')); | ||
} | ||
|
||
public function testSharedMaxAgeNotSetIfNotSetInAnyEmbeddedRequest() | ||
{ | ||
$cacheStrategy = new EsiResponseCacheStrategy(); | ||
|
||
$response1 = new Response(); | ||
$response1->setSharedMaxAge(60); | ||
$cacheStrategy->add($response1); | ||
|
||
$response2 = new Response(); | ||
$cacheStrategy->add($response2); | ||
|
||
$response = new Response(); | ||
$response->setSharedMaxAge(86400); | ||
$cacheStrategy->update($response); | ||
|
||
$this->assertFalse($response->headers->hasCacheControlDirective('s-maxage')); | ||
} | ||
|
||
public function testSharedMaxAgeNotSetIfNotSetInMasterRequest() | ||
{ | ||
$cacheStrategy = new EsiResponseCacheStrategy(); | ||
|
||
$response1 = new Response(); | ||
$response1->setSharedMaxAge(60); | ||
$cacheStrategy->add($response1); | ||
|
||
$response2 = new Response(); | ||
$response2->setSharedMaxAge(3600); | ||
$cacheStrategy->add($response2); | ||
|
||
$response = new Response(); | ||
$cacheStrategy->update($response); | ||
|
||
$this->assertFalse($response->headers->hasCacheControlDirective('s-maxage')); | ||
} | ||
} |