Skip to content

Commit

Permalink
Merge pull request #265 from CakeDC/feature/is-authorized-helper
Browse files Browse the repository at this point in the history
Refactoring UserHelper::link to use UserHelper::isAuthorized method
  • Loading branch information
steinkel committed Nov 12, 2015
2 parents f67a687 + 2856b2c commit 73c4225
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/View/Helper/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/View/Helper/UserHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testLinkAuthorized()
*
* @return void
*/
public function testIsAuthorizedHH()
public function testIsAuthorized()
{
$view = new View();
$eventManagerMock = $this->getMockBuilder('Cake\Event\EventManager')
Expand All @@ -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);
}


Expand Down

0 comments on commit 73c4225

Please sign in to comment.