From 3f447b9c8c52c371aee52a51dfcbeb2e91a85992 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 8 Jul 2020 18:23:06 +0200 Subject: [PATCH] Fix supporting defaults for routes Signed-off-by: Roeland Jago Douma --- .../AppFramework/Routing/RouteConfig.php | 16 ++++++++----- .../lib/AppFramework/Routing/RoutingTest.php | 24 ++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/private/AppFramework/Routing/RouteConfig.php b/lib/private/AppFramework/Routing/RouteConfig.php index 9a74564b61..1921ce6512 100644 --- a/lib/private/AppFramework/Routing/RouteConfig.php +++ b/lib/private/AppFramework/Routing/RouteConfig.php @@ -141,8 +141,7 @@ class RouteConfig { $routeName = $routeNamePrefix . $this->appName . '.' . $controller . '.' . $action . $postfix; $router = $this->router->create($routeName, $url) - ->method($verb) - ->setDefault('caller', [$this->appName, $controllerName, $actionName]); + ->method($verb); // optionally register requirements for route. This is used to // tell the route parser how url parameters should be matched @@ -152,9 +151,13 @@ class RouteConfig { // optionally register defaults for route. This is used to // tell the route parser how url parameters should be default valued + $defaults = []; if (array_key_exists('defaults', $route)) { - $router->defaults($route['defaults']); + $defaults = $route['defaults']; } + + $defaults['caller'] = [$this->appName, $controllerName, $actionName]; + $router->defaults($defaults); } /** @@ -230,9 +233,10 @@ class RouteConfig { $routeName = $routeNamePrefix . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); - $this->router->create($routeName, $url) - ->method($verb) - ->setDefault('caller', [$this->appName, $controllerName, $actionName]); + $route = $this->router->create($routeName, $url) + ->method($verb); + + $route->defaults(['caller' => [$this->appName, $controllerName, $actionName]]); } } } diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php index c078023e65..4712d2f30e 100644 --- a/tests/lib/AppFramework/Routing/RoutingTest.php +++ b/tests/lib/AppFramework/Routing/RoutingTest.php @@ -419,7 +419,7 @@ class RoutingTest extends \Test\TestCase { array $defaults=[] ) { $route = $this->getMockBuilder(Route::class) - ->onlyMethods(['method', 'setDefault', 'requirements', 'defaults']) + ->onlyMethods(['method', 'requirements', 'defaults']) ->disableOriginalConstructor() ->getMock(); $route @@ -428,12 +428,6 @@ class RoutingTest extends \Test\TestCase { ->with($this->equalTo($verb)) ->willReturn($route); - $route - ->expects($this->once()) - ->method('setDefault') - ->with('caller', ['app1', $controllerName, $actionName]) - ->willReturn($route); - if (count($requirements) > 0) { $route ->expects($this->once()) @@ -442,13 +436,15 @@ class RoutingTest extends \Test\TestCase { ->willReturn($route); } - if (count($defaults) > 0) { - $route - ->expects($this->once()) - ->method('defaults') - ->with($this->equalTo($defaults)) - ->willReturn($route); - } + $route->expects($this->once()) + ->method('defaults') + ->with($this->callback(function (array $def) use ($defaults, $controllerName, $actionName) { + $defaults['caller'] = ['app1', $controllerName, $actionName]; + + $this->assertEquals($defaults, $def); + return true; + })) + ->willReturn($route); return $route; }