mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-04-16 10:16:22 +02:00
Implemented tests for EntityDomService and refactored code
This commit is contained in:
parent
70a117c927
commit
62aaa2d686
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
namespace Infinito\Attribut;
|
namespace Infinito\Attribut;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
* @see TextAttributInterface
|
||||||
|
*/
|
||||||
trait TextAttribut
|
trait TextAttribut
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -9,11 +14,17 @@ trait TextAttribut
|
|||||||
*/
|
*/
|
||||||
protected $text;
|
protected $text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getText(): string
|
public function getText(): string
|
||||||
{
|
{
|
||||||
return $this->text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $text
|
||||||
|
*/
|
||||||
public function setText(string $text): void
|
public function setText(string $text): void
|
||||||
{
|
{
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
|
@ -9,6 +9,11 @@ use Infinito\Entity\UserInterface;
|
|||||||
*/
|
*/
|
||||||
interface UserAttributInterface
|
interface UserAttributInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public const USER_ATTRIBUT_NAME = 'user';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param UserInterface $user
|
* @param UserInterface $user
|
||||||
*/
|
*/
|
||||||
|
@ -120,15 +120,12 @@ final class EntityDomService implements EntityDomServiceInterface
|
|||||||
{
|
{
|
||||||
foreach (LayerInterfaceMap::getAllInterfaces() as $layer => $interface) {
|
foreach (LayerInterfaceMap::getAllInterfaces() as $layer => $interface) {
|
||||||
if ($value instanceof $interface) {
|
if ($value instanceof $interface) {
|
||||||
$domElement->setAttribute('layer', $layer);
|
$this->setLayerDomElement($domElement, $layer, $value);
|
||||||
$domElement->setAttribute('id', $value->getId());
|
|
||||||
$domElement->setAttribute('name', LayerType::getReadableValue($layer));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($value instanceof UserInterface) {
|
if ($value instanceof UserInterface) {
|
||||||
$domElement->setAttribute('value', $value->getId());
|
$this->setUserDomElement($domElement, $value);
|
||||||
$domElement->setAttribute('name', 'user');
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -142,6 +139,27 @@ final class EntityDomService implements EntityDomServiceInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \DOMElement $domElement
|
||||||
|
* @param string $layer
|
||||||
|
* @param EntityInterface $entity
|
||||||
|
*/
|
||||||
|
private function setLayerDomElement(\DOMElement $domElement, string $layer, EntityInterface $entity): void
|
||||||
|
{
|
||||||
|
$domElement->setAttribute('layer', $layer);
|
||||||
|
$domElement->setAttribute('id', $entity->getId());
|
||||||
|
$domElement->setAttribute('name', LayerType::getReadableValue($layer));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \DomElement $domElement
|
||||||
|
*/
|
||||||
|
private function setUserDomElement(\DomElement $domElement, \Infinito\Entity\UserInterface $user): void
|
||||||
|
{
|
||||||
|
$domElement->setAttribute('value', $user->getId());
|
||||||
|
$domElement->setAttribute('name', 'user');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param string $propertyName
|
* @param string $propertyName
|
||||||
|
@ -21,6 +21,9 @@ use Infinito\Entity\EntityInterface;
|
|||||||
use Infinito\Attribut\VersionAttribut;
|
use Infinito\Attribut\VersionAttribut;
|
||||||
use Infinito\Attribut\IdAttribut;
|
use Infinito\Attribut\IdAttribut;
|
||||||
use Infinito\Exception\NotCorrectInstanceException;
|
use Infinito\Exception\NotCorrectInstanceException;
|
||||||
|
use Infinito\Entity\Source\Complex\UserSource;
|
||||||
|
use Infinito\Entity\User;
|
||||||
|
use Infinito\Attribut\UserAttributInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -66,6 +69,27 @@ class EntityDomServiceTest extends TestCase
|
|||||||
$this->entityDomService->getDomDocument();
|
$this->entityDomService->getDomDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserSource(): void
|
||||||
|
{
|
||||||
|
$userSource = new UserSource();
|
||||||
|
$userId = 1234;
|
||||||
|
$user = new User();
|
||||||
|
$user->setId($userId);
|
||||||
|
$userSource->setUser($user);
|
||||||
|
$this->requestedEntityService->method('getEntity')->willReturn($userSource);
|
||||||
|
$result = $this->entityDomService->getDomDocument();
|
||||||
|
foreach ($result->childNodes as $attribut) {
|
||||||
|
$name = $attribut->getAttribute('name');
|
||||||
|
$value = $attribut->getAttribute('value');
|
||||||
|
if (UserAttributInterface::USER_ATTRIBUT_NAME === $name) {
|
||||||
|
$this->assertEquals($userId, $value);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertTrue(false, 'The user attribut was not defined!');
|
||||||
|
}
|
||||||
|
|
||||||
public function testAbstractSource(): void
|
public function testAbstractSource(): void
|
||||||
{
|
{
|
||||||
$slug = 'test';
|
$slug = 'test';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user