2019-03-31 16:59:46 +02:00
|
|
|
<?php
|
|
|
|
|
2019-05-30 16:10:09 +02:00
|
|
|
namespace tests\Integration\Domain\Fixture;
|
2019-03-31 16:59:46 +02:00
|
|
|
|
|
|
|
use Infinito\DBAL\Types\ActionType;
|
2020-04-02 21:13:35 +02:00
|
|
|
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
|
|
|
use Infinito\Domain\Fixture\EntityTemplateFactory;
|
2019-05-30 16:15:46 +02:00
|
|
|
use Infinito\Domain\Law\LawPermissionChecker;
|
2020-04-02 21:13:35 +02:00
|
|
|
use Infinito\Entity\Meta\Right;
|
|
|
|
use Infinito\Entity\Source\AbstractSource;
|
|
|
|
use Infinito\Entity\Source\Complex\UserSource;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-03-31 16:59:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|