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\HttpFoundation\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\RedirectResponse;
17 class RedirectResponseTest extends TestCase
19 public function testGenerateMetaRedirect()
21 $response = new RedirectResponse('foo.bar');
23 $this->assertEquals(1, preg_match(
24 '#<meta http-equiv="refresh" content="\d+;url=foo\.bar" />#',
25 preg_replace(array('/\s+/', '/\'/'), array(' ', '"'), $response->getContent())
30 * @expectedException \InvalidArgumentException
32 public function testRedirectResponseConstructorNullUrl()
34 $response = new RedirectResponse(null);
38 * @expectedException \InvalidArgumentException
40 public function testRedirectResponseConstructorWrongStatusCode()
42 $response = new RedirectResponse('foo.bar', 404);
45 public function testGenerateLocationHeader()
47 $response = new RedirectResponse('foo.bar');
49 $this->assertTrue($response->headers->has('Location'));
50 $this->assertEquals('foo.bar', $response->headers->get('Location'));
53 public function testGetTargetUrl()
55 $response = new RedirectResponse('foo.bar');
57 $this->assertEquals('foo.bar', $response->getTargetUrl());
60 public function testSetTargetUrl()
62 $response = new RedirectResponse('foo.bar');
63 $response->setTargetUrl('baz.beep');
65 $this->assertEquals('baz.beep', $response->getTargetUrl());
69 * @expectedException \InvalidArgumentException
71 public function testSetTargetUrlNull()
73 $response = new RedirectResponse('foo.bar');
74 $response->setTargetUrl(null);
77 public function testCreate()
79 $response = RedirectResponse::create('foo', 301);
81 $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
82 $this->assertEquals(301, $response->getStatusCode());