Julien Fastré 6911ace412 Refactor authorization helper to separate some methods
Methods regarding to role hierarchi are now delegated to a parent role helper.
2021-11-03 15:35:38 +01:00

37 lines
1.2 KiB
PHP

<?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'));
}
}