-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathHttpRedirectResponseTest.php
executable file
·132 lines (117 loc) · 5.43 KB
/
HttpRedirectResponseTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Illuminate\Tests\Http;
use Mockery as m;
use BadMethodCallException;
use Illuminate\Http\Request;
use PHPUnit\Framework\TestCase;
use Illuminate\Http\RedirectResponse;
class HttpRedirectResponseTest extends TestCase
{
public function tearDown()
{
m::close();
}
public function testHeaderOnRedirect()
{
$response = new RedirectResponse('foo.bar');
$this->assertNull($response->headers->get('foo'));
$response->header('foo', 'bar');
$this->assertEquals('bar', $response->headers->get('foo'));
$response->header('foo', 'baz', false);
$this->assertEquals('bar', $response->headers->get('foo'));
$response->header('foo', 'baz');
$this->assertEquals('baz', $response->headers->get('foo'));
}
public function testWithOnRedirect()
{
$response = new RedirectResponse('foo.bar');
$response->setRequest(Request::create('/', 'GET', ['name' => 'Taylor', 'age' => 26]));
$response->setSession($session = m::mock('Illuminate\Session\Store'));
$session->shouldReceive('flash')->twice();
$response->with(['name', 'age']);
}
public function testWithCookieOnRedirect()
{
$response = new RedirectResponse('foo.bar');
$this->assertCount(0, $response->headers->getCookies());
$this->assertEquals($response, $response->withCookie(new \Symfony\Component\HttpFoundation\Cookie('foo', 'bar')));
$cookies = $response->headers->getCookies();
$this->assertCount(1, $cookies);
$this->assertEquals('foo', $cookies[0]->getName());
$this->assertEquals('bar', $cookies[0]->getValue());
}
public function testInputOnRedirect()
{
$response = new RedirectResponse('foo.bar');
$response->setRequest(Request::create('/', 'GET', ['name' => 'Taylor', 'age' => 26]));
$response->setSession($session = m::mock('Illuminate\Session\Store'));
$session->shouldReceive('flashInput')->once()->with(['name' => 'Taylor', 'age' => 26]);
$response->withInput();
}
public function testOnlyInputOnRedirect()
{
$response = new RedirectResponse('foo.bar');
$response->setRequest(Request::create('/', 'GET', ['name' => 'Taylor', 'age' => 26]));
$response->setSession($session = m::mock('Illuminate\Session\Store'));
$session->shouldReceive('flashInput')->once()->with(['name' => 'Taylor']);
$response->onlyInput('name');
}
public function testExceptInputOnRedirect()
{
$response = new RedirectResponse('foo.bar');
$response->setRequest(Request::create('/', 'GET', ['name' => 'Taylor', 'age' => 26]));
$response->setSession($session = m::mock('Illuminate\Session\Store'));
$session->shouldReceive('flashInput')->once()->with(['name' => 'Taylor']);
$response->exceptInput('age');
}
public function testFlashingErrorsOnRedirect()
{
$response = new RedirectResponse('foo.bar');
$response->setRequest(Request::create('/', 'GET', ['name' => 'Taylor', 'age' => 26]));
$response->setSession($session = m::mock('Illuminate\Session\Store'));
$session->shouldReceive('get')->with('errors', m::type('Illuminate\Support\ViewErrorBag'))->andReturn(new \Illuminate\Support\ViewErrorBag);
$session->shouldReceive('flash')->once()->with('errors', m::type('Illuminate\Support\ViewErrorBag'));
$provider = m::mock('Illuminate\Contracts\Support\MessageProvider');
$provider->shouldReceive('getMessageBag')->once()->andReturn(new \Illuminate\Support\MessageBag);
$response->withErrors($provider);
}
public function testSettersGettersOnRequest()
{
$response = new RedirectResponse('foo.bar');
$this->assertNull($response->getRequest());
$this->assertNull($response->getSession());
$request = Request::create('/', 'GET');
$session = m::mock('Illuminate\Session\Store');
$response->setRequest($request);
$response->setSession($session);
$this->assertSame($request, $response->getRequest());
$this->assertSame($session, $response->getSession());
}
public function testRedirectWithErrorsArrayConvertsToMessageBag()
{
$response = new RedirectResponse('foo.bar');
$response->setRequest(Request::create('/', 'GET', ['name' => 'Taylor', 'age' => 26]));
$response->setSession($session = m::mock('Illuminate\Session\Store'));
$session->shouldReceive('get')->with('errors', m::type('Illuminate\Support\ViewErrorBag'))->andReturn(new \Illuminate\Support\ViewErrorBag);
$session->shouldReceive('flash')->once()->with('errors', m::type('Illuminate\Support\ViewErrorBag'));
$provider = ['foo' => 'bar'];
$response->withErrors($provider);
}
public function testMagicCall()
{
$response = new RedirectResponse('foo.bar');
$response->setRequest(Request::create('/', 'GET', ['name' => 'Taylor', 'age' => 26]));
$response->setSession($session = m::mock('Illuminate\Session\Store'));
$session->shouldReceive('flash')->once()->with('foo', 'bar');
$response->withFoo('bar');
}
/**
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Method [doesNotExist] does not exist on Redirect.
*/
public function testMagicCallException()
{
$response = new RedirectResponse('foo.bar');
$response->doesNotExist('bar');
}
}