From 2856b2cdcddb42034cd56edf266c1c77c90417ac Mon Sep 17 00:00:00 2001 From: Yelitza Parra Date: Mon, 9 Nov 2015 17:49:04 -0430 Subject: [PATCH] Refactoring UserHelper::link to use UserHelper::isAuthorized method --- src/View/Helper/UserHelper.php | 4 +--- tests/TestCase/View/Helper/UserHelperTest.php | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/View/Helper/UserHelper.php b/src/View/Helper/UserHelper.php index 0cb5dc7af..1263837bc 100644 --- a/src/View/Helper/UserHelper.php +++ b/src/View/Helper/UserHelper.php @@ -97,9 +97,7 @@ public function logout($message = null, $options = []) */ public function link($title, $url = null, array $options = []) { - $event = new Event(UsersAuthComponent::EVENT_IS_AUTHORIZED, $this, ['url' => $url]); - $result = $this->_View->eventManager()->dispatch($event); - if ($result->result) { + if ($this->isAuthorized($url)) { $linkOptions = $options; unset($linkOptions['before'], $linkOptions['after']); return Hash::get($options, 'before') . $this->Html->link($title, $url, $linkOptions) . Hash::get($options, 'after'); diff --git a/tests/TestCase/View/Helper/UserHelperTest.php b/tests/TestCase/View/Helper/UserHelperTest.php index bbdad73a3..6c29af869 100644 --- a/tests/TestCase/View/Helper/UserHelperTest.php +++ b/tests/TestCase/View/Helper/UserHelperTest.php @@ -153,7 +153,7 @@ public function testLinkAuthorized() * * @return void */ - public function testIsAuthorizedHH() + public function testIsAuthorized() { $view = new View(); $eventManagerMock = $this->getMockBuilder('Cake\Event\EventManager') @@ -167,8 +167,8 @@ public function testIsAuthorizedHH() ->method('dispatch') ->will($this->returnValue($result)); - $link = $this->User->isAuthorized(['controller' => 'MyController', 'action' => 'myAction']); - $this->assertTrue($link); + $result = $this->User->isAuthorized(['controller' => 'MyController', 'action' => 'myAction']); + $this->assertTrue($result); }