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
·147 lines (107 loc) · 5.03 KB
/
RoutingUrlGeneratorTest.php
File metadata and controls
executable file
·147 lines (107 loc) · 5.03 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
<?php
use Mockery as m;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Routing\UrlGenerator;
class RoutingUrlGeneratorTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testBasicUrlGeneration()
{
$gen = $this->getGenerator();
$gen->setRequest(Request::create('http://foobar.com/foo/bar', 'GET'));
$this->assertEquals('http://foobar.com', $gen->to('/'));
$this->assertEquals('http://foobar.com/something', $gen->to('/something'));
$this->assertEquals('http://foobar.com/something', $gen->to('something'));
$this->assertEquals('https://foobar.com', $gen->secure('/'));
$this->assertEquals('https://foobar.com/something', $gen->secure('/something'));
$this->assertEquals('https://foobar.com/something', $gen->secure('something'));
$this->assertEquals('http://foobar.com/dayle/rees', $gen->to('/', array('dayle', 'rees')));
$this->assertEquals('http://foobar.com/dayle/rees', $gen->to(null, array('dayle', 'rees')));
$this->assertEquals('http://foobar.com/something/dayle/rees', $gen->to('/something', array('dayle', 'rees')));
$this->assertEquals('http://foobar.com/something/dayle/rees', $gen->to('something', array('dayle', 'rees')));
}
public function testUrlGenerationUsesCurrentProtocol()
{
$gen = $this->getGenerator();
$gen->setRequest(Request::create('https://foobar.com/foo/bar', 'GET'));
$this->assertEquals('https://foobar.com/something', $gen->to('something'));
$this->assertEquals('http://foobar.com/something', $gen->to('something', array(), false));
}
public function testAssetUrlGeneration()
{
$gen = $this->getGenerator();
$gen->setRequest(Request::create('http://foobar.com/index.php/foo/bar', 'GET'));
$this->assertEquals('http://foobar.com/', $gen->asset('/'));
$this->assertEquals('http://foobar.com/something', $gen->asset('something'));
$this->assertEquals('https://foobar.com/something', $gen->secureAsset('something'));
}
public function testRouteUrlGeneration()
{
$gen = $this->getGenerator();
$symfonyGen = m::mock('Symfony\Component\Routing\Generator\UrlGenerator');
$symfonyGen->shouldReceive('generate')->once()->with('foo.bar', array('name' => 'taylor'), true);
$gen->setRequest(Request::create('http://foobar.com', 'GET'));
$gen->setGenerator($symfonyGen);
$gen->route('foo.bar', array('name' => 'taylor'));
}
public function testRouteUrlGenerationWithOptional()
{
$gen = $this->getGenerator();
$symfonyGen = m::mock('Symfony\Component\Routing\Generator\UrlGenerator');
$symfonyGen->shouldReceive('generate')->once()->with('foo.boom', array(), true);
$gen->setRequest(Request::create('http://foobar.com', 'GET'));
$gen->setGenerator($symfonyGen);
$gen->route('foo.boom', array());
}
public function testRouteParametersCanBeShortCircuited()
{
$gen = $this->getGenerator();
$symfonyGen = m::mock('Symfony\Component\Routing\Generator\UrlGenerator');
$symfonyGen->shouldReceive('generate')->once()->with('foo.baz', array('name' => 'taylor', 'age' => 25), true);
$gen->setRequest(Request::create('http://foobar.com', 'GET'));
$gen->setGenerator($symfonyGen);
$gen->route('foo.baz', array('taylor', 25));
}
public function testRouteParametersCanBeShortCircuitedWithOptionals()
{
$gen = $this->getGenerator();
$symfonyGen = m::mock('Symfony\Component\Routing\Generator\UrlGenerator');
$symfonyGen->shouldReceive('generate')->once()->with('foo.breeze', array('boom' => 'bar', 'breeze' => null), true);
$gen->setRequest(Request::create('http://foobar.com', 'GET'));
$gen->setGenerator($symfonyGen);
$gen->route('foo.breeze', array('bar'));
}
public function testRoutesToControllerAreGenerated()
{
$gen = $this->getGenerator();
$gen->setRequest(Request::create('http://foobar.com', 'GET'));
$this->assertEquals('http://foobar.com/boom/baz/taylor', $gen->action('FooController@fooAction', array('name' => 'taylor')));
$this->assertEquals('http://foobar.com/boom/baz/taylor', $gen->action('FooController@fooAction', array('name' => 'taylor')));
}
public function testWellFormedUrlIsReturnedUnchanged()
{
$gen = $this->getGenerator();
$this->assertEquals('http://google.com', $gen->to('http://google.com'));
}
public function testUrlGeneratorUsesCurrentSchemeIfNoneSpecified()
{
$router = new Router;
$router->get('/', array('as' => 'home', function() {}));
$request = Request::create('https://dayle.com');
$gen = new UrlGenerator($router->getRoutes(), $request);
$this->assertEquals('https://dayle.com/', $gen->route('home'));
}
protected function getGenerator()
{
$router = new Router;
$router->get('foo/bar/{name}', array('as' => 'foo.bar', function() {}));
$router->get('foo/bar/{name}/baz/{age}', array('as' => 'foo.baz', function() {}));
$router->get('foo/{boom?}', array('as' => 'foo.boom', function() {}));
$router->get('foo/{boom?}/{breeze?}', array('as' => 'foo.breeze', function() {}));
$router->get('/boom/baz/{name}', array('uses' => 'FooController@fooAction'));
return new UrlGenerator($router->getRoutes(), Request::create('/'));
}
}