|
|
@@ -6,20 +6,25 @@ use App\ApiResources\Profile\OrganizationProfile;
|
|
|
use App\Entity\Access\Access;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Person\Person;
|
|
|
+use App\Repository\Access\AccessRepository;
|
|
|
use App\Service\Access\AccessProfileCreator;
|
|
|
+use App\Service\Access\Utils;
|
|
|
use App\Service\Organization\OrganizationProfileCreator;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
|
|
use Symfony\Component\Security\Core\Role\RoleHierarchy;
|
|
|
|
|
|
class AccessProfileCreatorTest extends TestCase
|
|
|
{
|
|
|
private Access $access;
|
|
|
- private Person $person;
|
|
|
+ private $accessProfileCreator;
|
|
|
+ private $accessRepositoryMock;
|
|
|
+ private $accessUtilsMock;
|
|
|
|
|
|
public function setUp():void
|
|
|
{
|
|
|
- $this->person = new Person();
|
|
|
- $this->person
|
|
|
+ $person = new Person();
|
|
|
+ $person
|
|
|
->setName('Foo')
|
|
|
->setGivenName('Bar')
|
|
|
;
|
|
|
@@ -27,29 +32,57 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
$this->access = new Access();
|
|
|
$this->access
|
|
|
->setAdminAccess(true)
|
|
|
- ->setPerson($this->person)
|
|
|
+ ->setPerson($person)
|
|
|
->setOrganization(new Organization())
|
|
|
;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * @see AccessProfileCreator::getAccessProfile()
|
|
|
- */
|
|
|
- public function testGetAccessProfile(){
|
|
|
$roleHierarchyMock = $this->getMockBuilder(RoleHierarchy::class)->disableOriginalConstructor()->getMock();
|
|
|
$roleHierarchyMock
|
|
|
->method('getReachableRoleNames')
|
|
|
->willReturn(["ROLE_A", "ROLE_B"]);
|
|
|
|
|
|
- $organizationProfileCreator = $this->getMockBuilder(OrganizationProfileCreator::class)->disableOriginalConstructor()->getMock();
|
|
|
- $organizationProfileCreator
|
|
|
+ $organizationProfileCreatorMock = $this->getMockBuilder(OrganizationProfileCreator::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $organizationProfileCreatorMock
|
|
|
->method('getOrganizationProfile')
|
|
|
->with($this->access->getOrganization())
|
|
|
->willReturn(new OrganizationProfile());
|
|
|
|
|
|
- $accessProfileCreator = new AccessProfileCreator($roleHierarchyMock,$organizationProfileCreator);
|
|
|
- $accessProfile = $accessProfileCreator->getAccessProfile($this->access);
|
|
|
+ $this->accessRepositoryMock = $this->getMockBuilder(AccessRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->accessUtilsMock = $this->getMockBuilder(Utils::class)->disableOriginalConstructor()->getMock();
|
|
|
+
|
|
|
+ $this->accessProfileCreator = new AccessProfileCreator(
|
|
|
+ $roleHierarchyMock,
|
|
|
+ $organizationProfileCreatorMock,
|
|
|
+ $this->accessRepositoryMock,
|
|
|
+ $this->accessUtilsMock
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see AccessProfileCreator::getAccessProfile()
|
|
|
+ */
|
|
|
+ public function testGetAccessProfileFailed(){
|
|
|
+ $this->accessRepositoryMock
|
|
|
+ ->method('findAllValidAccesses')
|
|
|
+ ->with($this->access)
|
|
|
+ ->willReturn([]);
|
|
|
+ $this->expectException(AuthenticationException::class);
|
|
|
+ $this->accessProfileCreator->getAccessProfile($this->access);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see AccessProfileCreator::createAccessProfile()
|
|
|
+ */
|
|
|
+ public function testCreateAccessProfile(){
|
|
|
+ $accessProfile = $this->accessProfileCreator->createAccessProfile($this->access);
|
|
|
+ $this->assertInstanceOf(AccessProfile::class, $accessProfile);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * @see AccessProfileCreator::createLightAccessProfile()
|
|
|
+ */
|
|
|
+ public function testCreateLightAccessProfile(){
|
|
|
+ $accessProfile = $this->accessProfileCreator->createLightAccessProfile($this->access);
|
|
|
$this->assertInstanceOf(AccessProfile::class, $accessProfile);
|
|
|
}
|
|
|
}
|