Refactor authorization helper to separate some methods

Methods regarding to role hierarchi are now delegated to a parent role helper.
This commit is contained in:
2021-11-03 13:14:23 +01:00
parent 87e16ec24f
commit 6911ace412
4 changed files with 129 additions and 45 deletions

View File

@@ -0,0 +1,36 @@
<?php
namespace Chill\MainBundle\Tests\Security\Authorization;
use Chill\MainBundle\Security\ParentRoleHelper;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class ParentRoleHelperTest extends KernelTestCase
{
private ParentRoleHelper $parentRoleHelper;
public function setUp()
{
self::bootKernel();
$this->parentRoleHelper = self::$container->get(ParentRoleHelper::class);
}
public function testGetReachableRoles()
{
// this test will be valid until the role hierarchy for person is changed.
// this is not perfect but spare us a mock
$parentRoles = $this->parentRoleHelper->getParentRoles(PersonVoter::SEE);
$this->assertCount(2, $parentRoles);
$this->assertContains(PersonVoter::CREATE, $parentRoles);
$this->assertContains(PersonVoter::UPDATE, $parentRoles);
}
public function testIsRoleReached()
{
$this->assertTrue($this->parentRoleHelper->isRoleReached(PersonVoter::SEE, PersonVoter::CREATE));
$this->assertFalse($this->parentRoleHelper->isRoleReached(PersonVoter::SEE, 'foo'));
}
}