In between commit implementing EntityDomServiceTest

This commit is contained in:
Kevin Frantz 2019-02-25 14:34:55 +01:00
parent 608b00794b
commit 0b50b1df9a
7 changed files with 107 additions and 1 deletions

View File

@ -4,6 +4,11 @@ namespace Infinito\Attribut;
use Infinito\Entity\Meta\Relation\Parent\CreatorRelationInterface;
/**
* @author kevinfrantz
*
* @see CreatorRelationAttributInterface
*/
trait CreatorRelationAttribut
{
/**
@ -11,11 +16,17 @@ trait CreatorRelationAttribut
*/
protected $creatorRelation;
/**
* @param CreatorRelationInterface $creatorRelation
*/
public function setCreatorRelation(CreatorRelationInterface $creatorRelation)
{
$this->creatorRelation = $creatorRelation;
}
/**
* @return CreatorRelationInterface
*/
public function getCreatorRelation(): CreatorRelationInterface
{
return $this->creatorRelation;

View File

@ -4,9 +4,20 @@ namespace Infinito\Attribut;
use Infinito\Entity\Meta\Relation\Parent\CreatorRelationInterface;
/**
* @author kevinfrantz
*/
interface CreatorRelationAttributInterface
{
const CREATORRELATION_ATTRIBUT_NAME = 'creatorRelation';
/**
* @param CreatorRelationInterface $creatorRelation
*/
public function setCreatorRelation(CreatorRelationInterface $creatorRelation);
/**
* @return CreatorRelationInterface
*/
public function getCreatorRelation(): CreatorRelationInterface;
}

View File

@ -7,6 +7,8 @@ namespace Infinito\Attribut;
*/
interface IdAttributInterface
{
const ID_ATTRIBUT_NAME = 'id';
/**
* @param int $id
*/

View File

@ -4,6 +4,8 @@ namespace Infinito\Attribut;
/**
* @author kevinfrantz
*
* @see VersionAttributInterface
*/
trait VersionAttribut
{
@ -12,11 +14,17 @@ trait VersionAttribut
*/
protected $version;
/**
* @param int $version
*/
public function setVersion(int $version): void
{
$this->version = $version;
}
/**
* @return int
*/
public function getVersion(): int
{
return $this->version;

View File

@ -12,6 +12,11 @@ namespace Infinito\Attribut;
*/
interface VersionAttributInterface
{
/**
* @var string
*/
const VERSION_ATTRIBUT_NAME = 'version';
/**
* Returns the revision version of the entity.
*

View File

@ -121,8 +121,8 @@ final class EntityDomService implements EntityDomServiceInterface
if ($value instanceof $class) {
$domElement->setAttribute('layer', $layer);
$domElement->setAttribute('id', $value->getId());
$domElement->setAttribute('value', $value->getId());
$domElement->setAttribute('name', LayerType::getReadableValue($layer));
return;
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace tests\Unit\Domain\DomManagement;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\DomManagement\EntityDomServiceInterface;
use Infinito\Domain\RequestManagement\Entity\RequestedEntityServiceInterface;
use Infinito\Domain\DomManagement\EntityDomService;
use Infinito\Entity\Source\AbstractSource;
use Infinito\Attribut\SlugAttributInterface;
use Infinito\Attribut\IdAttributInterface;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Attribut\VersionAttributInterface;
/**
* @author kevinfrantz
*/
class EntityDomServiceTest extends TestCase
{
/**
* @var EntityDomServiceInterface
*/
private $entityDomService;
/**
* @var RequestedEntityServiceInterface
*/
private $requestedEntityService;
public function setUp(): void
{
$this->requestedEntityService = $this->createMock(RequestedEntityServiceInterface::class);
$this->entityDomService = new EntityDomService($this->requestedEntityService);
}
public function testAbstractSource(): void
{
$slug = 'test';
$id = 12345;
$source = new class() extends AbstractSource {
};
$source->setSlug($slug);
$source->setId($id);
$source->getCreatorRelation()->setId(1);
$source->getMemberRelation()->setId(2);
$source->getLaw()->setId(3);
$this->requestedEntityService->method('getEntity')->willReturn($source);
$result = $this->entityDomService->getDomDocument();
$expectedAttributNames = [
SlugAttributInterface::SLUG_ATTRIBUT_NAME,
IdAttributInterface::ID_ATTRIBUT_NAME,
VersionAttributInterface::VERSION_ATTRIBUT_NAME,
LayerType::getReadableValue(LayerType::MEMBER),
LayerType::getReadableValue(LayerType::LAW),
// LayerType::getReadableValue(LayerType::HEREDITY),
LayerType::getReadableValue(LayerType::CREATOR),
];
$this->assertEquals(count($expectedAttributNames), count($result->childNodes));
foreach ($result->childNodes as $attribut) {
$name = $attribut->getAttribute('name');
$layer = $attribut->getAttribute('layer');
$id = $attribut->getAttribute('id');
$this->assertTrue(in_array($name, $expectedAttributNames), "The attribut name <<$name>> is not defined in the expected values!");
if (in_array($layer, LayerType::getValues())) {
$this->assertGreaterThan(0, $id);
}
}
}
}