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