infinito/application/symfony/tests/Unit/Domain/RightManagement/RightCheckerTest.php

101 lines
3.6 KiB
PHP
Raw Normal View History

2018-12-08 12:51:29 +01:00
<?php
2018-12-08 12:51:29 +01:00
namespace Tests\Unit\Domain\RightManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right;
use App\Entity\Source\SourceInterface;
2019-01-05 17:27:40 +01:00
use App\DBAL\Types\Meta\Right\LayerType;
2018-12-08 12:51:29 +01:00
use App\Domain\RightManagement\RightCheckerInterface;
use App\Domain\RightManagement\RightChecker;
2019-01-05 17:27:40 +01:00
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Source\PureSource;
2018-12-08 12:51:29 +01:00
class RightCheckerTest extends TestCase
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $layer;
2018-12-08 12:51:29 +01:00
/**
* @var SourceInterface
*/
private $source;
2018-12-08 12:51:29 +01:00
/**
* @var RightInterface
*/
private $right;
2018-12-08 12:51:29 +01:00
/**
* @var RightCheckerInterface
*/
private $rightManager;
public function setUp(): void
{
2019-01-05 18:06:50 +01:00
$this->layer = LayerType::MEMBER;
2019-01-05 17:27:40 +01:00
$this->type = CRUDType::READ;
$this->source = new PureSource();
$this->right = new Right();
2018-12-14 10:10:28 +01:00
$this->right->setReciever($this->source);
2019-01-16 21:22:18 +01:00
$this->right->setCrud($this->type);
$this->right->setLayer($this->layer);
2018-12-08 12:51:29 +01:00
$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);
2019-01-05 17:27:40 +01:00
$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());
2018-12-14 10:10:28 +01:00
$this->assertFalse($notGranted4);
}
public function testSecondDimension(): void
{
$secondSource = new PureSource();
2018-12-30 16:12:46 +01:00
$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);
2019-01-05 17:27:40 +01:00
$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();
2018-12-30 16:12:46 +01:00
$secondSource->getMemberRelation()->getMembers()->add($thirdSource->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
$granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
2018-12-08 12:51:29 +01:00
$this->assertTrue($granted);
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $thirdSource);
2018-12-08 12:51:29 +01:00
$this->assertFalse($notGranted);
2019-01-05 17:27:40 +01:00
$notGranted2 = $this->rightManager->isGranted($this->layer, CRUDType::UPDATE, $thirdSource);
2018-12-08 12:51:29 +01:00
$this->assertFalse($notGranted2);
$this->right->setGrant(false);
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
2018-12-08 12:51:29 +01:00
$this->assertFalse($notGranted3);
}
}