From 130682ef6c3069e114424f5edbd2b9abd3ede96e Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 1 Jan 2019 22:36:55 +0100 Subject: [PATCH] Allowed guest users to access impressum --- .../src/DataFixtures/SourceFixtures.php | 61 ++++++++++++++----- .../SecureSourceLoaderTest.php | 24 ++++---- .../Unit/Repository/RightRepositoryTest.php | 3 - 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/application/src/DataFixtures/SourceFixtures.php b/application/src/DataFixtures/SourceFixtures.php index 08298f6..65bb309 100644 --- a/application/src/DataFixtures/SourceFixtures.php +++ b/application/src/DataFixtures/SourceFixtures.php @@ -9,36 +9,65 @@ use App\Entity\Source\Primitive\Text\TextSourceInterface; use App\DBAL\Types\SystemSlugType; use App\Entity\Source\Complex\UserSource; use App\Entity\Source\Complex\UserSourceInterface; +use App\Entity\Meta\Right; +use App\DBAL\Types\LayerType; +use App\DBAL\Types\RightType; +use App\Entity\Meta\RightInterface; +/** + * @author kevinfrantz + * + * @todo Create a collection class for all users + */ class SourceFixtures extends Fixture { + /** + * @var TextSourceInterface The example source for the impressum + */ + private $impressumSource; + + /** + * @var UserSourceInterface The UserSource which should be used for the anonymous user + */ + private $guestUserSource; + public function load(ObjectManager $manager) { - $manager->persist($this->getImpressum()); - $manager->persist($this->getGuestUser()); + $this->setGuestUserSource(); + $this->setImpressumSource(); + $manager->persist($this->impressumSource); + $manager->persist($this->getImpressumRight()); + $manager->persist($this->guestUserSource); $manager->flush(); } - /** - * @return TextSourceInterface The example source for the impressum - */ - private function getImpressum(): TextSourceInterface + private function setImpressumSource(): void { - $source = new TextSource(); - $source->setText('Example Impressum'); - $source->setSlug(SystemSlugType::IMPRINT); - - return $source; + $this->impressumSource = new TextSource(); + $this->impressumSource->setText('Example Impressum'); + $this->impressumSource->setSlug(SystemSlugType::IMPRINT); } /** - * @return UserSourceInterface The UserSource which should be used for the anonymous user + * @todo Implement that right gets automaticly created by persisting of law + * + * @return RightInterface */ - private function getGuestUser(): UserSourceInterface + private function getImpressumRight(): RightInterface { - $source = new UserSource(); - $source->setSlug(SystemSlugType::GUEST_USER); + $right = new Right(); + $right->setSource($this->impressumSource); + $right->setLaw($this->impressumSource->getLaw()); + $right->setLayer(LayerType::SOURCE); + $right->setType(RightType::READ); + $right->setReciever($this->guestUserSource); - return $source; + return $right; + } + + private function setGuestUserSource(): void + { + $this->guestUserSource = new UserSource(); + $this->guestUserSource->setSlug(SystemSlugType::GUEST_USER); } } diff --git a/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php b/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php index 6668e88..bf9fb4a 100644 --- a/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php +++ b/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php @@ -55,16 +55,16 @@ class SecureSourceLoaderTest extends KernelTestCase $secureSourceLoader->getSource(); } -// public function testGranted(): void -// { -// $requestedSource = new TextSource(); -// $requestedSource->setSlug(SystemSlugType::IMPRINT); -// $requestedRight = new Right(); -// $requestedRight->setSource($requestedSource); -// $requestedRight->setLayer(LayerType::SOURCE); -// $requestedRight->setType(RightType::READ); -// $requestedRight->setReciever($this->sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER])); -// $secureSourceLoader = new SecureSourceLoader($this->sourceRepository, $requestedRight); -// $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource()); -// } + public function testGranted(): void + { + $requestedSource = new TextSource(); + $requestedSource->setSlug(SystemSlugType::IMPRINT); + $requestedRight = new Right(); + $requestedRight->setSource($requestedSource); + $requestedRight->setLayer(LayerType::SOURCE); + $requestedRight->setType(RightType::READ); + $requestedRight->setReciever($this->sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER])); + $secureSourceLoader = new SecureSourceLoader($this->sourceRepository, $requestedRight); + $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource()); + } } diff --git a/application/tests/Unit/Repository/RightRepositoryTest.php b/application/tests/Unit/Repository/RightRepositoryTest.php index 8961247..44416c5 100644 --- a/application/tests/Unit/Repository/RightRepositoryTest.php +++ b/application/tests/Unit/Repository/RightRepositoryTest.php @@ -67,9 +67,6 @@ class RightRepositoryTest extends KernelTestCase $this->entityManager->persist($this->right); $this->entityManager->flush(); $rightId = $this->right->getId(); - /* - * @var RightInterface - */ $this->loadedRight = $this->rightRepository->find($rightId); $this->assertEquals($rightId, $this->loadedRight->getId()); $this->assertEquals(self::PRIORITY, $this->loadedRight->getPriority());