2018-12-08 12:51:29 +01:00
|
|
|
<?php
|
2018-12-08 13:22:50 +01:00
|
|
|
|
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;
|
2019-01-04 22:09:05 +01:00
|
|
|
use App\Entity\Source\PureSource;
|
2018-12-08 12:51:29 +01:00
|
|
|
|
|
|
|
class RightCheckerTest extends TestCase
|
|
|
|
{
|
2018-12-08 13:22:50 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $layer;
|
|
|
|
|
2018-12-08 12:51:29 +01:00
|
|
|
/**
|
|
|
|
* @var SourceInterface
|
|
|
|
*/
|
|
|
|
private $source;
|
2018-12-08 13:22:50 +01:00
|
|
|
|
2018-12-08 12:51:29 +01:00
|
|
|
/**
|
|
|
|
* @var RightInterface
|
|
|
|
*/
|
|
|
|
private $right;
|
2018-12-08 13:22:50 +01:00
|
|
|
|
2018-12-08 12:51:29 +01:00
|
|
|
/**
|
|
|
|
* @var RightCheckerInterface
|
|
|
|
*/
|
|
|
|
private $rightManager;
|
2018-12-08 13:22:50 +01:00
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->layer = LayerType::RELATION;
|
2019-01-05 17:27:40 +01:00
|
|
|
$this->type = CRUDType::READ;
|
2019-01-04 22:09:05 +01:00
|
|
|
$this->source = new PureSource();
|
2018-12-08 13:22:50 +01:00
|
|
|
$this->right = new Right();
|
2018-12-14 10:10:28 +01:00
|
|
|
$this->right->setReciever($this->source);
|
2018-12-08 13:22:50 +01:00
|
|
|
$this->right->setType($this->type);
|
|
|
|
$this->right->setLayer($this->layer);
|
2018-12-08 12:51:29 +01:00
|
|
|
$this->rightManager = new RightChecker($this->right);
|
|
|
|
}
|
2018-12-08 13:22:50 +01:00
|
|
|
|
|
|
|
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);
|
2018-12-08 13:22:50 +01:00
|
|
|
$this->assertFalse($notGranted2);
|
|
|
|
$this->right->setGrant(false);
|
|
|
|
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $this->source);
|
|
|
|
$this->assertFalse($notGranted3);
|
2019-01-04 22:09:05 +01:00
|
|
|
$notGranted4 = $this->rightManager->isGranted($this->layer, $this->type, new PureSource());
|
2018-12-14 10:10:28 +01:00
|
|
|
$this->assertFalse($notGranted4);
|
2018-12-08 13:22:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSecondDimension(): void
|
|
|
|
{
|
2019-01-04 22:09:05 +01:00
|
|
|
$secondSource = new PureSource();
|
2018-12-30 16:12:46 +01:00
|
|
|
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
|
2018-12-08 13:22:50 +01:00
|
|
|
$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);
|
2018-12-08 13:22:50 +01:00
|
|
|
$this->assertFalse($notGranted2);
|
|
|
|
$this->right->setGrant(false);
|
|
|
|
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $secondSource);
|
|
|
|
$this->assertFalse($notGranted3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testThirdDimension(): void
|
|
|
|
{
|
2019-01-04 22:09:05 +01:00
|
|
|
$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());
|
2018-12-08 13:22:50 +01:00
|
|
|
$granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
|
2018-12-08 12:51:29 +01:00
|
|
|
$this->assertTrue($granted);
|
2018-12-08 13:22:50 +01:00
|
|
|
$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);
|
2018-12-08 13:22:50 +01:00
|
|
|
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
|
2018-12-08 12:51:29 +01:00
|
|
|
$this->assertFalse($notGranted3);
|
|
|
|
}
|
2018-12-08 13:22:50 +01:00
|
|
|
}
|