Skip to content
Permalink
Browse files

Internal cleanup and additional tests added.

  • Loading branch information...
markstory committed Jul 14, 2014
1 parent 5b40e2d commit a2a4b26abadb9a8c613e8fceab10eed2f2ca4d17
Showing with 45 additions and 8 deletions.
  1. +6 −8 src/Routing/RouteBuilder.php
  2. +39 −0 tests/TestCase/Routing/RouteBuilderTest.php
@@ -48,11 +48,11 @@ class RouteBuilder {
* @var array
*/
protected static $_resourceMap = [
'index' => ['action' => 'index', 'method' => 'GET', 'id' => false],
'create' => ['action' => 'add', 'method' => 'POST', 'id' => false],
'view' => ['action' => 'view', 'method' => 'GET', 'id' => true],
'update' => ['action' => 'edit', 'method' => ['PUT', 'PATCH'], 'id' => true],
'delete' => ['action' => 'delete', 'method' => 'DELETE', 'id' => true],
'index' => ['action' => 'index', 'method' => 'GET', 'path' => ''],
'create' => ['action' => 'add', 'method' => 'POST', 'path' => ''],
'view' => ['action' => 'view', 'method' => 'GET', 'path' => ':id'],
'update' => ['action' => 'edit', 'method' => ['PUT', 'PATCH'], 'path' => ':id'],
'delete' => ['action' => 'delete', 'method' => 'DELETE', 'path' => ':id'],
];
/**
@@ -207,7 +207,6 @@ public function resources($name, $options = [], $callback = null) {
'actions' => [],
);
$options['only'] = (array)$options['only'];
$connectOptions = $options['connectOptions'];
$urlName = Inflector::underscore($name);
@@ -227,8 +226,7 @@ public function resources($name, $options = [], $callback = null) {
$action = $options['actions'][$method];
}
$id = $params['id'] ? ':id' : '';
$url = '/' . implode('/', array_filter(array($urlName, $id)));
$url = '/' . implode('/', array_filter([$urlName, $params['path']]));
$params = array(
'controller' => $name,
'action' => $action,
@@ -257,6 +257,45 @@ public function testResources() {
$this->assertEquals('Articles', $all[0]->defaults['controller']);
}
/**
* Test resource parsing.
*
* @return void
*/
public function testResourcesParsing() {
$routes = new RouteBuilder($this->collection, '/');
$routes->resources('Articles');
$_SERVER['REQUEST_METHOD'] = 'GET';
$result = $this->collection->parse('/articles');
$this->assertEquals('Articles', $result['controller']);
$this->assertEquals('index', $result['action']);
$this->assertEquals([], $result['pass']);
$result = $this->collection->parse('/articles/1');
$this->assertEquals('Articles', $result['controller']);
$this->assertEquals('view', $result['action']);
$this->assertEquals([1], $result['pass']);
$_SERVER['REQUEST_METHOD'] = 'POST';
$result = $this->collection->parse('/articles');
$this->assertEquals('Articles', $result['controller']);
$this->assertEquals('add', $result['action']);
$this->assertEquals([], $result['pass']);
$_SERVER['REQUEST_METHOD'] = 'PUT';
$result = $this->collection->parse('/articles/1');
$this->assertEquals('Articles', $result['controller']);
$this->assertEquals('edit', $result['action']);
$this->assertEquals([1], $result['pass']);
$_SERVER['REQUEST_METHOD'] = 'DELETE';
$result = $this->collection->parse('/articles/1');
$this->assertEquals('Articles', $result['controller']);
$this->assertEquals('delete', $result['action']);
$this->assertEquals([1], $result['pass']);
}
/**
* Test the only option of RouteBuilder.
*

0 comments on commit a2a4b26

Please sign in to comment.
You can’t perform that action at this time.