mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Implemented Type and Layer validation for right
This commit is contained in:
parent
0aac336609
commit
0c66e7a42a
@ -16,6 +16,7 @@ use App\Entity\Attribut\LayerAttribut;
|
||||
use App\Entity\Attribut\RelationAttribut;
|
||||
use App\Entity\Attribut\PriorityAttribut;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Exception\NoValidChoice;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -95,4 +96,20 @@ class Right extends AbstractMeta implements RightInterface
|
||||
$this->grant = true;
|
||||
$this->priority = 0;
|
||||
}
|
||||
|
||||
public function setType(string $type): void
|
||||
{
|
||||
if (!array_key_exists($type, RightType::getChoices())) {
|
||||
throw new NoValidChoice();
|
||||
}
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function setLayer(string $layer): void
|
||||
{
|
||||
if (!array_key_exists($layer, LayerType::getChoices())) {
|
||||
throw new NoValidChoice();
|
||||
}
|
||||
$this->layer = $layer;
|
||||
}
|
||||
}
|
||||
|
7
application/src/Exception/NoValidChoice.php
Normal file
7
application/src/Exception/NoValidChoice.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exception;
|
||||
|
||||
class NoValidChoice extends \Exception
|
||||
{
|
||||
}
|
@ -7,6 +7,8 @@ use App\DBAL\Types\RightType;
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Entity\Meta\Right;
|
||||
use App\Entity\Meta\Law;
|
||||
use App\DBAL\Types\LayerType;
|
||||
use App\Exception\NoValidChoice;
|
||||
|
||||
/**
|
||||
* @todo Implement reciever test
|
||||
@ -18,7 +20,7 @@ class RightTest extends TestCase
|
||||
/**
|
||||
* @var RightInterface
|
||||
*/
|
||||
protected $right;
|
||||
private $right;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
@ -70,7 +72,21 @@ class RightTest extends TestCase
|
||||
|
||||
public function testRight(): void
|
||||
{
|
||||
$this->assertNull($this->right->setType(RightType::READ));
|
||||
$this->assertEquals(RightType::READ, $this->right->getType());
|
||||
foreach (RightType::getChoices() as $key => $value) {
|
||||
$this->assertNull($this->right->setType($key));
|
||||
$this->assertEquals($key, $this->right->getType());
|
||||
}
|
||||
$this->expectException(NoValidChoice::class);
|
||||
$this->right->setType('NoneValidType');
|
||||
}
|
||||
|
||||
public function testLayer(): void
|
||||
{
|
||||
foreach (LayerType::getChoices() as $key => $value) {
|
||||
$this->assertNull($this->right->setLayer($key));
|
||||
$this->assertEquals($key, $this->right->getLayer());
|
||||
}
|
||||
$this->expectException(NoValidChoice::class);
|
||||
$this->right->setLayer('NoneValidLayer');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user