mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Implemented slug for sources
This commit is contained in:
parent
84c2de2283
commit
baca225775
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 Doctrine\Common\Collections\ArrayCollection;
|
||||||
use App\Entity\Attribut\MembershipsAttribut;
|
use App\Entity\Attribut\MembershipsAttribut;
|
||||||
use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface;
|
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
|
* @author kevinfrantz
|
||||||
@ -24,10 +27,22 @@ use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface;
|
|||||||
* @ORM\InheritanceType("JOINED")
|
* @ORM\InheritanceType("JOINED")
|
||||||
* @ORM\DiscriminatorColumn(name="discr", type="string")
|
* @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"})
|
* @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
|
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
|
* @var RelationInterface
|
||||||
|
@ -7,10 +7,11 @@ use App\Entity\EntityInterface;
|
|||||||
use App\Entity\Attribut\LawAttributInterface;
|
use App\Entity\Attribut\LawAttributInterface;
|
||||||
use App\Entity\Attribut\RelationAttributInterface;
|
use App\Entity\Attribut\RelationAttributInterface;
|
||||||
use App\Entity\Attribut\MembershipsAttributInterface;
|
use App\Entity\Attribut\MembershipsAttributInterface;
|
||||||
|
use App\Entity\Attribut\SlugAttributInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @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(Collection::class, $this->source->getMemberships());
|
||||||
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
|
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSlugInit(): void
|
||||||
|
{
|
||||||
|
$this->expectException(\TypeError::class);
|
||||||
|
$this->source->getSlug();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user