forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoutingUrlGeneratorTest.php
More file actions
executable file
·208 lines (163 loc) · 7.19 KB
/
RoutingUrlGeneratorTest.php
File metadata and controls
executable file
·208 lines (163 loc) · 7.19 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
use Illuminate\Routing\UrlGenerator;
class RoutingUrlGeneratorTest extends PHPUnit_Framework_TestCase {
public function testBasicGeneration()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('http://www.foo.com/')
);
$this->assertEquals('http://www.foo.com/foo/bar', $url->to('foo/bar'));
$this->assertEquals('https://www.foo.com/foo/bar', $url->to('foo/bar', array(), true));
$this->assertEquals('https://www.foo.com/foo/bar/baz/boom', $url->to('foo/bar', array('baz', 'boom'), true));
/**
* Test HTTPS request URL generation...
*/
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('https://www.foo.com/')
);
$this->assertEquals('https://www.foo.com/foo/bar', $url->to('foo/bar'));
/**
* Test asset URL generation...
*/
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('http://www.foo.com/index.php/')
);
$this->assertEquals('http://www.foo.com/foo/bar', $url->asset('foo/bar'));
$this->assertEquals('https://www.foo.com/foo/bar', $url->asset('foo/bar', true));
}
public function testBasicRouteGeneration()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('http://www.foo.com/')
);
/**
* Empty Named Route
*/
$route = new Illuminate\Routing\Route(array('GET'), '/', array('as' => 'plain'));
$routes->add($route);
/**
* Named Routes
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('as' => 'foo'));
$routes->add($route);
/**
* Parameters...
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar/{baz}/breeze/{boom}', array('as' => 'bar'));
$routes->add($route);
/**
* HTTPS...
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('as' => 'baz', 'https'));
$routes->add($route);
/**
* Controller Route Route
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('controller' => 'foo@bar'));
$routes->add($route);
/**
* Non ASCII routes
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar/åαф/{baz}', array('as' => 'foobarbaz'));
$routes->add($route);
$this->assertEquals('/', $url->route('plain', array(), false));
$this->assertEquals('/?foo=bar', $url->route('plain', array('foo' => 'bar'), false));
$this->assertEquals('http://www.foo.com/foo/bar', $url->route('foo'));
$this->assertEquals('/foo/bar', $url->route('foo', array(), false));
$this->assertEquals('/foo/bar?foo=bar', $url->route('foo', array('foo' => 'bar'), false));
$this->assertEquals('http://www.foo.com/foo/bar/taylor/breeze/otwell?fly=wall', $url->route('bar', array('taylor', 'otwell', 'fly' => 'wall')));
$this->assertEquals('http://www.foo.com/foo/bar/otwell/breeze/taylor?fly=wall', $url->route('bar', array('boom' => 'taylor', 'baz' => 'otwell', 'fly' => 'wall')));
$this->assertEquals('/foo/bar/taylor/breeze/otwell?fly=wall', $url->route('bar', array('taylor', 'otwell', 'fly' => 'wall'), false));
$this->assertEquals('https://www.foo.com/foo/bar', $url->route('baz'));
$this->assertEquals('http://www.foo.com/foo/bar', $url->action('foo@bar'));
$this->assertEquals('http://www.foo.com/foo/bar/taylor/breeze/otwell?wall&woz', $url->route('bar', array('wall', 'woz', 'boom' => 'otwell', 'baz' => 'taylor')));
$this->assertEquals('http://www.foo.com/foo/bar/taylor/breeze/otwell?wall&woz', $url->route('bar', array('taylor', 'otwell', 'wall', 'woz')));
$this->assertEquals('http://www.foo.com/foo/bar/%C3%A5%CE%B1%D1%84/%C3%A5%CE%B1%D1%84', $url->route('foobarbaz', array('baz' => 'åαф')));
}
public function testRoutesMaintainRequestScheme()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('https://www.foo.com/')
);
/**
* Named Routes
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('as' => 'foo'));
$routes->add($route);
$this->assertEquals('https://www.foo.com/foo/bar', $url->route('foo'));
}
public function testHttpOnlyRoutes()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('https://www.foo.com/')
);
/**
* Named Routes
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('as' => 'foo', 'http'));
$routes->add($route);
$this->assertEquals('http://www.foo.com/foo/bar', $url->route('foo'));
}
public function testRoutesWithDomains()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('http://www.foo.com/')
);
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('as' => 'foo', 'domain' => 'sub.foo.com'));
$routes->add($route);
/**
* Wildcards & Domains...
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar/{baz}', array('as' => 'bar', 'domain' => 'sub.{foo}.com'));
$routes->add($route);
$this->assertEquals('http://sub.foo.com/foo/bar', $url->route('foo'));
$this->assertEquals('http://sub.taylor.com/foo/bar/otwell', $url->route('bar', array('taylor', 'otwell')));
$this->assertEquals('/foo/bar/otwell', $url->route('bar', array('taylor', 'otwell'), false));
}
public function testRoutesWithDomainsAndPorts()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('http://www.foo.com:8080/')
);
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('as' => 'foo', 'domain' => 'sub.foo.com'));
$routes->add($route);
/**
* Wildcards & Domains...
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar/{baz}', array('as' => 'bar', 'domain' => 'sub.{foo}.com'));
$routes->add($route);
$this->assertEquals('http://sub.foo.com:8080/foo/bar', $url->route('foo'));
$this->assertEquals('http://sub.taylor.com:8080/foo/bar/otwell', $url->route('bar', array('taylor', 'otwell')));
}
public function testHttpsRoutesWithDomains()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('https://foo.com/')
);
/**
* When on HTTPS, no need to specify 443
*/
$route = new Illuminate\Routing\Route(array('GET'), 'foo/bar', array('as' => 'baz', 'domain' => 'sub.foo.com'));
$routes->add($route);
$this->assertEquals('https://sub.foo.com/foo/bar', $url->route('baz'));
}
public function testUrlGenerationForControllers()
{
$url = new UrlGenerator(
$routes = new Illuminate\Routing\RouteCollection,
$request = Illuminate\Http\Request::create('http://www.foo.com:8080/')
);
$route = new Illuminate\Routing\Route(array('GET'), 'foo/{one}/{two?}/{three?}', array('as' => 'foo', function() {}));
$routes->add($route);
$this->assertEquals('http://www.foo.com:8080/foo', $url->route('foo'));
}
}