use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\Routing\RouteActionHandler;
use OC\AppFramework\Routing\RouteConfig;
+use OC\Route\Route;
use OC\Route\Router;
use OCP\ILogger;
use OCP\Route\IRouter;
['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'GET']
]];
- $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/folders/{folderId}/open', 'FoldersController', 'open');
+ $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
+ }
+
+ public function testSimpleRouteWithUnderScoreNames() {
+ $routes = ['routes' => [
+ ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'root' => '']
+ ]];
+
+ $this->assertSimpleRoute($routes, 'admin_folders.open_current', 'DELETE', '/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent', [], [], '', true);
}
public function testSimpleOCSRoute() {
['name' => 'folders#open', 'url' => '/folders/{folderId}/open']
]];
- $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/folders/{folderId}/open', 'FoldersController', 'open');
+ $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
}
public function testSimpleOCSRouteWithMissingVerb() {
['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
]];
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open');
+ $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
}
public function testSimpleOCSRouteWithLowercaseVerb() {
['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'requirements' => ['something']]
]];
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
+ $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
}
public function testSimpleOCSRouteWithRequirements() {
['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', [], 'defaults' => ['param' => 'foobar']]
]];
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
+ $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
}
['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'postfix' => '_something']
]];
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
+ $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
}
public function testSimpleOCSRouteWithPostfix() {
$this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
}
-
+
public function testSimpleRouteWithBrokenName() {
$this->expectException(\UnexpectedValueException::class);
['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
]];
- // router mock
- $router = $this->getMockBuilder('\OC\Route\Router')
- ->setMethods(['create'])
- ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()])
+ /** @var IRouter|MockObject $router */
+ $router = $this->getMockBuilder(Router::class)
+ ->onlyMethods(['create'])
+ ->setConstructorArgs([$this->createMock(ILogger::class)])
->getMock();
// load route configuration
$config->register();
}
-
+
public function testSimpleOCSRouteWithBrokenName() {
$this->expectException(\UnexpectedValueException::class);
['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
]];
- // router mock
- $router = $this->getMockBuilder('\OC\Route\Router')
- ->setMethods(['create'])
- ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()])
+ /** @var IRouter|MockObject $router */
+ $router = $this->getMockBuilder(Router::class)
+ ->onlyMethods(['create'])
+ ->setConstructorArgs([$this->createMock(ILogger::class)])
->getMock();
// load route configuration
$config->register();
}
- public function testSimpleRouteWithUnderScoreNames() {
- $routes = ['routes' => [
- ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- $this->assertSimpleRoute($routes, 'admin_folders.open_current', 'DELETE', '/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent');
- }
-
public function testSimpleOCSRouteWithUnderScoreNames() {
$routes = ['ocs' => [
['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
$this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'id');
}
- /**
- * @param string $name
- * @param string $verb
- * @param string $url
- * @param string $controllerName
- * @param string $actionName
- */
- private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements=[], array $defaults=[], $postfix='') {
+ private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements = [], array $defaults = [], $postfix = '', $allowRootUrl = false): void {
if ($postfix) {
$name .= $postfix;
}
$container = new DIContainer('app1');
$route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
- // router mock
- $router = $this->getMockBuilder('\OC\Route\Router')
- ->setMethods(['create'])
- ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()])
+ /** @var IRouter|MockObject $router */
+ $router = $this->getMockBuilder(Router::class)
+ ->onlyMethods(['create'])
+ ->setConstructorArgs([$this->createMock(ILogger::class)])
->getMock();
// we expect create to be called once:
// load route configuration
$config = new RouteConfig($container, $router, $routes);
+ if ($allowRootUrl) {
+ self::invokePrivate($config, 'rootUrlApps', [['app1']]);
+ }
$config->register();
}
$container = new DIContainer('app1');
$route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
- // router mock
- $router = $this->getMockBuilder('\OC\Route\Router')
- ->setMethods(['create'])
- ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()])
+ /** @var IRouter|MockObject $router */
+ $router = $this->getMockBuilder(Router::class)
+ ->onlyMethods(['create'])
+ ->setConstructorArgs([$this->createMock(ILogger::class)])
->getMock();
// we expect create to be called once:
private function assertOCSResource($yaml, $resourceName, $url, $controllerName, $paramName): void {
/** @var IRouter|MockObject $router */
$router = $this->getMockBuilder(Router::class)
- ->setMethods(['create'])
- ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()])
+ ->onlyMethods(['create'])
+ ->setConstructorArgs([$this->createMock(ILogger::class)])
->getMock();
// route mocks
* @param string $paramName
*/
private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName) {
- // router mock
- $router = $this->getMockBuilder('\OC\Route\Router')
- ->setMethods(['create'])
- ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()])
+ /** @var IRouter|MockObject $router */
+ $router = $this->getMockBuilder(Router::class)
+ ->onlyMethods(['create'])
+ ->setConstructorArgs([$this->createMock(ILogger::class)])
->getMock();
// route mocks
* @param string $actionName
* @param array $requirements
* @param array $defaults
- * @return \PHPUnit_Framework_MockObject_MockObject
+ * @return MockObject
*/
private function mockRoute(
DIContainer $container,
array $requirements=[],
array $defaults=[]
) {
- $route = $this->getMockBuilder('\OC\Route\Route')
- ->setMethods(['method', 'action', 'requirements', 'defaults'])
+ $route = $this->getMockBuilder(Route::class)
+ ->onlyMethods(['method', 'action', 'requirements', 'defaults'])
->disableOriginalConstructor()
->getMock();
$route
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('method')
->with($this->equalTo($verb))
->willReturn($route);
$route
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('action')
->with($this->equalTo(new RouteActionHandler($container, $controllerName, $actionName)))
->willReturn($route);
if (count($requirements) > 0) {
$route
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('requirements')
->with($this->equalTo($requirements))
->willReturn($route);
if (count($defaults) > 0) {
$route
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('defaults')
->with($this->equalTo($defaults))
->willReturn($route);
return $route;
}
}
-
-/*
-#
-# sample routes.yaml for ownCloud
-#
-# the section simple describes one route
-
-routes:
- - name: folders#open
- url: /folders/{folderId}/open
- verb: GET
- # controller: name.split()[0]
- # action: name.split()[1]
-
-# for a resource following actions will be generated:
-# - index
-# - create
-# - show
-# - update
-# - destroy
-# - new
-resources:
- accounts:
- url: /accounts
-
- folders:
- url: /accounts/{accountId}/folders
- # actions can be used to define additional actions on the resource
- actions:
- - name: validate
- verb: GET
- on-collection: false
-
- * */