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:
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user