diff --git a/application/src/Domain/RightManagement/RightChecker.php b/application/src/Domain/RightManagement/RightChecker.php index 4c7a3c6..40fb470 100644 --- a/application/src/Domain/RightManagement/RightChecker.php +++ b/application/src/Domain/RightManagement/RightChecker.php @@ -26,9 +26,9 @@ final class RightChecker implements RightCheckerInterface */ private function getAllSourcesToWhichRightApplies(): Collection { - $rightSourceMemberInformation = new SourceMemberInformation($this->right->getSource()); + $rightSourceMemberInformation = new SourceMemberInformation($this->right->getReciever()); $allSourcesToWhichRightApplies = clone $rightSourceMemberInformation->getAllMembers(); - $allSourcesToWhichRightApplies->add($this->right->getSource()); + $allSourcesToWhichRightApplies->add($this->right->getReciever()); return $allSourcesToWhichRightApplies; } diff --git a/application/src/Entity/Attribut/RecieverAttribut.php b/application/src/Entity/Attribut/RecieverAttribut.php index 1618e9b..c15dfc8 100644 --- a/application/src/Entity/Attribut/RecieverAttribut.php +++ b/application/src/Entity/Attribut/RecieverAttribut.php @@ -2,7 +2,7 @@ namespace App\Entity\Attribut; -use App\Entity\Meta\RecieverInterface; +use App\Entity\Source\SourceInterface; /** * @author kevinfrantz @@ -10,16 +10,16 @@ use App\Entity\Meta\RecieverInterface; trait RecieverAttribut { /** - * @var RecieverInterface + * @var SourceInterface */ protected $reciever; - public function setReciever(RecieverInterface $reciever): void + public function setReciever(SourceInterface $reciever): void { $this->reciever = $reciever; } - public function getReciever(): RecieverInterface + public function getReciever(): SourceInterface { return $this->reciever; } diff --git a/application/src/Entity/Attribut/RecieverAttributInterface.php b/application/src/Entity/Attribut/RecieverAttributInterface.php index 3ee921a..4c11c8d 100644 --- a/application/src/Entity/Attribut/RecieverAttributInterface.php +++ b/application/src/Entity/Attribut/RecieverAttributInterface.php @@ -2,14 +2,14 @@ namespace App\Entity\Attribut; -use App\Entity\Meta\RecieverInterface; +use App\Entity\Source\SourceInterface; /** * @author kevinfrantz */ interface RecieverAttributInterface { - public function setReciever(RecieverInterface $reciever): void; + public function setReciever(SourceInterface $reciever): void; - public function getReciever(): RecieverInterface; + public function getReciever(): SourceInterface; } diff --git a/application/src/Entity/Meta/Reciever.php b/application/src/Entity/Meta/Reciever.php deleted file mode 100644 index 533d6d5..0000000 --- a/application/src/Entity/Meta/Reciever.php +++ /dev/null @@ -1,46 +0,0 @@ -collection = new ArrayCollection(); - } -} diff --git a/application/src/Entity/Meta/RecieverInterface.php b/application/src/Entity/Meta/RecieverInterface.php deleted file mode 100644 index ada3dde..0000000 --- a/application/src/Entity/Meta/RecieverInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -grant = true; $this->priority = 0; - $this->reciever = new Reciever(); - $this->reciever->setRight($this); } } diff --git a/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php b/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php index f87a9eb..4cbf003 100644 --- a/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php +++ b/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php @@ -15,6 +15,9 @@ use App\Entity\Meta\LawInterface; use App\Entity\Meta\RightInterface; use Doctrine\Common\Collections\ArrayCollection; +/** + * @author kevinfrantz + */ class LawPermissionCheckerTest extends TestCase { /** @@ -30,7 +33,12 @@ class LawPermissionCheckerTest extends TestCase /** * @var RightInterface */ - protected $client; + protected $clientRight; + + /** + * @var SourceInterface + */ + private $clientSource; private function getSourceMock(): SourceInterface { @@ -40,61 +48,60 @@ class LawPermissionCheckerTest extends TestCase private function checkClientPermission(): bool { - return $this->lawPermissionChecker->hasPermission($this->client); + return $this->lawPermissionChecker->hasPermission($this->clientRight); } public function setUp(): void { - $this->client = new Right(); + $this->clientRight = new Right(); $this->law = new Law(); $this->lawPermissionChecker = new LawPermissionCheckerService($this->law); - $source = $this->getSourceMock(); - $this->client->setSource($source); - $this->client->setLayer(LayerType::SOURCE); - $this->client->setType(RightType::READ); + $this->clientSource = $this->getSourceMock(); + $this->clientRight->setSource($this->clientSource); + $this->clientRight->setLayer(LayerType::SOURCE); + $this->clientRight->setType(RightType::READ); } public function testGeneralPermission(): void { $this->assertFalse($this->checkClientPermission()); - $lawRight = clone $this->client; + $lawRight = clone $this->clientRight; + $lawRight->setReciever($this->clientSource); $this->law->getRights()->add($lawRight); $this->assertTrue($this->checkClientPermission()); - $this->client->setType(RightType::WRITE); + $this->clientRight->setType(RightType::WRITE); $this->assertFalse($this->checkClientPermission()); } public function testMemberPermission(): void { $parentSource = $this->getSourceMock(); - $this->client->getSource()->getMemberRelation()->getMemberships()->add($parentSource); - $parentSource->getMemberRelation()->getMembers()->add($this->client->getSource()); - $lawRight = clone $this->client; - $lawRight->setSource($parentSource); + $this->clientRight->getSource()->getMemberRelation()->getMemberships()->add($parentSource); + $parentSource->getMemberRelation()->getMembers()->add($this->clientRight->getSource()); + $lawRight = clone $this->clientRight; + $lawRight->setReciever($parentSource); $this->law->getRights()->add($lawRight); - $permission = $this->lawPermissionChecker->hasPermission($this->client); + $permission = $this->lawPermissionChecker->hasPermission($this->clientRight); $this->assertTrue($permission); $this->law->setRights(new ArrayCollection()); - $permission = $this->lawPermissionChecker->hasPermission($this->client); + $permission = $this->lawPermissionChecker->hasPermission($this->clientRight); $this->assertFalse($permission); } public function testSort(): void { - $right1 = clone $this->client; + $right1 = clone $this->clientRight; $right1->setPriority(123); $right1->setGrant(false); - $right2 = clone $this->client; + $right1->setReciever($this->clientSource); + $right2 = clone $this->clientRight; $right2->setPriority(456); $right2->setGrant(true); + $right2->setReciever($this->clientSource); $this->law->setRights(new ArrayCollection([$right1, $right2])); $this->assertFalse($this->checkClientPermission()); $right2->setPriority(789); $right1->setPriority(101112); $this->assertTrue($this->checkClientPermission()); } - -// public function test2Rights():void{ - -// } } diff --git a/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php b/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php index a4554f7..beda3fe 100644 --- a/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php +++ b/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php @@ -51,7 +51,7 @@ class RightCheckerTest extends TestCase $this->type = RightType::READ; $this->source = $this->getSourceMock(); $this->right = new Right(); - $this->right->setSource($this->source); + $this->right->setReciever($this->source); $this->right->setType($this->type); $this->right->setLayer($this->layer); $this->rightManager = new RightChecker($this->right); @@ -68,6 +68,8 @@ class RightCheckerTest extends TestCase $this->right->setGrant(false); $notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $this->source); $this->assertFalse($notGranted3); + $notGranted4 = $this->rightManager->isGranted($this->layer, $this->type, $this->getSourceMock()); + $this->assertFalse($notGranted4); } public function testSecondDimension(): void diff --git a/application/tests/Unit/Entity/Attribut/RecieverAttributTest.php b/application/tests/Unit/Entity/Attribut/RecieverAttributTest.php index 7c644b9..59a5f65 100644 --- a/application/tests/Unit/Entity/Attribut/RecieverAttributTest.php +++ b/application/tests/Unit/Entity/Attribut/RecieverAttributTest.php @@ -5,7 +5,7 @@ namespace Tests\Unit\Entity\Attribut; use PHPUnit\Framework\TestCase; use App\Entity\Attribut\RecieverAttributInterface; use App\Entity\Attribut\RecieverAttribut; -use App\Entity\Meta\RecieverInterface; +use App\Entity\Source\AbstractSource; class RecieverAttributTest extends TestCase { @@ -29,7 +29,7 @@ class RecieverAttributTest extends TestCase public function testAccessors(): void { - $reciever = $this->createMock(RecieverInterface::class); + $reciever = $this->createMock(AbstractSource::class); $this->assertNull($this->reciever->setReciever($reciever)); $this->assertEquals($reciever, $this->reciever->getReciever()); } diff --git a/application/tests/Unit/Entity/Meta/RecieverTest.php b/application/tests/Unit/Entity/Meta/RecieverTest.php deleted file mode 100644 index 69c6a31..0000000 --- a/application/tests/Unit/Entity/Meta/RecieverTest.php +++ /dev/null @@ -1,28 +0,0 @@ -reciever = new Reciever(); - } - - public function testConstructor(): void - { - $this->assertInstanceOf(Collection::class, $this->reciever->getCollection()); - $this->expectException(\TypeError::class); - $this->reciever->getRight(); - } -} diff --git a/application/tests/Unit/Entity/Meta/RightTest.php b/application/tests/Unit/Entity/Meta/RightTest.php index 4076ecc..ac79afb 100644 --- a/application/tests/Unit/Entity/Meta/RightTest.php +++ b/application/tests/Unit/Entity/Meta/RightTest.php @@ -27,11 +27,16 @@ class RightTest extends TestCase public function testConstructorGeneral(): void { - $this->assertEquals($this->right, $this->right->getReciever()->getRight()); $this->assertTrue($this->right->getGrant()); $this->assertEquals(0, $this->right->getPriority()); } + public function testConstructorReciever(): void + { + $this->expectException(\TypeError::class); + $this->right->getReciever(); + } + public function testConstructorLayer(): void { $this->expectException(\TypeError::class);