Merge pull request #392 from vesln/resource-map

Resource map
This commit is contained in:
Mark Story 2012-01-02 05:23:30 -08:00
commit 81d7ef46c5
2 changed files with 45 additions and 0 deletions

View file

@ -174,6 +174,20 @@ class Router {
return self::$_namedExpressions;
}
/**
* Resource map getter & setter.
*
* @param array $resourceMap Resource map
* @return mixed
* @see Router::$_resourceMap
*/
public static function resourceMap($resourceMap = null) {
if ($resourceMap === null) {
return self::$_resourceMap;
}
self::$_resourceMap = $resourceMap;
}
/**
* Connects a new Route in the router.
*

View file

@ -2454,6 +2454,37 @@ class RouterTest extends CakeTestCase {
$this->assertFalse($result);
}
/**
* Tests resourceMap as getter and setter.
*
* @return void
*/
public function testResourceMap() {
$default = Router::resourceMap();
$exepcted = array(
array('action' => 'index', 'method' => 'GET', 'id' => false),
array('action' => 'view', 'method' => 'GET', 'id' => true),
array('action' => 'add', 'method' => 'POST', 'id' => false),
array('action' => 'edit', 'method' => 'PUT', 'id' => true),
array('action' => 'delete', 'method' => 'DELETE', 'id' => true),
array('action' => 'edit', 'method' => 'POST', 'id' => true)
);
$this->assertEquals($default, $exepcted);
$custom = array(
array('action' => 'index', 'method' => 'GET', 'id' => false),
array('action' => 'view', 'method' => 'GET', 'id' => true),
array('action' => 'add', 'method' => 'POST', 'id' => false),
array('action' => 'edit', 'method' => 'PUT', 'id' => true),
array('action' => 'delete', 'method' => 'DELETE', 'id' => true),
array('action' => 'update', 'method' => 'POST', 'id' => true)
);
Router::resourceMap($custom);
$this->assertEquals($custom, Router::resourceMap());
Router::resourceMap($default);
}
/**
* test setting redirect routes
*