mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Optimized RightCheck for thirdt and second dimension source
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Unit\Domain\RightManagement;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
@@ -13,49 +14,91 @@ use App\DBAL\Types\RightType;
 | 
			
		||||
 | 
			
		||||
class RightCheckerTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    private $type;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    private $layer;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $source;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RightInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $right;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RightCheckerInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $rightManager;
 | 
			
		||||
    
 | 
			
		||||
    private function getSourceMock():SourceInterface{
 | 
			
		||||
        return new class extends AbstractSource{};
 | 
			
		||||
 | 
			
		||||
    private function getSourceMock(): SourceInterface
 | 
			
		||||
    {
 | 
			
		||||
        return new class() extends AbstractSource {
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function setUp():void{
 | 
			
		||||
        $this->right = new Right();
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->layer = LayerType::RELATION;
 | 
			
		||||
        $this->type = RightType::READ;
 | 
			
		||||
        $this->source = $this->getSourceMock();
 | 
			
		||||
        $this->right = new Right();
 | 
			
		||||
        $this->right->setSource($this->source);
 | 
			
		||||
        $this->right->setType($this->type);
 | 
			
		||||
        $this->right->setLayer($this->layer);
 | 
			
		||||
        $this->rightManager = new RightChecker($this->right);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function testFirstDimension():void{
 | 
			
		||||
        $layer = LayerType::RELATION;
 | 
			
		||||
        $type = RightType::READ;
 | 
			
		||||
        $this->right->setType($type);
 | 
			
		||||
        $this->right->setLayer($layer);
 | 
			
		||||
        $granted = $this->rightManager->isGranted($layer, $type, $this->source);
 | 
			
		||||
 | 
			
		||||
    public function testFirstDimension(): void
 | 
			
		||||
    {
 | 
			
		||||
        $granted = $this->rightManager->isGranted($this->layer, $this->type, $this->source);
 | 
			
		||||
        $this->assertTrue($granted);
 | 
			
		||||
        $notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $type, $this->source);
 | 
			
		||||
        $notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $this->source);
 | 
			
		||||
        $this->assertFalse($notGranted);
 | 
			
		||||
        $notGranted2 = $this->rightManager->isGranted($layer, RightType::WRITE, $this->source);
 | 
			
		||||
        $notGranted2 = $this->rightManager->isGranted($this->layer, RightType::WRITE, $this->source);
 | 
			
		||||
        $this->assertFalse($notGranted2);
 | 
			
		||||
        $this->right->setGrant(false);
 | 
			
		||||
        $notGranted3 = $this->rightManager->isGranted($layer, $type, $this->source);
 | 
			
		||||
        $notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $this->source);
 | 
			
		||||
        $this->assertFalse($notGranted3);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
//     public function testSecondDimension():void{
 | 
			
		||||
        
 | 
			
		||||
//     }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    public function testSecondDimension(): void
 | 
			
		||||
    {
 | 
			
		||||
        $secondSource = $this->getSourceMock();
 | 
			
		||||
        $this->source->getMemberRelation()->getMembers()->add($secondSource);
 | 
			
		||||
        $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, RightType::WRITE, $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 = $this->getSourceMock();
 | 
			
		||||
        $secondSource = $this->getSourceMock();
 | 
			
		||||
        $secondSource->getMemberRelation()->getMembers()->add($thirdSource);
 | 
			
		||||
        $this->source->getMemberRelation()->getMembers()->add($secondSource);
 | 
			
		||||
        $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, RightType::WRITE, $thirdSource);
 | 
			
		||||
        $this->assertFalse($notGranted2);
 | 
			
		||||
        $this->right->setGrant(false);
 | 
			
		||||
        $notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
 | 
			
		||||
        $this->assertFalse($notGranted3);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user