ServerBagTest.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\Tests\Component\HttpFoundation;
  11. use Symfony\Component\HttpFoundation\ServerBag;
  12. /**
  13. * ServerBagTest
  14. *
  15. * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
  16. */
  17. class ServerBagTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function testShouldExtractHeadersFromServerArray()
  20. {
  21. $server = array(
  22. 'SOME_SERVER_VARIABLE' => 'value',
  23. 'SOME_SERVER_VARIABLE2' => 'value',
  24. 'ROOT' => 'value',
  25. 'HTTP_CONTENT_TYPE' => 'text/html',
  26. 'HTTP_CONTENT_LENGTH' => '0',
  27. 'HTTP_ETAG' => 'asdf',
  28. 'PHP_AUTH_USER' => 'foo',
  29. 'PHP_AUTH_PW' => 'bar',
  30. );
  31. $bag = new ServerBag($server);
  32. $this->assertEquals(array(
  33. 'CONTENT_TYPE' => 'text/html',
  34. 'CONTENT_LENGTH' => '0',
  35. 'ETAG' => 'asdf',
  36. 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
  37. ), $bag->getHeaders());
  38. }
  39. public function testHttpPasswordIsOptional()
  40. {
  41. $bag = new ServerBag(array('PHP_AUTH_USER' => 'foo'));
  42. $this->assertEquals(array('AUTHORIZATION' => 'Basic '.base64_encode('foo:')), $bag->getHeaders());
  43. }
  44. }