Version 1
[yaffs-website] / vendor / symfony / browser-kit / Tests / ResponseTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\BrowserKit\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\BrowserKit\Response;
16
17 class ResponseTest extends TestCase
18 {
19     public function testGetUri()
20     {
21         $response = new Response('foo');
22         $this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
23     }
24
25     public function testGetStatus()
26     {
27         $response = new Response('foo', 304);
28         $this->assertEquals('304', $response->getStatus(), '->getStatus() returns the status of the response');
29     }
30
31     public function testGetHeaders()
32     {
33         $response = new Response('foo', 200, array('foo' => 'bar'));
34         $this->assertEquals(array('foo' => 'bar'), $response->getHeaders(), '->getHeaders() returns the headers of the response');
35     }
36
37     public function testGetHeader()
38     {
39         $response = new Response('foo', 200, array(
40             'Content-Type' => 'text/html',
41             'Set-Cookie' => array('foo=bar', 'bar=foo'),
42         ));
43
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');
49
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');
52     }
53
54     public function testMagicToString()
55     {
56         $response = new Response('foo', 304, array('foo' => 'bar'));
57
58         $this->assertEquals("foo: bar\n\nfoo", $response->__toString(), '->__toString() returns the headers and the content as a string');
59     }
60
61     public function testMagicToStringWithMultipleSetCookieHeader()
62     {
63         $headers = array(
64             'content-type' => 'text/html; charset=utf-8',
65             'set-cookie' => array('foo=bar', 'bar=foo'),
66         );
67
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";
71         $expected .= 'foo';
72
73         $response = new Response('foo', 304, $headers);
74
75         $this->assertEquals($expected, $response->__toString(), '->__toString() returns the headers and the content as a string');
76     }
77 }