ResponseTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Components\BrowserKit;
  11. use Symfony\Components\BrowserKit\Response;
  12. class ResponseTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testGetUri()
  15. {
  16. $response = new Response('foo');
  17. $this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
  18. }
  19. public function testGetStatus()
  20. {
  21. $response = new Response('foo', 304);
  22. $this->assertEquals('304', $response->getStatus(), '->getStatus() returns the status of the response');
  23. }
  24. public function testGetHeaders()
  25. {
  26. $response = new Response('foo', 304, array('foo' => 'bar'));
  27. $this->assertEquals(array('foo' => 'bar'), $response->getHeaders(), '->getHeaders() returns the headers of the response');
  28. }
  29. public function testGetHeader()
  30. {
  31. $response = new Response('foo', 304, array('Content-Type' => 'text/html'));
  32. $this->assertEquals('text/html', $response->getHeader('Content-Type'), '->getHeader() returns a header of the response');
  33. $this->assertEquals('text/html', $response->getHeader('content-type'), '->getHeader() returns a header of the response');
  34. $this->assertEquals('text/html', $response->getHeader('content_type'), '->getHeader() returns a header of the response');
  35. $this->assertNull($response->getHeader('foo'), '->getHeader() returns null if the header is not defined');
  36. }
  37. public function testGetCookies()
  38. {
  39. $response = new Response('foo', 304, array(), array('foo' => 'bar'));
  40. $this->assertEquals(array('foo' => 'bar'), $response->getCookies(), '->getCookies() returns the cookies of the response');
  41. }
  42. public function testMagicToString()
  43. {
  44. $response = new Response('foo', 304, array('foo' => 'bar'), array('foo' => array('value' => 'bar')));
  45. $this->assertEquals("foo: bar\nSet-Cookie: foo=bar\n\nfoo", $response->__toString(), '->__toString() returns the headers and the content as a string');
  46. }
  47. }