From a453b7f9a2397f76f5770f26c46a1bf1a5efff60 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 2 May 2018 12:30:29 +0200 Subject: [PATCH] Create a separate test --- tests/Routing/RoutingUrlGeneratorTest.php | 30 ++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/Routing/RoutingUrlGeneratorTest.php b/tests/Routing/RoutingUrlGeneratorTest.php index 09ac0f0aec60..cc574e142488 100755 --- a/tests/Routing/RoutingUrlGeneratorTest.php +++ b/tests/Routing/RoutingUrlGeneratorTest.php @@ -59,16 +59,34 @@ public function testBasicGenerationWithFormatting() $route = new Route(['GET'], '/named-route', ['as' => 'plain']); $routes->add($route); - $url->formatPathUsing(function ($path, $route) { - if ($route) { - return '/something'.$path.'/'.$route->getName(); - } - + $url->formatPathUsing(function ($path) { return '/something'.$path; }); $this->assertEquals('http://www.foo.com/something/foo/bar', $url->to('foo/bar')); - $this->assertEquals('/something/named-route/plain', $url->route('plain', [], false)); + $this->assertEquals('/something/named-route', $url->route('plain', [], false)); + } + + public function testUrlFormattersShouldReceiveTargetRoute() + { + $url = new UrlGenerator( + $routes = new RouteCollection, + $request = Request::create('http://abc.com/') + ); + + $namedRoute = new Route(['GET'], '/bar', ['as' => 'plain', 'root' => 'bar.com', 'path' => 'foo']); + $routes->add($namedRoute); + + $url->formatHostUsing(function ($root, $route) { + return $route ? 'http://'.$route->getAction('root') : $root; + }); + + $url->formatPathUsing(function ($path, $route) { + return $route ? '/'.$route->getAction('path') : $path; + }); + + $this->assertEquals('http://abc.com/foo/bar', $url->to('foo/bar')); + $this->assertEquals('http://bar.com/foo', $url->route('plain')); } public function testBasicRouteGeneration()