[Pkg-owncloud-commits] [owncloud] 110/134: add requirements to routing
David Prévot
taffit at moszumanska.debian.org
Fri Apr 18 21:44:07 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit fc8004d335782374c5a78ed652e3b88263dd1875
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date: Wed Apr 9 21:57:32 2014 +0200
add requirements to routing
Conflicts:
tests/lib/appframework/routing/RoutingTest.php
---
lib/private/appframework/routing/routeconfig.php | 10 ++++++-
tests/lib/appframework/routing/RoutingTest.php | 33 +++++++++++++++++++++---
2 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/lib/private/appframework/routing/routeconfig.php b/lib/private/appframework/routing/routeconfig.php
index 53ab11b..19acc0c 100644
--- a/lib/private/appframework/routing/routeconfig.php
+++ b/lib/private/appframework/routing/routeconfig.php
@@ -84,7 +84,15 @@ class RouteConfig {
// register the route
$handler = new RouteActionHandler($this->container, $controllerName, $actionName);
- $this->router->create($this->appName.'.'.$controller.'.'.$action, $url)->method($verb)->action($handler);
+ $router = $this->router->create($this->appName.'.'.$controller.'.'.$action, $url)
+ ->method($verb)
+ ->action($handler);
+
+ // optionally register requirements for route. This is used to
+ // tell the route parser how url parameters should be matched
+ if(array_key_exists('requirements', $simpleRoute)) {
+ $router->requirements($simpleRoute['requirements']);
+ }
}
}
diff --git a/tests/lib/appframework/routing/RoutingTest.php b/tests/lib/appframework/routing/RoutingTest.php
index a7aa922..81a92ce 100644
--- a/tests/lib/appframework/routing/RoutingTest.php
+++ b/tests/lib/appframework/routing/RoutingTest.php
@@ -36,6 +36,16 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
$this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open');
}
+ public function testSimpleRouteWithRequirements()
+ {
+ $routes = array('routes' => array(
+ array('name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'requirements' => array('something'))
+ ));
+
+ $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', array('something'));
+ }
+
+
/**
* @expectedException \UnexpectedValueException
*/
@@ -78,10 +88,17 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
$this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'adminAccountId');
}
- private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName)
+ /**
+ * @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())
{
// route mocks
- $route = $this->mockRoute($verb, $controllerName, $actionName);
+ $route = $this->mockRoute($verb, $controllerName, $actionName, $requirements);
// router mock
$router = $this->getMock("\OC_Router", array('create'));
@@ -158,10 +175,10 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
* @param $actionName
* @return \PHPUnit_Framework_MockObject_MockObject
*/
- private function mockRoute($verb, $controllerName, $actionName)
+ private function mockRoute($verb, $controllerName, $actionName, array $requirements=array())
{
$container = new DIContainer('app1');
- $route = $this->getMock("\OC_Route", array('method', 'action'), array(), '', false);
+ $route = $this->getMock("\OC\Route", array('method', 'action', 'requirements'), array(), '', false);
$route
->expects($this->exactly(1))
->method('method')
@@ -173,6 +190,14 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
->method('action')
->with($this->equalTo(new RouteActionHandler($container, $controllerName, $actionName)))
->will($this->returnValue($route));
+
+ if(count($requirements) > 0) {
+ $route
+ ->expects($this->exactly(1))
+ ->method('requirements')
+ ->with($this->equalTo($requirements))
+ ->will($this->returnValue($route));
+ }
return $route;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list