mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
* fix center resolver dispatcher * add scope resolver * tests for authorization helper
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?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]);
|
|
}
|
|
|
|
}
|