Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
70c88027
Commit
70c88027
authored
11 years ago
by
Bernhard Posselt
Browse files
Options
Downloads
Patches
Plain Diff
add requirements to routing
parent
5b8c7a01
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/private/appframework/routing/routeconfig.php
+9
-1
9 additions, 1 deletion
lib/private/appframework/routing/routeconfig.php
tests/lib/appframework/routing/RoutingTest.php
+22
-4
22 additions, 4 deletions
tests/lib/appframework/routing/RoutingTest.php
with
31 additions
and
5 deletions
lib/private/appframework/routing/routeconfig.php
+
9
−
1
View file @
70c88027
...
...
@@ -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'
]);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/lib/appframework/routing/RoutingTest.php
+
22
−
4
View file @
70c88027
...
...
@@ -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
*/
...
...
@@ -85,10 +95,10 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
* @param string $controllerName
* @param string $actionName
*/
private
function
assertSimpleRoute
(
$routes
,
$name
,
$verb
,
$url
,
$controllerName
,
$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\Route\Router"
,
array
(
'create'
));
...
...
@@ -171,10 +181,10 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
* @param string $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\Route"
,
array
(
'method'
,
'action'
),
array
(),
''
,
false
);
$route
=
$this
->
getMock
(
"\OC\Route\Route"
,
array
(
'method'
,
'action'
,
'requirements'
),
array
(),
''
,
false
);
$route
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'method'
)
...
...
@@ -186,6 +196,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
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment