/** * @param string $resourceName * @param string $url * @param string $controllerName * @param string $paramName */ private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName) { // router mock $router = $this->getMock("\\OC\\Route\\Router", array('create'), [\OC::$server->getLogger()]); // route mocks $container = new DIContainer('app1'); $indexRoute = $this->mockRoute($container, 'GET', $controllerName, 'index'); $showRoute = $this->mockRoute($container, 'GET', $controllerName, 'show'); $createRoute = $this->mockRoute($container, 'POST', $controllerName, 'create'); $updateRoute = $this->mockRoute($container, 'PUT', $controllerName, 'update'); $destroyRoute = $this->mockRoute($container, 'DELETE', $controllerName, 'destroy'); $urlWithParam = $url . '/{' . $paramName . '}'; // we expect create to be called once: $router->expects($this->at(0))->method('create')->with($this->equalTo('app1.' . $resourceName . '.index'), $this->equalTo($url))->will($this->returnValue($indexRoute)); $router->expects($this->at(1))->method('create')->with($this->equalTo('app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam))->will($this->returnValue($showRoute)); $router->expects($this->at(2))->method('create')->with($this->equalTo('app1.' . $resourceName . '.create'), $this->equalTo($url))->will($this->returnValue($createRoute)); $router->expects($this->at(3))->method('create')->with($this->equalTo('app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam))->will($this->returnValue($updateRoute)); $router->expects($this->at(4))->method('create')->with($this->equalTo('app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam))->will($this->returnValue($destroyRoute)); // load route configuration $config = new RouteConfig($container, $router, $yaml); $config->register(); }
/** * This function is to be called to create single routes and restful routes based on the given $routes array. * * Example code in routes.php of tasks app (it will register two restful resources): * $routes = array( * 'resources' => array( * 'lists' => array('url' => '/tasklists'), * 'tasks' => array('url' => '/tasklists/{listId}/tasks') * ) * ); * * $a = new TasksApp(); * $a->registerRoutes($this, $routes); * * @param \OCP\Route\IRouter $router * @param array $routes * @since 6.0.0 */ public function registerRoutes($router, $routes) { $routeConfig = new RouteConfig($this->container, $router, $routes); $routeConfig->register(); }