9e3e90c53e4fe1844c1d5149e8fe7e061927aae8
[yaffs-website] / vendor / symfony / http-foundation / Tests / RedirectResponseTest.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\HttpFoundation\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\RedirectResponse;
16
17 class RedirectResponseTest extends TestCase
18 {
19     public function testGenerateMetaRedirect()
20     {
21         $response = new RedirectResponse('foo.bar');
22
23         $this->assertEquals(1, preg_match(
24             '#<meta http-equiv="refresh" content="\d+;url=foo\.bar" />#',
25             preg_replace(array('/\s+/', '/\'/'), array(' ', '"'), $response->getContent())
26         ));
27     }
28
29     /**
30      * @expectedException \InvalidArgumentException
31      */
32     public function testRedirectResponseConstructorNullUrl()
33     {
34         $response = new RedirectResponse(null);
35     }
36
37     /**
38      * @expectedException \InvalidArgumentException
39      */
40     public function testRedirectResponseConstructorWrongStatusCode()
41     {
42         $response = new RedirectResponse('foo.bar', 404);
43     }
44
45     public function testGenerateLocationHeader()
46     {
47         $response = new RedirectResponse('foo.bar');
48
49         $this->assertTrue($response->headers->has('Location'));
50         $this->assertEquals('foo.bar', $response->headers->get('Location'));
51     }
52
53     public function testGetTargetUrl()
54     {
55         $response = new RedirectResponse('foo.bar');
56
57         $this->assertEquals('foo.bar', $response->getTargetUrl());
58     }
59
60     public function testSetTargetUrl()
61     {
62         $response = new RedirectResponse('foo.bar');
63         $response->setTargetUrl('baz.beep');
64
65         $this->assertEquals('baz.beep', $response->getTargetUrl());
66     }
67
68     /**
69      * @expectedException \InvalidArgumentException
70      */
71     public function testSetTargetUrlNull()
72     {
73         $response = new RedirectResponse('foo.bar');
74         $response->setTargetUrl(null);
75     }
76
77     public function testCreate()
78     {
79         $response = RedirectResponse::create('foo', 301);
80
81         $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
82         $this->assertEquals(301, $response->getStatusCode());
83     }
84 }