ResponseTestCase.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Component\HttpFoundation\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. abstract class ResponseTestCase extends TestCase
  14. {
  15. public function testNoCacheControlHeaderOnAttachmentUsingHTTPSAndMSIE()
  16. {
  17. // Check for HTTPS and IE 8
  18. $request = new Request();
  19. $request->server->set('HTTPS', true);
  20. $request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
  21. $response = $this->provideResponse();
  22. $response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
  23. $response->prepare($request);
  24. $this->assertFalse($response->headers->has('Cache-Control'));
  25. // Check for IE 10 and HTTPS
  26. $request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)');
  27. $response = $this->provideResponse();
  28. $response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
  29. $response->prepare($request);
  30. $this->assertTrue($response->headers->has('Cache-Control'));
  31. // Check for IE 9 and HTTPS
  32. $request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)');
  33. $response = $this->provideResponse();
  34. $response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
  35. $response->prepare($request);
  36. $this->assertTrue($response->headers->has('Cache-Control'));
  37. // Check for IE 9 and HTTP
  38. $request->server->set('HTTPS', false);
  39. $response = $this->provideResponse();
  40. $response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
  41. $response->prepare($request);
  42. $this->assertTrue($response->headers->has('Cache-Control'));
  43. // Check for IE 8 and HTTP
  44. $request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
  45. $response = $this->provideResponse();
  46. $response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
  47. $response->prepare($request);
  48. $this->assertTrue($response->headers->has('Cache-Control'));
  49. // Check for non-IE and HTTPS
  50. $request->server->set('HTTPS', true);
  51. $request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17');
  52. $response = $this->provideResponse();
  53. $response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
  54. $response->prepare($request);
  55. $this->assertTrue($response->headers->has('Cache-Control'));
  56. // Check for non-IE and HTTP
  57. $request->server->set('HTTPS', false);
  58. $response = $this->provideResponse();
  59. $response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
  60. $response->prepare($request);
  61. $this->assertTrue($response->headers->has('Cache-Control'));
  62. }
  63. abstract protected function provideResponse();
  64. }