]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix supporting defaults for routes 21758/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 8 Jul 2020 16:23:06 +0000 (18:23 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 8 Jul 2020 17:52:45 +0000 (19:52 +0200)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/private/AppFramework/Routing/RouteConfig.php
tests/lib/AppFramework/Routing/RoutingTest.php

index 9a74564b6132c473c4becd1d4a98d108dcf6e4a1..1921ce651283f2daacd6c1c09ce105cef1abb1b3 100644 (file)
@@ -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]]);
                        }
                }
        }
index c078023e653271bd674e969c0f71e05f3ca17687..4712d2f30eb6f5c4cad2fb346d8a31a42901551a 100644 (file)
@@ -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;
        }