ResponseHeaderBagTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\HttpFoundation;
  11. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  12. class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testCacheControlHeader()
  15. {
  16. $bag = new ResponseHeaderBag(array());
  17. $this->assertEquals('no-cache', $bag->get('Cache-Control'));
  18. $this->assertTrue($bag->hasCacheControlDirective('no-cache'));
  19. $bag = new ResponseHeaderBag(array('Cache-Control' => 'public'));
  20. $this->assertEquals('public', $bag->get('Cache-Control'));
  21. $this->assertTrue($bag->hasCacheControlDirective('public'));
  22. $bag = new ResponseHeaderBag(array('ETag' => 'abcde'));
  23. $this->assertEquals('private, max-age=0, must-revalidate', $bag->get('Cache-Control'));
  24. $this->assertTrue($bag->hasCacheControlDirective('private'));
  25. $this->assertTrue($bag->hasCacheControlDirective('must-revalidate'));
  26. $this->assertEquals(0, $bag->getCacheControlDirective('max-age'));
  27. $bag = new ResponseHeaderBag(array('Last-Modified' => 'abcde'));
  28. $this->assertEquals('private, max-age=0, must-revalidate', $bag->get('Cache-Control'));
  29. $bag = new ResponseHeaderBag(array('Etag' => 'abcde', 'Last-Modified' => 'abcde'));
  30. $this->assertEquals('private, max-age=0, must-revalidate', $bag->get('Cache-Control'));
  31. $bag = new ResponseHeaderBag(array('cache-control' => 'max-age=100'));
  32. $this->assertEquals('max-age=100, private', $bag->get('Cache-Control'));
  33. $bag = new ResponseHeaderBag(array('cache-control' => 's-maxage=100'));
  34. $this->assertEquals('s-maxage=100', $bag->get('Cache-Control'));
  35. $bag = new ResponseHeaderBag(array('cache-control' => 'private, max-age=100'));
  36. $this->assertEquals('max-age=100, private', $bag->get('Cache-Control'));
  37. $bag = new ResponseHeaderBag(array('cache-control' => 'public, max-age=100'));
  38. $this->assertEquals('max-age=100, public', $bag->get('Cache-Control'));
  39. }
  40. }