Skip to content

Commit

Permalink
Pass a single role to isGranted
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and greg0ire committed Mar 16, 2020
1 parent 45a0373 commit 53908d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Menu/Provider/GroupMenuProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private function canGenerateMenuItem(array $item, array $group): bool
if (!empty($item['roles'])) {
$isItemGranted = false;
foreach ($item['roles'] as $role) {
if ($this->checker->isGranted([$role])) {
if ($this->checker->isGranted($role)) {
$isItemGranted = true;
break;
}
Expand All @@ -157,7 +157,7 @@ private function canGenerateMenuItem(array $item, array $group): bool
if (!empty($group['roles'])) {
$isGroupGranted = false;
foreach ($group['roles'] as $role) {
if ($this->checker->isGranted([$role])) {
if ($this->checker->isGranted($role)) {
$isGroupGranted = true;
break;
}
Expand Down
24 changes: 4 additions & 20 deletions tests/Menu/Provider/GroupMenuProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,14 @@ public function testGetMenuProviderWithCheckerGrantedGroupRoles(array $adminGrou
$this->assertSame($extras['label_catalogue'], 'SonataAdminBundle');
}

public function unanimousGrantCheckerMock(array $args): bool
public function unanimousGrantCheckerMock(string $role): bool
{
if ($args === ['foo', 'bar']) {
return false;
}

if ($args === ['foo'] || $args === ['bar'] || $args === ['baz']) {
return true;
}

return false;
return \in_array($role, ['foo', 'bar', 'baz'], true);
}

public function unanimousGrantCheckerNoBazMock(array $args): bool
public function unanimousGrantCheckerNoBazMock(string $role): bool
{
if ($args === ['foo', 'bar'] || $args === ['baz']) {
return false;
}

if ($args === ['foo'] || $args === ['bar']) {
return true;
}

return false;
return \in_array($role, ['foo', 'bar'], true);
}

/**
Expand Down

0 comments on commit 53908d4

Please sign in to comment.