Skip to content
Snippets Groups Projects
Commit 9ee1c7ff authored by Morris Jobke's avatar Morris Jobke
Browse files

Merge pull request #9228 from owncloud/remove-routing-singular-issues

Routing: Dont strip the s from the resource id to prevent possible weird behavior with irregular english plural nouns
parents 4b917418 2662c4c6
No related branches found
No related tags found
No related merge requests found
......@@ -88,7 +88,7 @@ class RouteConfig {
->method($verb)
->action($handler);
// optionally register requirements for route. This is used to
// 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']);
......@@ -122,14 +122,13 @@ class RouteConfig {
foreach ($resources as $resource => $config) {
// the url parameter used as id to the resource
$resourceId = $this->buildResourceId($resource);
foreach($actions as $action) {
$url = $config['url'];
$method = $action['name'];
$verb = isset($action['verb']) ? strtoupper($action['verb']) : 'GET';
$collectionAction = isset($action['on-collection']) ? $action['on-collection'] : false;
if (!$collectionAction) {
$url = $url . '/' . $resourceId;
$url = $url . '/{id}';
}
if (isset($action['url-postfix'])) {
$url = $url . '/' . $action['url-postfix'];
......@@ -168,15 +167,6 @@ class RouteConfig {
return $this->underScoreToCamelCase($action);
}
/**
* Generates the id used in the url part o the route url
* @param string $resource
* @return string
*/
private function buildResourceId($resource) {
return '{'.$this->underScoreToCamelCase(rtrim($resource, 's')).'Id}';
}
/**
* Underscored strings are converted to camel case strings
* @param string $str
......
......@@ -6,7 +6,7 @@ use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\routing\RouteConfig;
class RouteConfigTest extends \PHPUnit_Framework_TestCase
class RoutingTest extends \PHPUnit_Framework_TestCase
{
public function testSimpleRoute()
......@@ -76,16 +76,16 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
public function testResource()
{
$routes = array('resources' => array('accounts' => array('url' => '/accounts')));
$routes = array('resources' => array('account' => array('url' => '/accounts')));
$this->assertResource($routes, 'accounts', '/accounts', 'AccountsController', 'accountId');
$this->assertResource($routes, 'account', '/accounts', 'AccountController', 'id');
}
public function testResourceWithUnderScoreName()
{
$routes = array('resources' => array('admin_accounts' => array('url' => '/admin/accounts')));
$this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'adminAccountId');
$this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'id');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment