forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoutingRedirectorTest.php
More file actions
152 lines (109 loc) · 4.79 KB
/
RoutingRedirectorTest.php
File metadata and controls
152 lines (109 loc) · 4.79 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
use Mockery as m;
use Illuminate\Routing\Redirector;
class RoutingRedirectorTest extends PHPUnit_Framework_TestCase {
protected $headers;
protected $request;
protected $url;
protected $session;
protected $redirect;
public function setUp()
{
$this->headers = m::mock('Symfony\Component\HttpFoundation\HeaderBag');
$this->request = m::mock('Illuminate\Http\Request');
$this->request->headers = $this->headers;
$this->url = m::mock('Illuminate\Routing\UrlGenerator');
$this->url->shouldReceive('getRequest')->andReturn($this->request);
$this->url->shouldReceive('to')->with('bar', array(), null)->andReturn('http://foo.com/bar');
$this->url->shouldReceive('to')->with('bar', array(), true)->andReturn('https://foo.com/bar');
$this->url->shouldReceive('to')->with('login', array(), null)->andReturn('http://foo.com/login');
$this->url->shouldReceive('to')->with('http://foo.com/bar', array(), null)->andReturn('http://foo.com/bar');
$this->url->shouldReceive('to')->with('/', array(), null)->andReturn('http://foo.com/');
$this->session = m::mock('Illuminate\Session\Store');
$this->redirect = new Redirector($this->url);
$this->redirect->setSession($this->session);
}
public function tearDown()
{
m::close();
}
public function testBasicRedirectTo()
{
$response = $this->redirect->to('bar');
$this->assertInstanceOf('Illuminate\Http\RedirectResponse', $response);
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals($this->session, $response->getSession());
}
public function testComplexRedirectTo()
{
$response = $this->redirect->to('bar', 303, array('X-RateLimit-Limit' => 60, 'X-RateLimit-Remaining' => 59), true);
$this->assertEquals('https://foo.com/bar', $response->getTargetUrl());
$this->assertEquals(303, $response->getStatusCode());
$this->assertEquals(60, $response->headers->get('X-RateLimit-Limit'));
$this->assertEquals(59, $response->headers->get('X-RateLimit-Remaining'));
}
public function testGuestPutCurrentUrlInSession()
{
$this->url->shouldReceive('full')->andReturn('http://foo.com/bar');
$this->session->shouldReceive('put')->once()->with('url.intended', 'http://foo.com/bar');
$response = $this->redirect->guest('login');
$this->assertEquals('http://foo.com/login', $response->getTargetUrl());
}
public function testIntendedRedirectToIntendedUrlInSession()
{
$this->session->shouldReceive('pull')->with('url.intended', '/')->andReturn('http://foo.com/bar');
$response = $this->redirect->intended();
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
}
public function testIntendedWithoutIntendedUrlInSession()
{
$this->session->shouldReceive('forget')->with('url.intended');
// without fallback url
$this->session->shouldReceive('pull')->with('url.intended', '/')->andReturn('/');
$response = $this->redirect->intended();
$this->assertEquals('http://foo.com/', $response->getTargetUrl());
// with a fallback url
$this->session->shouldReceive('pull')->with('url.intended', 'bar')->andReturn('bar');
$response = $this->redirect->intended('bar');
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
}
public function testRefreshRedirectToCurrentUrl()
{
$this->request->shouldReceive('path')->andReturn('http://foo.com/bar');
$response = $this->redirect->refresh();
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
}
public function testBackRedirectToHttpReferer()
{
$this->headers->shouldReceive('has')->with('referer')->andReturn(true);
$this->headers->shouldReceive('get')->with('referer')->andReturn('http://foo.com/bar');
$response = $this->redirect->back();
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
}
public function testAwayDoesntValidateTheUrl()
{
$response = $this->redirect->away('bar');
$this->assertEquals('bar', $response->getTargetUrl());
}
public function testSecureRedirectToHttpsUrl()
{
$response = $this->redirect->secure('bar');
$this->assertEquals('https://foo.com/bar', $response->getTargetUrl());
}
public function testAction()
{
$this->url->shouldReceive('action')->with('bar@index', array())->andReturn('http://foo.com/bar');
$response = $this->redirect->action('bar@index');
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
}
public function testRoute()
{
$this->url->shouldReceive('route')->with('home')->andReturn('http://foo.com/bar');
$this->url->shouldReceive('route')->with('home', array())->andReturn('http://foo.com/bar');
$response = $this->redirect->route('home');
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
$response = $this->redirect->home();
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
}
}