mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Refactored LawPermissionCheckerServiceTest
This commit is contained in:
parent
7575ef5edf
commit
33b1151a00
@ -38,39 +38,37 @@ class LawPermissionCheckerTest extends TestCase
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkClientPermission(): bool
|
||||||
|
{
|
||||||
|
return $this->lawPermissionChecker->hasPermission($this->client);
|
||||||
|
}
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->client = new Right();
|
$this->client = new Right();
|
||||||
$this->law = new Law();
|
$this->law = new Law();
|
||||||
$this->lawPermissionChecker = new LawPermissionCheckerService($this->law);
|
$this->lawPermissionChecker = new LawPermissionCheckerService($this->law);
|
||||||
}
|
|
||||||
|
|
||||||
public function testGeneralPermission(): void
|
|
||||||
{
|
|
||||||
$source = $this->getSourceMock();
|
$source = $this->getSourceMock();
|
||||||
$this->client->setSource($source);
|
$this->client->setSource($source);
|
||||||
$this->client->setLayer(LayerType::SOURCE);
|
$this->client->setLayer(LayerType::SOURCE);
|
||||||
$this->client->setType(RightType::READ);
|
$this->client->setType(RightType::READ);
|
||||||
$permission = $this->lawPermissionChecker->hasPermission($this->client);
|
}
|
||||||
$this->assertFalse($permission);
|
|
||||||
|
public function testGeneralPermission(): void
|
||||||
|
{
|
||||||
|
$this->assertFalse($this->checkClientPermission());
|
||||||
$lawRight = clone $this->client;
|
$lawRight = clone $this->client;
|
||||||
$this->law->getRights()->add($lawRight);
|
$this->law->getRights()->add($lawRight);
|
||||||
$permission = $this->lawPermissionChecker->hasPermission($this->client);
|
$this->assertTrue($this->checkClientPermission());
|
||||||
$this->assertTrue($permission);
|
|
||||||
$this->client->setType(RightType::WRITE);
|
$this->client->setType(RightType::WRITE);
|
||||||
$permission = $this->lawPermissionChecker->hasPermission($this->client);
|
$this->assertFalse($this->checkClientPermission());
|
||||||
$this->assertFalse($permission);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMemberPermission(): void
|
public function testMemberPermission(): void
|
||||||
{
|
{
|
||||||
$parentSource = $this->getSourceMock();
|
$parentSource = $this->getSourceMock();
|
||||||
$source = $this->getSourceMock();
|
$this->client->getSource()->getMemberRelation()->getMemberships()->add($parentSource);
|
||||||
$this->client->setSource($source);
|
$parentSource->getMemberRelation()->getMembers()->add($this->client->getSource());
|
||||||
$this->client->setLayer(LayerType::SOURCE);
|
|
||||||
$this->client->setType(RightType::READ);
|
|
||||||
$source->getMemberRelation()->getMemberships()->add($parentSource);
|
|
||||||
$parentSource->getMemberRelation()->getMembers()->add($source);
|
|
||||||
$lawRight = clone $this->client;
|
$lawRight = clone $this->client;
|
||||||
$lawRight->setSource($parentSource);
|
$lawRight->setSource($parentSource);
|
||||||
$this->law->getRights()->add($lawRight);
|
$this->law->getRights()->add($lawRight);
|
||||||
@ -83,10 +81,6 @@ class LawPermissionCheckerTest extends TestCase
|
|||||||
|
|
||||||
public function testSort(): void
|
public function testSort(): void
|
||||||
{
|
{
|
||||||
$source = $this->getSourceMock();
|
|
||||||
$this->client->setSource($source);
|
|
||||||
$this->client->setLayer(LayerType::SOURCE);
|
|
||||||
$this->client->setType(RightType::READ);
|
|
||||||
$right1 = clone $this->client;
|
$right1 = clone $this->client;
|
||||||
$right1->setPriority(123);
|
$right1->setPriority(123);
|
||||||
$right1->setGrant(false);
|
$right1->setGrant(false);
|
||||||
@ -94,11 +88,13 @@ class LawPermissionCheckerTest extends TestCase
|
|||||||
$right2->setPriority(456);
|
$right2->setPriority(456);
|
||||||
$right2->setGrant(true);
|
$right2->setGrant(true);
|
||||||
$this->law->setRights(new ArrayCollection([$right1, $right2]));
|
$this->law->setRights(new ArrayCollection([$right1, $right2]));
|
||||||
$permission = $this->lawPermissionChecker->hasPermission($this->client);
|
$this->assertFalse($this->checkClientPermission());
|
||||||
$this->assertFalse($permission);
|
|
||||||
$right2->setPriority(789);
|
$right2->setPriority(789);
|
||||||
$right1->setPriority(101112);
|
$right1->setPriority(101112);
|
||||||
$permission = $this->lawPermissionChecker->hasPermission($this->client);
|
$this->assertTrue($this->checkClientPermission());
|
||||||
$this->assertTrue($permission);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function test2Rights():void{
|
||||||
|
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user