|
2 | 2 |
|
3 | 3 | namespace Illuminate\Tests\Support; |
4 | 4 |
|
| 5 | +use Illuminate\Contracts\Routing\UrlGenerator; |
5 | 6 | use Illuminate\Support\Uri; |
6 | 7 | use PHPUnit\Framework\TestCase; |
7 | 8 |
|
8 | 9 | class SupportUriTest extends TestCase |
9 | 10 | { |
| 11 | + public function test_can_build_special_urls() |
| 12 | + { |
| 13 | + Uri::setUrlGeneratorResolver(fn () => new CustomUrlGeneratorResolver); |
| 14 | + |
| 15 | + $this->assertEquals('https://laravel.com/to', Uri::to('')->value()); |
| 16 | + $this->assertEquals('https://laravel.com/route', Uri::route('')->value()); |
| 17 | + $this->assertEquals('https://laravel.com/signed-route', Uri::signedRoute('')->value()); |
| 18 | + $this->assertEquals('https://laravel.com/signed-route', Uri::temporarySignedRoute('', '')->value()); |
| 19 | + $this->assertEquals('https://laravel.com/action', Uri::action('')->value()); |
| 20 | + } |
| 21 | + |
10 | 22 | public function test_basic_uri_interactions() |
11 | 23 | { |
12 | 24 | $uri = Uri::of($originalUri = 'https://laravel.com/docs/installation'); |
@@ -232,3 +244,66 @@ public function test_macroable() |
232 | 244 | $this->assertSame('https://laravel.com/foobar', (string) $uri->myMacro()); |
233 | 245 | } |
234 | 246 | } |
| 247 | + |
| 248 | +class CustomUrlGeneratorResolver implements UrlGenerator |
| 249 | +{ |
| 250 | + public function current() |
| 251 | + { |
| 252 | + return 'https://laravel.com/current'; |
| 253 | + } |
| 254 | + |
| 255 | + public function previous($fallback = false) |
| 256 | + { |
| 257 | + // TODO: Implement previous() method. |
| 258 | + } |
| 259 | + |
| 260 | + public function to($path, $extra = [], $secure = null) |
| 261 | + { |
| 262 | + return 'https://laravel.com/to'; |
| 263 | + } |
| 264 | + |
| 265 | + public function secure($path, $parameters = []) |
| 266 | + { |
| 267 | + // TODO: Implement secure() method. |
| 268 | + } |
| 269 | + |
| 270 | + public function asset($path, $secure = null) |
| 271 | + { |
| 272 | + // TODO: Implement asset() method. |
| 273 | + } |
| 274 | + |
| 275 | + public function route($name, $parameters = [], $absolute = true) |
| 276 | + { |
| 277 | + return 'https://laravel.com/route'; |
| 278 | + } |
| 279 | + |
| 280 | + public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true) |
| 281 | + { |
| 282 | + return 'https://laravel.com/signed-route'; |
| 283 | + } |
| 284 | + |
| 285 | + public function temporarySignedRoute($name, $expiration, $parameters = [], $absolute = true) |
| 286 | + { |
| 287 | + return 'https://laravel.com/temporary-signed-route'; |
| 288 | + } |
| 289 | + |
| 290 | + public function query($path, $query = [], $extra = [], $secure = null) |
| 291 | + { |
| 292 | + // TODO: Implement query() method. |
| 293 | + } |
| 294 | + |
| 295 | + public function action($action, $parameters = [], $absolute = true) |
| 296 | + { |
| 297 | + return 'https://laravel.com/action'; |
| 298 | + } |
| 299 | + |
| 300 | + public function getRootControllerNamespace() |
| 301 | + { |
| 302 | + // TODO: Implement getRootControllerNamespace() method. |
| 303 | + } |
| 304 | + |
| 305 | + public function setRootControllerNamespace($rootNamespace) |
| 306 | + { |
| 307 | + // TODO: Implement setRootControllerNamespace() method. |
| 308 | + } |
| 309 | +} |
0 commit comments