mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 05:47:11 +02:00
Implemented draft for ActionManagement
This commit is contained in:
@@ -10,7 +10,7 @@ use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class RequestAttributTest extends TestCase
|
||||
class LayerRepositoryFactoryServiceAttributTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var LayerRepositoryFactoryServiceAttributInterface
|
||||
|
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
use App\DBAL\Types\Meta\Right\LayerType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Domain\ActionManagement\ActionFactoryServiceInterface;
|
||||
use App\Domain\ActionManagement\ActionFactoryService;
|
||||
use App\Domain\ActionManagement\ActionServiceInterface;
|
||||
use App\DBAL\Types\ActionType;
|
||||
use App\Domain\ActionManagement\ActionInterface;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ActionFactoryServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ActionFactoryServiceInterface
|
||||
*/
|
||||
private $actionFactoryService;
|
||||
|
||||
/**
|
||||
* @var ActionServiceInterface
|
||||
*/
|
||||
private $actionService;
|
||||
|
||||
/**
|
||||
* @var RequestedActionInterface
|
||||
*/
|
||||
private $requestedAction;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
$this->requestedAction = $this->createMock(RequestedActionInterface::class);
|
||||
$this->actionService = $this->createMock(ActionServiceInterface::class);
|
||||
$this->actionService->method('getRequestedAction')->willReturn($this->requestedAction);
|
||||
$this->actionFactoryService = new ActionFactoryService($this->actionService);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
foreach (ActionType::getChoices() as $action) {
|
||||
foreach (LayerType::getChoices() as $layer) {
|
||||
$this->requestedAction->method('getLayer')->willReturn($layer);
|
||||
$this->requestedAction->method('getActionType')->willReturn($action);
|
||||
$action = $this->actionFactoryService->create();
|
||||
$this->assertInstanceOf(ActionInterface::class, $action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,26 +6,71 @@ use PHPUnit\Framework\TestCase;
|
||||
use App\Domain\ActionManagement\ActionService;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Domain\FormManagement\EntityFormBuilderServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use App\Domain\ActionManagement\ActionServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ActionServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var RequestedActionInterface
|
||||
*/
|
||||
private $requestedAction;
|
||||
|
||||
/**
|
||||
* @var SecureRequestedRightCheckerInterface
|
||||
*/
|
||||
private $secureRequestedRightChecker;
|
||||
|
||||
/**
|
||||
* @var EntityFormBuilderServiceInterface
|
||||
*/
|
||||
private $entityFormBuilderService;
|
||||
|
||||
/**
|
||||
* @var RequestStack
|
||||
*/
|
||||
private $requestStack;
|
||||
|
||||
/**
|
||||
* @var LayerRepositoryFactoryServiceInterface
|
||||
*/
|
||||
private $layerRepositoryFactoryService;
|
||||
|
||||
/**
|
||||
* @var ActionServiceInterface
|
||||
*/
|
||||
private $actionService;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->requestedAction = $this->createMock(RequestedActionInterface::class);
|
||||
$this->secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
|
||||
$this->entityFormBuilderService = $this->createMock(EntityFormBuilderServiceInterface::class);
|
||||
$this->requestStack = $this->createMock(RequestStack::class);
|
||||
$this->layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
$this->entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$this->actionService = new ActionService($this->requestedAction, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->entityFormBuilderService, $this->entityManager);
|
||||
}
|
||||
|
||||
public function testIsRequestedActionSecure()
|
||||
{
|
||||
$requestedAction = $this->createMock(RequestedActionInterface::class);
|
||||
$secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
|
||||
$secureRequestedRightChecker->method('check')->willReturn(true);
|
||||
$actionService = new ActionService($requestedAction, $secureRequestedRightChecker);
|
||||
$this->assertTrue($actionService->isRequestedActionSecure());
|
||||
$this->secureRequestedRightChecker->method('check')->willReturn(true);
|
||||
$this->assertTrue($this->actionService->isRequestedActionSecure());
|
||||
}
|
||||
|
||||
public function testRequestedActionGetter()
|
||||
{
|
||||
$requestedAction = $this->createMock(RequestedActionInterface::class);
|
||||
$secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
|
||||
$actionService = new ActionService($requestedAction, $secureRequestedRightChecker);
|
||||
$this->assertInstanceOf(RequestedActionInterface::class, $actionService->getRequestedAction());
|
||||
$this->assertInstanceOf(RequestedActionInterface::class, $this->actionService->getRequestedAction());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\SecureCRUDManagement\CRUD\Read;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Domain\ActionManagement\Read\ReadAction;
|
||||
use App\Domain\ActionManagement\ActionServiceInterface;
|
||||
use App\Domain\ActionManagement\Read\ReadActionInterface;
|
||||
use App\Exception\NotSecureException;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ReadSourceActionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var ActionServiceInterface
|
||||
*/
|
||||
private $actionService;
|
||||
|
||||
/**
|
||||
* @var ReadActionInterface
|
||||
*/
|
||||
private $sourceReadAction;
|
||||
|
||||
/**
|
||||
* @var RequestedEntityInterface
|
||||
*/
|
||||
private $requestedEntity;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $entity;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->entity = $this->createMock(SourceInterface::class);
|
||||
$this->requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
$this->requestedEntity->method('getEntity')->willReturn($this->entity);
|
||||
$this->entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$this->requestedAction = $this->createMock(RequestedActionInterface::class);
|
||||
$this->requestedAction->method('getRequestedEntity')->willReturn($this->requestedEntity);
|
||||
$this->actionService = $this->createMock(ActionServiceInterface::class);
|
||||
$this->actionService->method('getEntityManager')->willReturn($this->entityManager);
|
||||
$this->actionService->method('getRequestedAction')->willReturn($this->requestedAction);
|
||||
$this->sourceReadAction = new ReadAction($this->actionService);
|
||||
}
|
||||
|
||||
public function testNotSecureException(): void
|
||||
{
|
||||
$this->actionService->method('isRequestedActionSecure')->willReturn(false);
|
||||
$this->expectException(NotSecureException::class);
|
||||
$this->sourceReadAction->execute();
|
||||
}
|
||||
|
||||
public function testGranted(): void
|
||||
{
|
||||
$this->actionService->method('isRequestedActionSecure')->willReturn(true);
|
||||
$result = $this->sourceReadAction->execute();
|
||||
$this->assertEquals($this->entity, $result);
|
||||
}
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Unit\Domain\ResponseManagement;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Entity\Meta\Right;
|
||||
use FOS\RestBundle\View\ViewHandlerInterface;
|
||||
use App\Entity\Source\PureSource;
|
||||
use App\DBAL\Types\SystemSlugType;
|
||||
use App\DBAL\Types\Meta\Right\LayerType;
|
||||
use App\DBAL\Types\Meta\Right\CRUDType;
|
||||
use App\Domain\ResponseManagement\SourceRESTResponseManager;
|
||||
use App\Exception\AllreadyDefinedException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement more tests!
|
||||
*/
|
||||
class SourceRESTReponseManagerTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var RightInterface
|
||||
*/
|
||||
private $requestedRight;
|
||||
|
||||
/**
|
||||
* @var ViewHandlerInterface
|
||||
*/
|
||||
private $viewHandler;
|
||||
|
||||
private function setRequestedRight(): void
|
||||
{
|
||||
$this->requestedRight = new Right();
|
||||
}
|
||||
|
||||
private function setEntityManager(): void
|
||||
{
|
||||
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
||||
}
|
||||
|
||||
private function setViewHandler(): void
|
||||
{
|
||||
$this->viewHandler = $this->createMock(ViewHandlerInterface::class);
|
||||
}
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->setEntityManager();
|
||||
$this->setRequestedRight();
|
||||
$this->setViewHandler();
|
||||
}
|
||||
|
||||
public function testAllreadyDefinedException(): void
|
||||
{
|
||||
$requestedSource = new PureSource();
|
||||
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||
$requestedRight = new Right();
|
||||
$requestedRight->setSource($requestedSource);
|
||||
$requestedRight->setReciever(new PureSource());
|
||||
$requestedRight->setLayer(LayerType::SOURCE);
|
||||
$requestedRight->setCrud(CRUDType::READ);
|
||||
$this->expectException(AllreadyDefinedException::class);
|
||||
$sourceResponseManager = new SourceRESTResponseManager(null, $this->entityManager, $requestedRight, $this->viewHandler);
|
||||
$sourceResponseManager->getResponse();
|
||||
}
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\SecureCRUDManagement\CRUD\Read;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use App\Entity\Source\Primitive\Text\TextSource;
|
||||
use App\DBAL\Types\SystemSlugType;
|
||||
use App\Entity\Meta\Right;
|
||||
use App\DBAL\Types\Meta\Right\LayerType;
|
||||
use App\DBAL\Types\Meta\Right\CRUDType;
|
||||
use App\Entity\Source\Complex\UserSource;
|
||||
use App\Entity\Source\Primitive\Text\TextSourceInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Domain\SecureCRUDManagement\CRUD\Read\SecureSourceReadService;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement more tests
|
||||
*/
|
||||
class SecureSourceReadServiceTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectRepository
|
||||
*/
|
||||
private $sourceRepository;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var SecureSourceReadService
|
||||
*/
|
||||
private $secureSourceReadService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$requestStack = self::$container->get('request_stack');
|
||||
$security = new Security(self::$kernel->getContainer());
|
||||
$entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
||||
$this->secureSourceReadService = new SecureSourceReadService($requestStack, $security, $entityManager);
|
||||
}
|
||||
|
||||
public function testAccessDeniedException(): void
|
||||
{
|
||||
$requestedSource = new TextSource();
|
||||
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||
$requestedRight = new Right();
|
||||
$requestedRight->setSource($requestedSource);
|
||||
$requestedRight->setLayer(LayerType::SOURCE);
|
||||
$requestedRight->setCrud(CRUDType::READ);
|
||||
$requestedRight->setReciever(new UserSource());
|
||||
$this->expectException(AccessDeniedHttpException::class);
|
||||
$this->secureSourceReadService->read($requestedRight);
|
||||
}
|
||||
|
||||
public function testGranted(): void
|
||||
{
|
||||
$requestedSource = new TextSource();
|
||||
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||
$requestedRight = new Right();
|
||||
$requestedRight->setSource($requestedSource);
|
||||
$requestedRight->setLayer(LayerType::SOURCE);
|
||||
$requestedRight->setCrud(CRUDType::READ);
|
||||
$requestedRight->setReciever($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
|
||||
$textSourceResponse = $this->secureSourceReadService->read($requestedRight);
|
||||
$this->assertInstanceOf(TextSourceInterface::class, $textSourceResponse);
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryService;
|
||||
use App\DBAL\Types\Meta\Right\LayerType;
|
||||
use App\Entity\Meta\Right;
|
||||
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
|
||||
use App\DBAL\Types\Meta\Right\CRUDType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class SecureCRUDFactoryServiceTest extends KernelTestCase
|
||||
{
|
||||
const EXCLUDED_TYPES = [
|
||||
CRUDType::CREATE => [
|
||||
LayerType::LAW,
|
||||
],
|
||||
CRUDType::DELETE => [
|
||||
LayerType::LAW,
|
||||
],
|
||||
CRUDType::READ => [],
|
||||
CRUDType::UPDATE => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* @var SecureCRUDFactoryServiceInterface
|
||||
*/
|
||||
private $secureCRUDFactoryService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$requestStack = self::$container->get('request_stack');
|
||||
$security = new Security(self::$kernel->getContainer());
|
||||
$entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
||||
$this->secureCRUDFactoryService = new SecureCRUDFactoryService($requestStack, $security, $entityManager);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
foreach (CRUDType::getChoices() as $crud) {
|
||||
foreach (LayerType::getChoices() as $layer) {
|
||||
if (!in_array($layer, self::EXCLUDED_TYPES[$crud])) {
|
||||
$requestedRight = new Right();
|
||||
$requestedRight->setLayer($layer);
|
||||
$requestedRight->setCrud($crud);
|
||||
$secureCreator = $this->secureCRUDFactoryService->create($requestedRight);
|
||||
$this->assertInstanceOf(SecureCRUDServiceInterface::class, $secureCreator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user