mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Implemented Type and Layer validation for right
This commit is contained in:
		@@ -16,6 +16,7 @@ use App\Entity\Attribut\LayerAttribut;
 | 
				
			|||||||
use App\Entity\Attribut\RelationAttribut;
 | 
					use App\Entity\Attribut\RelationAttribut;
 | 
				
			||||||
use App\Entity\Attribut\PriorityAttribut;
 | 
					use App\Entity\Attribut\PriorityAttribut;
 | 
				
			||||||
use App\Entity\Source\SourceInterface;
 | 
					use App\Entity\Source\SourceInterface;
 | 
				
			||||||
 | 
					use App\Exception\NoValidChoice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @author kevinfrantz
 | 
					 * @author kevinfrantz
 | 
				
			||||||
@@ -95,4 +96,20 @@ class Right extends AbstractMeta implements RightInterface
 | 
				
			|||||||
        $this->grant = true;
 | 
					        $this->grant = true;
 | 
				
			||||||
        $this->priority = 0;
 | 
					        $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\RightInterface;
 | 
				
			||||||
use App\Entity\Meta\Right;
 | 
					use App\Entity\Meta\Right;
 | 
				
			||||||
use App\Entity\Meta\Law;
 | 
					use App\Entity\Meta\Law;
 | 
				
			||||||
 | 
					use App\DBAL\Types\LayerType;
 | 
				
			||||||
 | 
					use App\Exception\NoValidChoice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @todo Implement reciever test
 | 
					 * @todo Implement reciever test
 | 
				
			||||||
@@ -18,7 +20,7 @@ class RightTest extends TestCase
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @var RightInterface
 | 
					     * @var RightInterface
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $right;
 | 
					    private $right;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setUp(): void
 | 
					    public function setUp(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -70,7 +72,21 @@ class RightTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function testRight(): void
 | 
					    public function testRight(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->assertNull($this->right->setType(RightType::READ));
 | 
					        foreach (RightType::getChoices() as $key => $value) {
 | 
				
			||||||
        $this->assertEquals(RightType::READ, $this->right->getType());
 | 
					            $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');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user