mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Implemented tests for EntityDomService and refactored code
This commit is contained in:
parent
70a117c927
commit
62aaa2d686
@ -2,6 +2,11 @@
|
||||
|
||||
namespace Infinito\Attribut;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @see TextAttributInterface
|
||||
*/
|
||||
trait TextAttribut
|
||||
{
|
||||
/**
|
||||
@ -9,11 +14,17 @@ trait TextAttribut
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getText(): string
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText(string $text): void
|
||||
{
|
||||
$this->text = $text;
|
||||
|
@ -9,6 +9,11 @@ use Infinito\Entity\UserInterface;
|
||||
*/
|
||||
interface UserAttributInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const USER_ATTRIBUT_NAME = 'user';
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
*/
|
||||
|
@ -120,15 +120,12 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
{
|
||||
foreach (LayerInterfaceMap::getAllInterfaces() as $layer => $interface) {
|
||||
if ($value instanceof $interface) {
|
||||
$domElement->setAttribute('layer', $layer);
|
||||
$domElement->setAttribute('id', $value->getId());
|
||||
$domElement->setAttribute('name', LayerType::getReadableValue($layer));
|
||||
$this->setLayerDomElement($domElement, $layer, $value);
|
||||
|
||||
return;
|
||||
}
|
||||
if ($value instanceof UserInterface) {
|
||||
$domElement->setAttribute('value', $value->getId());
|
||||
$domElement->setAttribute('name', 'user');
|
||||
$this->setUserDomElement($domElement, $value);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -142,6 +139,27 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
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 $propertyName
|
||||
|
@ -21,6 +21,9 @@ use Infinito\Entity\EntityInterface;
|
||||
use Infinito\Attribut\VersionAttribut;
|
||||
use Infinito\Attribut\IdAttribut;
|
||||
use Infinito\Exception\NotCorrectInstanceException;
|
||||
use Infinito\Entity\Source\Complex\UserSource;
|
||||
use Infinito\Entity\User;
|
||||
use Infinito\Attribut\UserAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -66,6 +69,27 @@ class EntityDomServiceTest extends TestCase
|
||||
$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
|
||||
{
|
||||
$slug = 'test';
|
||||
|
Loading…
Reference in New Issue
Block a user