Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Resource map accessor #391

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+45 −0
Split
@@ -175,6 +175,20 @@ public static function getNamedExpressions() {
}
/**
+ * 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.
*
* Routes are a way of connecting request urls to objects in your application. At their core routes
@@ -2455,6 +2455,37 @@ public function testPatternOnAction() {
}
/**
+ * 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
*
* @return void