ResponseCacheStrategyTest.php 2.3 KB

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