|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * This code is partially based on the Rack-Cache library by Ryan Tomayko, |
| 9 | + * which is released under the MIT license. |
| 10 | + * (based on commit 02d2b48d75bcb63cf1c0c7149c077ad256542801) |
| 11 | + * |
| 12 | + * For the full copyright and license information, please view the LICENSE |
| 13 | + * file that was distributed with this source code. |
| 14 | + */ |
| 15 | + |
| 16 | +namespace Symfony\Component\HttpKernel\Tests\HttpCache; |
| 17 | + |
| 18 | +use Symfony\Component\HttpFoundation\Response; |
| 19 | +use Symfony\Component\HttpKernel\HttpCache\EsiResponseCacheStrategy; |
| 20 | + |
| 21 | +class EsiResponseCacheStrategyTest extends \PHPUnit_Framework_TestCase |
| 22 | +{ |
| 23 | + public function testMinimumSharedMaxAgeWins() |
| 24 | + { |
| 25 | + $cacheStrategy = new EsiResponseCacheStrategy(); |
| 26 | + |
| 27 | + $response1 = new Response(); |
| 28 | + $response1->setSharedMaxAge(60); |
| 29 | + $cacheStrategy->add($response1); |
| 30 | + |
| 31 | + $response2 = new Response(); |
| 32 | + $response2->setSharedMaxAge(3600); |
| 33 | + $cacheStrategy->add($response2); |
| 34 | + |
| 35 | + $response = new Response(); |
| 36 | + $response->setSharedMaxAge(86400); |
| 37 | + $cacheStrategy->update($response); |
| 38 | + |
| 39 | + $this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage')); |
| 40 | + } |
| 41 | + |
| 42 | + public function testSharedMaxAgeNotSetIfNotSetInAnyEmbeddedRequest() |
| 43 | + { |
| 44 | + $cacheStrategy = new EsiResponseCacheStrategy(); |
| 45 | + |
| 46 | + $response1 = new Response(); |
| 47 | + $response1->setSharedMaxAge(60); |
| 48 | + $cacheStrategy->add($response1); |
| 49 | + |
| 50 | + $response2 = new Response(); |
| 51 | + $cacheStrategy->add($response2); |
| 52 | + |
| 53 | + $response = new Response(); |
| 54 | + $response->setSharedMaxAge(86400); |
| 55 | + $cacheStrategy->update($response); |
| 56 | + |
| 57 | + $this->assertFalse($response->headers->hasCacheControlDirective('s-maxage')); |
| 58 | + } |
| 59 | + |
| 60 | + public function testSharedMaxAgeNotSetIfNotSetInMasterRequest() |
| 61 | + { |
| 62 | + $cacheStrategy = new EsiResponseCacheStrategy(); |
| 63 | + |
| 64 | + $response1 = new Response(); |
| 65 | + $response1->setSharedMaxAge(60); |
| 66 | + $cacheStrategy->add($response1); |
| 67 | + |
| 68 | + $response2 = new Response(); |
| 69 | + $response2->setSharedMaxAge(3600); |
| 70 | + $cacheStrategy->add($response2); |
| 71 | + |
| 72 | + $response = new Response(); |
| 73 | + $cacheStrategy->update($response); |
| 74 | + |
| 75 | + $this->assertFalse($response->headers->hasCacheControlDirective('s-maxage')); |
| 76 | + } |
| 77 | +} |
0 commit comments