Renamed domain RightManagement to Right

This commit is contained in:
Kevin Frantz
2019-05-30 16:55:08 +02:00
parent b8029bb7cc
commit e9110622db
16 changed files with 24 additions and 24 deletions

View File

@@ -0,0 +1,115 @@
<?php
namespace Tests\Unit\Domain\Right;
use PHPUnit\Framework\TestCase;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Entity\Meta\Right;
use Infinito\Entity\Source\SourceInterface;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Domain\Right\RightCheckerInterface;
use Infinito\Domain\Right\RightChecker;
use Infinito\DBAL\Types\Meta\Right\CRUDType;
use Infinito\Entity\Source\PureSource;
/**
* @author kevinfrantz
*/
class RightCheckerTest extends TestCase
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $layer;
/**
* @var SourceInterface
*/
private $source;
/**
* @var RightInterface
*/
private $right;
/**
* @var RightCheckerInterface
*/
private $rightManager;
public function setUp(): void
{
$this->layer = LayerType::MEMBER;
$this->type = CRUDType::READ;
$this->source = new PureSource();
$this->right = new Right();
$this->right->setReciever($this->source);
$this->right->setActionType($this->type);
$this->right->setLayer($this->layer);
$this->rightManager = new RightChecker($this->right);
}
public function testFirstDimension(): void
{
$granted = $this->rightManager->isGranted($this->layer, $this->type, $this->source);
$this->assertTrue($granted);
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $this->source);
$this->assertFalse($notGranted);
$notGranted2 = $this->rightManager->isGranted($this->layer, CRUDType::UPDATE, $this->source);
$this->assertFalse($notGranted2);
$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, new PureSource());
$this->assertFalse($notGranted4);
}
public function testSecondDimension(): void
{
$secondSource = new PureSource();
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
$granted = $this->rightManager->isGranted($this->layer, $this->type, $secondSource);
$this->assertTrue($granted);
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $secondSource);
$this->assertFalse($notGranted);
$notGranted2 = $this->rightManager->isGranted($this->layer, CRUDType::UPDATE, $secondSource);
$this->assertFalse($notGranted2);
$this->right->setGrant(false);
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $secondSource);
$this->assertFalse($notGranted3);
}
public function testThirdDimension(): void
{
$thirdSource = new PureSource();
$secondSource = new PureSource();
$secondSource->getMemberRelation()->getMembers()->add($thirdSource->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
$granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
$this->assertTrue($granted);
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $thirdSource);
$this->assertFalse($notGranted);
$notGranted2 = $this->rightManager->isGranted($this->layer, CRUDType::UPDATE, $thirdSource);
$this->assertFalse($notGranted2);
$this->right->setGrant(false);
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
$this->assertFalse($notGranted3);
}
public function testAppliesToAll(): void
{
$this->assertNull($this->right->setReciever(null));
$this->assertTrue($this->rightManager->isGranted($this->layer, $this->type, $this->source));
$source2 = new PureSource();
$this->assertTrue($this->rightManager->isGranted($this->layer, $this->type, $source2));
$source3 = new PureSource();
$this->assertNull($this->right->setReciever($source3));
$this->assertTrue($this->rightManager->isGranted($this->layer, $this->type, $source3));
$this->assertFalse($this->rightManager->isGranted($this->layer, $this->type, $source2));
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace tests\Unit\Domain\Right;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\Right\RightLayerCombinationServiceInterface;
use Infinito\Domain\Right\RightLayerCombinationService;
use Infinito\DBAL\Types\Meta\Right\CRUDType;
use Infinito\DBAL\Types\Meta\Right\LayerType;
/**
* @author kevinfrantz
*/
class RightLayerCombinationServiceTest extends TestCase
{
/**
* @var RightLayerCombinationServiceInterface
*/
public $rightLayerCombinationService;
/**
* {@inheritdoc}
*
* @see \PHPUnit\Framework\TestCase::setUp()
*/
public function setUp()
{
$this->rightLayerCombinationService = new RightLayerCombinationService();
}
public function testBySource(): void
{
foreach (CRUDType::getValues() as $crudType) {
$layers = $this->rightLayerCombinationService->getPossibleLayers($crudType);
$this->assertContains(LayerType::SOURCE, $layers);
$sourceCruds = $this->rightLayerCombinationService->getPossibleCruds(LayerType::SOURCE);
$this->assertContains($crudType, $sourceCruds);
}
}
public function testByLaw(): void
{
foreach ([CRUDType::DELETE, CRUDType::CREATE] as $crudType) {
$layers = $this->rightLayerCombinationService->getPossibleLayers($crudType);
$this->assertNotContains(LayerType::LAW, $layers);
$sourceCruds = $this->rightLayerCombinationService->getPossibleCruds(LayerType::LAW);
$this->assertNotContains($crudType, $sourceCruds);
}
foreach ([CRUDType::READ, CRUDType::UPDATE] as $crudType) {
$layers = $this->rightLayerCombinationService->getPossibleLayers($crudType);
$this->assertContains(LayerType::LAW, $layers);
$sourceCruds = $this->rightLayerCombinationService->getPossibleCruds(LayerType::LAW);
$this->assertContains($crudType, $sourceCruds);
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace tests\Unit\Domain\Right;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\Request\Right\RequestedRight;
use Infinito\DBAL\Types\Meta\Right\CRUDType;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Domain\Right\RightTransformerService;
use Infinito\Domain\Request\Entity\RequestedEntityInterface;
/**
* @author kevinfrantz
*/
class RightTransformerServiceTest extends TestCase
{
public function testTransformation(): void
{
$source = $this->createMock(SourceInterface::class);
$crud = CRUDType::READ;
$layer = LayerType::SOURCE;
$reciever = $this->createMock(SourceInterface::class);
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('hasId')->willReturn(123);
$requestedEntity->method('getEntity')->willReturn($source);
$requestedEntity->method('hasIdentity')->willReturn(true);
$requestedEntity->method('hasRequestedRight')->willReturn(true);
$requestedRight = new RequestedRight();
$requestedRight->setActionType($crud);
$requestedRight->setLayer($layer);
$requestedRight->setRequestedEntity($requestedEntity);
$requestedRight->setReciever($reciever);
$transformer = new RightTransformerService();
$right = $transformer->transform($requestedRight);
$this->assertEquals($crud, $right->getActionType());
$this->assertEquals($layer, $right->getLayer());
$this->assertEquals($reciever, $right->getReciever());
$this->assertEquals($source, $right->getSource());
}
}