From 66b21735663edd9d9a52259fabe48977716e83d5 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Wed, 27 Aug 2014 16:06:54 -0500 Subject: [PATCH 1/2] Made AuthComponent::mapActions() act as a getter refs #3331 --- .../Controller/Component/AuthComponent.php | 6 ++- .../Component/AuthComponentTest.php | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index 5435862f6..4eb8e7c7d 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -577,8 +577,12 @@ class AuthComponent extends Component { if (empty($this->_authorizeObjects)) { $this->constructAuthorize(); } + $mappedActions = array(); foreach ($this->_authorizeObjects as $auth) { - $auth->mapActions($map); + $mappedActions = Hash::merge($mappedActions, $auth->mapActions($map)); + } + if (empty($map)) { + return $mappedActions; } } diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index a0e8d284f..29266cf1f 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -1305,6 +1305,45 @@ class AuthComponentTest extends CakeTestCase { $this->Auth->logout(); } +/** + * Test mapActions as a getter + * + * @return void + */ + public function testMapActions() { + $MapActionMockAuthorize = $this->getMock( + 'BaseAuthorize', + array('authorize'), + array(), + '', + false + ); + $this->Auth->authorize = array('MapActionAuthorize'); + $this->Auth->setAuthorizeObject(0, $MapActionMockAuthorize); + + $actions = array('my_action' => 'create'); + $this->Auth->mapActions($actions); + $actions = array( + 'create' => array('my_other_action'), + 'update' => array('updater') + ); + $this->Auth->mapActions($actions); + + $actions = $this->Auth->mapActions(); + + $result = $actions['my_action']; + $expected = 'create'; + $this->assertEquals($expected, $result); + + $result = $actions['my_other_action']; + $expected = 'create'; + $this->assertEquals($expected, $result); + + $result = $actions['updater']; + $expected = 'update'; + $this->assertEquals($expected, $result); + } + /** * test mapActions loading and delegating to authorize objects. * From 3a41433c9463c8654e820108b6d70cf6103d2823 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Mon, 1 Sep 2014 08:52:26 -0500 Subject: [PATCH 2/2] Deprecated AuthComponent::mapActions --- lib/Cake/Controller/Component/AuthComponent.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index 4eb8e7c7d..e9792f7e5 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -572,6 +572,7 @@ class AuthComponent extends Component { * @return void * @see BaseAuthorize::mapActions() * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#mapping-actions-when-using-crudauthorize + * @deprecated 3.0.0 Map actions using `actionMap` config key on authorize objects instead */ public function mapActions($map = array()) { if (empty($this->_authorizeObjects)) {