mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Continue work on ACL rewritting
* fix center resolver dispatcher * add scope resolver * tests for authorization helper
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Tests\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\HasScopeInterface;
|
||||
use Chill\MainBundle\Entity\HasScopesInterface;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Security\Resolver\DefaultScopeResolver;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DefaultScopeResolverTest extends TestCase
|
||||
{
|
||||
private DefaultScopeResolver $scopeResolver;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->scopeResolver = new DefaultScopeResolver();
|
||||
}
|
||||
|
||||
public function testHasScopeInterface()
|
||||
{
|
||||
$scope = new Scope();
|
||||
$entity = new class($scope) implements HasScopeInterface {
|
||||
|
||||
public function __construct(Scope $scope) {
|
||||
$this->scope = $scope;
|
||||
}
|
||||
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$this->assertTrue($this->scopeResolver->supports($entity));
|
||||
$this->assertTrue($this->scopeResolver->isConcerned($entity));
|
||||
$this->assertSame($scope, $this->scopeResolver->resolveScope($entity));
|
||||
}
|
||||
|
||||
public function testHasScopesInterface()
|
||||
{
|
||||
$entity = new class($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface {
|
||||
|
||||
public function __construct(Scope $scopeA, Scope $scopeB) {
|
||||
$this->scopes = [$scopeA, $scopeB];
|
||||
}
|
||||
|
||||
public function getScopes(): iterable
|
||||
{
|
||||
return $this->scopes;
|
||||
}
|
||||
};
|
||||
|
||||
$this->assertTrue($this->scopeResolver->supports($entity));
|
||||
$this->assertTrue($this->scopeResolver->isConcerned($entity));
|
||||
$this->assertIsArray($this->scopeResolver->resolveScope($entity));
|
||||
$this->assertSame($scopeA, $this->scopeResolver->resolveScope($entity)[0]);
|
||||
$this->assertSame($scopeB, $this->scopeResolver->resolveScope($entity)[1]);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user