Optimized tests for fixture sources

This commit is contained in:
Kevin Frantz
2019-03-31 16:59:46 +02:00
parent 0115751e98
commit 108debf6bf
9 changed files with 89 additions and 16 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace tests\Integration\Domain\FixtureManagement;
use PHPUnit\Framework\TestCase;
use Infinito\Entity\Source\AbstractSource;
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
use Infinito\Entity\Source\Complex\UserSource;
use Infinito\Entity\Meta\Right;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\DBAL\Types\ActionType;
use Infinito\Domain\LawManagement\LawPermissionChecker;
/**
* @author kevinfrantz
*/
class EntityTemplateFactoryIntegrationTest extends TestCase
{
public function testStandartPublicRights(): void
{
$allowedActions = [ActionType::READ, ActionType::EXECUTE];
$allowedLayers = [LayerType::SOURCE];
$source = new class() extends AbstractSource {
};
$law = $source->getLaw();
$anonymUserSource = new UserSource();
EntityTemplateFactory::createStandartPublicRights($source);
$requestedRight = new Right();
$requestedRight->setReciever($anonymUserSource);
$lawPermissionChecker = new LawPermissionChecker($law);
foreach (LayerType::getValues() as $layerType) {
foreach (ActionType::getValues() as $actionType) {
$requestedRight->setActionType($actionType);
$requestedRight->setLayer($layerType);
$checkResult = $lawPermissionChecker->hasPermission($requestedRight);
if (in_array($actionType, $allowedActions) && in_array($layerType, $allowedLayers)) {
$this->assertTrue($checkResult);
} else {
$this->assertFalse($checkResult);
}
}
}
}
}

View File

@@ -10,7 +10,7 @@ use Infinito\Entity\Source\SourceInterface;
/**
* @author kevinfrantz
*/
class FixtureSourceFactoryTest extends TestCase
class FixtureSourceFactoryIntegrationTest extends TestCase
{
/**
* @var array|FixtureSourceInterface[]
@@ -39,12 +39,27 @@ class FixtureSourceFactoryTest extends TestCase
}
}
public function testFixtureSourcesIcons(): void
{
$icons = [];
foreach ($this->fixtureSources as $fixtureSource) {
$this->assertInstanceOf(FixtureSourceInterface::class, $fixtureSource);
$icon = $fixtureSource->getIcon();
$this->assertIsString($icon);
$this->assertFalse(in_array($icon, $icons), 'An icon has to be unique');
$icons[] = $icon;
}
}
/**
* The following test is redundant.
*/
public function testFixtureSourcesObjects(): void
{
$objects = [];
foreach ($this->fixtureSources as $fixtureSource) {
$this->assertInstanceOf(SourceInterface::class, $fixtureSource->getORMReadyObject());
$this->assertFalse(in_array($fixtureSource, $objects), 'A slug has to be unique');
$this->assertFalse(in_array($fixtureSource, $objects), 'A object has to be unique');
$objects[] = $fixtureSource;
}
}

View File

@@ -9,7 +9,7 @@ use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
/**
* @author kevinfrantz
*/
class ImprintFixtureSourceTest extends KernelTestCase
class ImprintFixtureSourceIntegrationTest extends KernelTestCase
{
/**
* {@inheritdoc}