mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-10 06:27:24 +01:00
Optimized draft for RequestedRight
This commit is contained in:
parent
2b63e0e447
commit
7af1b3e58c
@ -50,7 +50,7 @@ class RequestedRight implements RequestedRightInterface
|
|||||||
*/
|
*/
|
||||||
private function isIdEquals(): bool
|
private function isIdEquals(): bool
|
||||||
{
|
{
|
||||||
if ($this->requestedSource->hasId() && $this->source->hasId()) {
|
if (!$this->requestedSource->hasId() || !$this->source->hasId()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,19 +62,27 @@ class RequestedRight implements RequestedRightInterface
|
|||||||
*/
|
*/
|
||||||
private function isSlugEquals(): bool
|
private function isSlugEquals(): bool
|
||||||
{
|
{
|
||||||
if ($this->requestedSource->hasSlug() && $this->source->hasSlug()) {
|
if (!$this->requestedSource->hasSlug() || !$this->source->hasSlug()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->requestedSource->getSlug() === $this->source->getSlug();
|
return $this->requestedSource->getSlug() === $this->source->getSlug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool Returns true if the source is not set!
|
||||||
|
*/
|
||||||
|
private function isSourceNotSet(): bool
|
||||||
|
{
|
||||||
|
return !isset($this->source);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool Tells if a reload of the source is neccessary
|
* @return bool Tells if a reload of the source is neccessary
|
||||||
*/
|
*/
|
||||||
private function isReloadNeccessary(): bool
|
private function isReloadNeccessary(): bool
|
||||||
{
|
{
|
||||||
return $this->isIdEquals() && $this->isSlugEquals();
|
return $this->isSourceNotSet() || $this->isIdEquals() || $this->isSlugEquals();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,11 +96,19 @@ class RequestedRight implements RequestedRightInterface
|
|||||||
{
|
{
|
||||||
if ($this->isReloadNeccessary()) {
|
if ($this->isReloadNeccessary()) {
|
||||||
$this->loadSource();
|
$this->loadSource();
|
||||||
|
$this->setSourceIfNotSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->source;
|
return $this->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setSourceIfNotSet(): void
|
||||||
|
{
|
||||||
|
if (!isset($this->source)) {
|
||||||
|
$this->source = $this->requestedSource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
@ -101,6 +117,5 @@ class RequestedRight implements RequestedRightInterface
|
|||||||
final public function setRequestedSource(RequestedSourceInterface $requestedSource)
|
final public function setRequestedSource(RequestedSourceInterface $requestedSource)
|
||||||
{
|
{
|
||||||
$this->requestedSource = $requestedSource;
|
$this->requestedSource = $requestedSource;
|
||||||
$this->loadSource();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace tests\Unit\Domain\RightManagement\RightRequestManagement;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface;
|
||||||
|
use App\Domain\RightManagement\RightRequestManagement\RequestedRight;
|
||||||
|
use App\Entity\Source\AbstractSource;
|
||||||
|
use App\DBAL\Types\Meta\Right\LayerType;
|
||||||
|
use App\Domain\SourceManagement\RequestedSource;
|
||||||
|
use App\DBAL\Types\SystemSlugType;
|
||||||
|
use App\Domain\SourceManagement\RequestedSourceInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
class RequestedRightTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var RequestedRightInterface
|
||||||
|
*/
|
||||||
|
private $requestedRight;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
||||||
|
$sourceRepository = $entityManager->getRepository(AbstractSource::class);
|
||||||
|
$this->requestedRight = new RequestedRight($sourceRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLayer(): void
|
||||||
|
{
|
||||||
|
$layer = LayerType::SOURCE;
|
||||||
|
$this->assertNull($this->requestedRight->setLayer($layer));
|
||||||
|
$this->assertEquals($layer, $this->requestedRight->getLayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLayerException(): void
|
||||||
|
{
|
||||||
|
$this->expectException(\TypeError::class);
|
||||||
|
var_dump($this->requestedRight->getLayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnsavedRequestedSource(): void
|
||||||
|
{
|
||||||
|
$source = $this->createMock(RequestedSource::class);
|
||||||
|
$this->requestedRight->setRequestedSource($source);
|
||||||
|
$this->assertEquals($source, $this->requestedRight->getSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testKnownSource(): void
|
||||||
|
{
|
||||||
|
$requestedSource = new RequestedSource();
|
||||||
|
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||||
|
$this->requestedRight->setRequestedSource($requestedSource);
|
||||||
|
$sourceResponse1 = $this->requestedRight->getSource();
|
||||||
|
$this->assertGreaterThan(0, $sourceResponse1->getId());
|
||||||
|
$requestedSource->setSlug('');
|
||||||
|
$sourceResponse2 = $this->requestedRight->getSource();
|
||||||
|
$this->assertInstanceOf(RequestedSourceInterface::class, $sourceResponse2);
|
||||||
|
$this->assertFalse($sourceResponse2->hasId());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user