mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Implemented slug for sources
This commit is contained in:
		
							
								
								
									
										21
									
								
								application/src/Entity/Attribut/SlugAttribut.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								application/src/Entity/Attribut/SlugAttribut.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| trait SlugAttribut | ||||
| { | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $slug; | ||||
|  | ||||
|     public function setSlug(string $slug): void | ||||
|     { | ||||
|         $this->slug = $slug; | ||||
|     } | ||||
|  | ||||
|     public function getSlug(): string | ||||
|     { | ||||
|         return $this->slug; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										10
									
								
								application/src/Entity/Attribut/SlugAttributInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								application/src/Entity/Attribut/SlugAttributInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| interface SlugAttributInterface | ||||
| { | ||||
|     public function setSlug(string $slug): void; | ||||
|  | ||||
|     public function getSlug(): string; | ||||
| } | ||||
| @@ -15,6 +15,9 @@ use App\Entity\Meta\Law; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use App\Entity\Attribut\MembershipsAttribut; | ||||
| use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface; | ||||
| use App\Entity\Attribut\SlugAttribut; | ||||
| use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | ||||
| use Symfony\Component\Validator\Constraints as Assert; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -24,10 +27,22 @@ use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface; | ||||
|  * @ORM\InheritanceType("JOINED") | ||||
|  * @ORM\DiscriminatorColumn(name="discr", type="string") | ||||
|  * @ORM\DiscriminatorMap({"primitive" = "App\Entity\Source\Primitive\AbstractPrimitiveSource", "collection" = "App\Entity\Source\Complex\Collection\AbstractCollectionSource","operation"="App\Entity\Source\Operation\AbstractOperation"}) | ||||
|  * @UniqueEntity("slug",ignoreNull=true) | ||||
|  */ | ||||
| abstract class AbstractSource extends AbstractEntity implements SourceInterface | ||||
| { | ||||
|     use RelationAttribut,MembershipsAttribut, LawAttribut; | ||||
|     use RelationAttribut,MembershipsAttribut, LawAttribut,SlugAttribut; | ||||
|  | ||||
|     /** | ||||
|      * System slugs should be writen in UPPER CASES | ||||
|      * Slugs which are defined by the user are checked via the assert. | ||||
|      * | ||||
|      * @ORM\Column(type="string",length=30,nullable=true,unique=true) | ||||
|      * @Assert\Regex(pattern="/^[a-z]+$/") | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $slug; | ||||
|  | ||||
|     /** | ||||
|      * @var RelationInterface | ||||
|   | ||||
| @@ -7,10 +7,11 @@ use App\Entity\EntityInterface; | ||||
| use App\Entity\Attribut\LawAttributInterface; | ||||
| use App\Entity\Attribut\RelationAttributInterface; | ||||
| use App\Entity\Attribut\MembershipsAttributInterface; | ||||
| use App\Entity\Attribut\SlugAttributInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, RelationAttributInterface | ||||
| interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, RelationAttributInterface, SlugAttributInterface | ||||
| { | ||||
| } | ||||
|   | ||||
							
								
								
									
										38
									
								
								application/tests/Unit/Entity/Attribut/SlugAttributTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								application/tests/Unit/Entity/Attribut/SlugAttributTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Entity\Attribut; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Entity\Attribut\SlugAttributInterface; | ||||
| use App\Entity\Attribut\SlugAttribut; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class SlugAttributTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @var SlugAttributInterface | ||||
|      */ | ||||
|     protected $slugAttribut; | ||||
|  | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         $this->slugAttribut = new class() implements SlugAttributInterface { | ||||
|             use SlugAttribut; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function testConstructor(): void | ||||
|     { | ||||
|         $this->expectException(\TypeError::class); | ||||
|         $this->slugAttribut->getSlug(); | ||||
|     } | ||||
|  | ||||
|     public function testAccessors(): void | ||||
|     { | ||||
|         $slug = 'goodslug'; | ||||
|         $this->assertNull($this->slugAttribut->setSlug($slug)); | ||||
|         $this->assertEquals($slug, $this->slugAttribut->getSlug()); | ||||
|     } | ||||
| } | ||||
| @@ -33,4 +33,10 @@ class AbstractSourceTest extends TestCase | ||||
|         $this->assertInstanceOf(Collection::class, $this->source->getMemberships()); | ||||
|         $this->assertInstanceOf(LawInterface::class, $this->source->getLaw()); | ||||
|     } | ||||
|  | ||||
|     public function testSlugInit(): void | ||||
|     { | ||||
|         $this->expectException(\TypeError::class); | ||||
|         $this->source->getSlug(); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user