mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 11:17:58 +00:00 
			
		
		
		
	Implemenented version attribt, repository and tests for right entity
This commit is contained in:
		
							
								
								
									
										21
									
								
								application/src/Entity/Attribut/PriorityAttribut.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								application/src/Entity/Attribut/PriorityAttribut.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Entity\Attribut;
 | 
			
		||||
 | 
			
		||||
trait PriorityAttribut
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var int
 | 
			
		||||
     */
 | 
			
		||||
    protected $priority;
 | 
			
		||||
 | 
			
		||||
    public function setPriority(int $priority): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->priority = $priority;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getPriority(): int
 | 
			
		||||
    {
 | 
			
		||||
        return $this->priority;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Entity\Attribut;
 | 
			
		||||
 | 
			
		||||
interface PriorityAttributInterface
 | 
			
		||||
{
 | 
			
		||||
    public function setPriority(int $priority): void;
 | 
			
		||||
 | 
			
		||||
    public function getPriority(): int;
 | 
			
		||||
}
 | 
			
		||||
@@ -21,7 +21,7 @@ class Reciever extends AbstractMeta implements RecieverInterface
 | 
			
		||||
     * The right which the reciever group belongs to.
 | 
			
		||||
     *
 | 
			
		||||
     * @ORM\OneToOne(targetEntity="Right",cascade={"persist", "remove"})
 | 
			
		||||
     * @ORM\JoinColumn(name="right_id", referencedColumnName="id")
 | 
			
		||||
     * @ORM\JoinColumn(name="right_id", referencedColumnName="id",onDelete="CASCADE")
 | 
			
		||||
     *
 | 
			
		||||
     * @var RightInterface
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@ use App\Entity\Attribut\ConditionAttribut;
 | 
			
		||||
use App\Entity\Attribut\RecieverAttribut;
 | 
			
		||||
use App\Entity\Attribut\LayerAttribut;
 | 
			
		||||
use App\Entity\Attribut\RelationAttribut;
 | 
			
		||||
use App\Entity\Attribut\PriorityAttribut;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -22,7 +23,14 @@ use App\Entity\Attribut\RelationAttribut;
 | 
			
		||||
 */
 | 
			
		||||
class Right extends AbstractMeta implements RightInterface
 | 
			
		||||
{
 | 
			
		||||
    use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut;
 | 
			
		||||
    use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut,PriorityAttribut;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @ORM\Column(type="integer")
 | 
			
		||||
     *
 | 
			
		||||
     * @var int which priority has the right in a roleset
 | 
			
		||||
     */
 | 
			
		||||
    protected $priority;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @ORM\ManyToOne(targetEntity="Law", inversedBy="rights")
 | 
			
		||||
@@ -42,7 +50,7 @@ class Right extends AbstractMeta implements RightInterface
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @ORM\OneToOne(targetEntity="Reciever",cascade={"persist", "remove"})
 | 
			
		||||
     * @ORM\JoinColumn(name="reciever_id", referencedColumnName="id")
 | 
			
		||||
     * @ORM\JoinColumn(name="reciever_id", referencedColumnName="id",onDelete="CASCADE")
 | 
			
		||||
     *
 | 
			
		||||
     * @var RecieverInterface
 | 
			
		||||
     */
 | 
			
		||||
@@ -75,6 +83,7 @@ class Right extends AbstractMeta implements RightInterface
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct();
 | 
			
		||||
        $this->grant = true;
 | 
			
		||||
        $this->priority = 0;
 | 
			
		||||
        $this->reciever = new Reciever();
 | 
			
		||||
        $this->reciever->setRight($this);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,10 +9,11 @@ use App\Entity\Attribut\GrantAttributInterface;
 | 
			
		||||
use App\Entity\Attribut\ConditionAttributInterface;
 | 
			
		||||
use App\Entity\Attribut\LayerAttributInterface;
 | 
			
		||||
use App\Entity\Attribut\RelationAttributInterface;
 | 
			
		||||
use App\Entity\Attribut\PriorityAttributInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface RightInterface extends TypeAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface
 | 
			
		||||
interface RightInterface extends TypeAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface, PriorityAttributInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								application/src/Repository/RightRepository.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								application/src/Repository/RightRepository.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Repository;
 | 
			
		||||
 | 
			
		||||
use Doctrine\ORM\EntityRepository;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RightRepository extends EntityRepository
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,38 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Unit\Entity\Attribut;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Entity\Attribut\PriorityAttributInterface;
 | 
			
		||||
use App\Entity\Attribut\PriorityAttribut;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class PriorityAttributTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var PriorityAttributInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $priorityAttribut;
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->priorityAttribut = new class() implements PriorityAttributInterface {
 | 
			
		||||
            use PriorityAttribut;
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructor(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(\TypeError::class);
 | 
			
		||||
        $this->priorityAttribut->getPriority();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAccessors(): void
 | 
			
		||||
    {
 | 
			
		||||
        $priority = 123;
 | 
			
		||||
        $this->assertNull($this->priorityAttribut->setPriority($priority));
 | 
			
		||||
        $this->assertEquals($priority, $this->priorityAttribut->getPriority());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -29,6 +29,7 @@ class RightTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals($this->right, $this->right->getReciever()->getRight());
 | 
			
		||||
        $this->assertTrue($this->right->getGrant());
 | 
			
		||||
        $this->assertEquals(0, $this->right->getPriority());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testConstructorLayer(): void
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										100
									
								
								application/tests/Unit/Repository/RightRepositoryTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								application/tests/Unit/Repository/RightRepositoryTest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,100 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Repository;
 | 
			
		||||
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use Doctrine\ORM\EntityManager;
 | 
			
		||||
use Doctrine\ORM\EntityRepository;
 | 
			
		||||
use App\Entity\Meta\RightInterface;
 | 
			
		||||
use App\Entity\Meta\Right;
 | 
			
		||||
use App\DBAL\Types\LayerType;
 | 
			
		||||
use App\DBAL\Types\RightType;
 | 
			
		||||
use App\Entity\Meta\Law;
 | 
			
		||||
use App\Entity\Meta\LawInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @todo specify tests for all attributes
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RightRepositoryTest extends KernelTestCase
 | 
			
		||||
{
 | 
			
		||||
    const PRIORITY = 123;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityManager
 | 
			
		||||
     */
 | 
			
		||||
    protected $entityManager;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityRepository
 | 
			
		||||
     */
 | 
			
		||||
    protected $rightRepository;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RightInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $loadedRight;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RightInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $right;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var LawInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $law;
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        $kernel = self::bootKernel();
 | 
			
		||||
        $this->entityManager = $kernel->getContainer()
 | 
			
		||||
            ->get('doctrine')
 | 
			
		||||
            ->getManager();
 | 
			
		||||
        $this->rightRepository = $this->entityManager->getRepository(Right::class);
 | 
			
		||||
        $this->right = new Right();
 | 
			
		||||
        $this->right->setPriority(self::PRIORITY);
 | 
			
		||||
        $this->right->setLayer(LayerType::SOURCE);
 | 
			
		||||
        $this->right->setType(RightType::READ);
 | 
			
		||||
        $this->law = new Law();
 | 
			
		||||
        $this->entityManager->persist($this->law);
 | 
			
		||||
        $this->right->setLaw($this->law);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreation(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->entityManager->persist($this->right);
 | 
			
		||||
        $this->entityManager->flush();
 | 
			
		||||
        $rightId = $this->right->getId();
 | 
			
		||||
        /*
 | 
			
		||||
         * @var RightInterface
 | 
			
		||||
         */
 | 
			
		||||
        $this->loadedRight = $this->rightRepository->find($rightId);
 | 
			
		||||
        $this->assertEquals($rightId, $this->loadedRight->getId());
 | 
			
		||||
        $this->assertEquals(self::PRIORITY, $this->loadedRight->getPriority());
 | 
			
		||||
        $this->deleteRight();
 | 
			
		||||
        $this->assertNull($this->rightRepository->find($rightId));
 | 
			
		||||
        $this->loadedRight = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function deleteRight(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->entityManager->remove($this->loadedRight);
 | 
			
		||||
        $this->entityManager->flush();
 | 
			
		||||
        $this->entityManager->remove($this->law);
 | 
			
		||||
        $this->entityManager->flush();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown()
 | 
			
		||||
     */
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        parent::tearDown();
 | 
			
		||||
        $this->entityManager->close();
 | 
			
		||||
        $this->entityManager = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user