4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
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)
12 * For the full copyright and license information, please view the LICENSE
13 * file that was distributed with this source code.
16 namespace Symfony\Component\HttpKernel\Tests\HttpCache;
18 use PHPUnit\Framework\TestCase;
19 use Symfony\Component\HttpFoundation\Response;
20 use Symfony\Component\HttpKernel\HttpCache\ResponseCacheStrategy;
22 class ResponseCacheStrategyTest extends TestCase
24 public function testMinimumSharedMaxAgeWins()
26 $cacheStrategy = new ResponseCacheStrategy();
28 $response1 = new Response();
29 $response1->setSharedMaxAge(60);
30 $cacheStrategy->add($response1);
32 $response2 = new Response();
33 $response2->setSharedMaxAge(3600);
34 $cacheStrategy->add($response2);
36 $response = new Response();
37 $response->setSharedMaxAge(86400);
38 $cacheStrategy->update($response);
40 $this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
43 public function testSharedMaxAgeNotSetIfNotSetInAnyEmbeddedRequest()
45 $cacheStrategy = new ResponseCacheStrategy();
47 $response1 = new Response();
48 $response1->setSharedMaxAge(60);
49 $cacheStrategy->add($response1);
51 $response2 = new Response();
52 $cacheStrategy->add($response2);
54 $response = new Response();
55 $response->setSharedMaxAge(86400);
56 $cacheStrategy->update($response);
58 $this->assertFalse($response->headers->hasCacheControlDirective('s-maxage'));
61 public function testSharedMaxAgeNotSetIfNotSetInMasterRequest()
63 $cacheStrategy = new ResponseCacheStrategy();
65 $response1 = new Response();
66 $response1->setSharedMaxAge(60);
67 $cacheStrategy->add($response1);
69 $response2 = new Response();
70 $response2->setSharedMaxAge(3600);
71 $cacheStrategy->add($response2);
73 $response = new Response();
74 $cacheStrategy->update($response);
76 $this->assertFalse($response->headers->hasCacheControlDirective('s-maxage'));