4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\BrowserKit\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\BrowserKit\Response;
17 class ResponseTest extends TestCase
19 public function testGetUri()
21 $response = new Response('foo');
22 $this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
25 public function testGetStatus()
27 $response = new Response('foo', 304);
28 $this->assertEquals('304', $response->getStatus(), '->getStatus() returns the status of the response');
31 public function testGetHeaders()
33 $response = new Response('foo', 200, array('foo' => 'bar'));
34 $this->assertEquals(array('foo' => 'bar'), $response->getHeaders(), '->getHeaders() returns the headers of the response');
37 public function testGetHeader()
39 $response = new Response('foo', 200, array(
40 'Content-Type' => 'text/html',
41 'Set-Cookie' => array('foo=bar', 'bar=foo'),
44 $this->assertEquals('text/html', $response->getHeader('Content-Type'), '->getHeader() returns a header of the response');
45 $this->assertEquals('text/html', $response->getHeader('content-type'), '->getHeader() returns a header of the response');
46 $this->assertEquals('text/html', $response->getHeader('content_type'), '->getHeader() returns a header of the response');
47 $this->assertEquals('foo=bar', $response->getHeader('Set-Cookie'), '->getHeader() returns the first header value');
48 $this->assertEquals(array('foo=bar', 'bar=foo'), $response->getHeader('Set-Cookie', false), '->getHeader() returns all header values if first is false');
50 $this->assertNull($response->getHeader('foo'), '->getHeader() returns null if the header is not defined');
51 $this->assertEquals(array(), $response->getHeader('foo', false), '->getHeader() returns an empty array if the header is not defined and first is set to false');
54 public function testMagicToString()
56 $response = new Response('foo', 304, array('foo' => 'bar'));
58 $this->assertEquals("foo: bar\n\nfoo", $response->__toString(), '->__toString() returns the headers and the content as a string');
61 public function testMagicToStringWithMultipleSetCookieHeader()
64 'content-type' => 'text/html; charset=utf-8',
65 'set-cookie' => array('foo=bar', 'bar=foo'),
68 $expected = 'content-type: text/html; charset=utf-8'."\n";
69 $expected .= 'set-cookie: foo=bar'."\n";
70 $expected .= 'set-cookie: bar=foo'."\n\n";
73 $response = new Response('foo', 304, $headers);
75 $this->assertEquals($expected, $response->__toString(), '->__toString() returns the headers and the content as a string');