diff --git a/application/src/Entity/Meta/Right.php b/application/src/Entity/Meta/Right.php index e275528..82458e9 100644 --- a/application/src/Entity/Meta/Right.php +++ b/application/src/Entity/Meta/Right.php @@ -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; + } } diff --git a/application/src/Exception/NoValidChoice.php b/application/src/Exception/NoValidChoice.php new file mode 100644 index 0000000..156f67b --- /dev/null +++ b/application/src/Exception/NoValidChoice.php @@ -0,0 +1,7 @@ +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'); } }