mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
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:
@@ -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'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user