Optimized dom management

This commit is contained in:
Kevin Frantz
2019-02-25 16:38:54 +01:00
parent 0b50b1df9a
commit be9e22577c
13 changed files with 259 additions and 9 deletions

View File

@@ -11,6 +11,16 @@ use Infinito\Attribut\SlugAttributInterface;
use Infinito\Attribut\IdAttributInterface;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Attribut\VersionAttributInterface;
use Infinito\Entity\Meta\Law;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Attribut\SourceAttributInterface;
use Infinito\Attribut\GrantAttributInterface;
use Infinito\Attribut\RightsAttributInterface;
use Infinito\Entity\EntityInterface;
use Infinito\Attribut\VersionAttribut;
use Infinito\Attribut\IdAttribut;
use Infinito\Exception\NotCorrectInstanceException;
/**
* @author kevinfrantz
@@ -33,6 +43,29 @@ class EntityDomServiceTest extends TestCase
$this->entityDomService = new EntityDomService($this->requestedEntityService);
}
public function testNotCorrectInstanceException(): void
{
$entity = new class() implements EntityInterface {
use VersionAttribut,IdAttribut;
private $test;
public function setTest($test): void
{
$this->test = $test;
}
public function getTest()
{
return $this->test;
}
};
$entity->setTest(new class() {
});
$this->requestedEntityService->method('getEntity')->willReturn($entity);
$this->expectException(NotCorrectInstanceException::class);
$this->entityDomService->getDomDocument();
}
public function testAbstractSource(): void
{
$slug = 'test';
@@ -66,4 +99,56 @@ class EntityDomServiceTest extends TestCase
}
}
}
public function testLaw(): void
{
$source = $this->createMock(SourceInterface::class);
$source->method('getId')->willReturn(123);
$source->method('hasId')->willReturn(true);
$right = $this->createMock(RightInterface::class);
$right->method('getId')->willReturn(124);
$right->method('hasId')->willReturn(true);
$id = 12345;
$law = new Law();
$law->setId($id);
$law->setSource($source);
$law->getRights()->add($right);
$law->getRights()->add(clone $right);
$law->getRights()->add(clone $right);
$this->requestedEntityService->method('getEntity')->willReturn($law);
$result = $this->entityDomService->getDomDocument();
foreach ($result->childNodes as $attribut) {
$name = $attribut->getAttribute('name');
$value = $attribut->getAttribute('value');
$id = $attribut->getAttribute('id');
$layer = $attribut->getAttribute('layer');
$type = $attribut->getAttribute('type');
switch ($name) {
case IdAttributInterface::ID_ATTRIBUT_NAME:
$this->assertGreaterThan(0, $value);
break;
case VersionAttributInterface::VERSION_ATTRIBUT_NAME:
$this->assertGreaterThan(-1, $value);
break;
case SourceAttributInterface::SOURCE_ATTRIBUT_NAME:
$this->assertGreaterThan(0, $id);
$this->assertEquals(LayerType::SOURCE, $layer);
break;
case GrantAttributInterface::GRANT_ATTRIBUT_NAME:
$this->assertEquals('', $value);
$this->assertEquals('boolean', $type);
break;
case RightsAttributInterface::RIGHTS_ATTRIBUT_NAME:
$rights = $attribut->childNodes;
$this->assertCount(3, $rights);
foreach ($rights as $rightAttribut) {
$this->assertEquals(LayerType::RIGHT, $rightAttribut->getAttribute('layer'));
$this->assertGreaterThan(0, $rightAttribut->getAttribute('id'));
}
break;
default:
throw new \Exception("No assert was defined for attribut with name <<$name>>!");
}
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace tests\Unit\Domain\LayerManagement;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\LayerManagement\LayerInterfaceMap;
/**
* @author kevinfrantz
*/
class LayerInterfaceMapTest extends TestCase
{
public function testIfInterfaceForEachLayerExist(): void
{
foreach (LayerInterfaceMap::getAllInterfaces() as $interface) {
$this->assertTrue(interface_exists($interface));
}
}
}