mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Renamed domain ActionManagement to Action
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\Action;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\Action\ActionFactoryService;
|
||||
use Infinito\Domain\Action\ActionDependenciesDAOServiceInterface;
|
||||
use Infinito\Domain\Action\ActionInterface;
|
||||
use Infinito\Domain\RequestManagement\Action\RequestedAction;
|
||||
use Infinito\Domain\RequestManagement\Right\RequestedRight;
|
||||
use Infinito\Domain\LayerManagement\LayerActionMap;
|
||||
use Infinito\Domain\RequestManagement\User\RequestedUser;
|
||||
use Infinito\Domain\UserManagement\UserSourceDirectorInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ActionFactoryServiceTest extends TestCase
|
||||
{
|
||||
public function testCreate(): void
|
||||
{
|
||||
foreach (LayerActionMap::LAYER_ACTION_MAP as $layer => $actions) {
|
||||
foreach ($actions as $action) {
|
||||
$requestedRight = new RequestedRight();
|
||||
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
|
||||
$requestedUser = new RequestedUser($userSourceDirector, $requestedRight);
|
||||
$requestedAction = new RequestedAction($requestedUser);
|
||||
$actionService = $this->createMock(ActionDependenciesDAOServiceInterface::class);
|
||||
$actionService->method('getRequestedAction')->willReturn($requestedAction);
|
||||
$actionFactoryService = new ActionFactoryService($actionService);
|
||||
$requestedAction->setLayer($layer);
|
||||
$requestedAction->setActionType($action);
|
||||
$result = $actionFactoryService->create();
|
||||
$this->assertInstanceOf(ActionInterface::class, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\Action;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\Action\ActionDependenciesDAOService;
|
||||
use Infinito\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Infinito\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use Infinito\Domain\Action\ActionDependenciesDAOServiceInterface;
|
||||
use Infinito\Repository\RepositoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Infinito\Entity\EntityInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Infinito\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
|
||||
use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
||||
use Infinito\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ActionServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var RequestedActionServiceInterface|MockObject
|
||||
*/
|
||||
private $requestedActionService;
|
||||
|
||||
/**
|
||||
* @var SecureRequestedRightCheckerServiceInterface
|
||||
*/
|
||||
private $secureRequestedRightCheckerService;
|
||||
|
||||
/**
|
||||
* @var RequestedActionFormBuilderServiceInterface|MockObject
|
||||
*/
|
||||
private $requestedActionFormBuilderService;
|
||||
|
||||
/**
|
||||
* @var RequestStack|MockObject
|
||||
*/
|
||||
private $requestStack;
|
||||
|
||||
/**
|
||||
* @var LayerRepositoryFactoryServiceInterface|MockObject
|
||||
*/
|
||||
private $layerRepositoryFactoryService;
|
||||
|
||||
/**
|
||||
* @var ActionDependenciesDAOServiceInterface
|
||||
*/
|
||||
private $actionService;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface|MockObject
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var RequestedEntityInterface|MockObject
|
||||
*/
|
||||
private $requestedEntity;
|
||||
|
||||
/**
|
||||
* @var EntityInterface|MockObject
|
||||
*/
|
||||
private $entity;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->entity = $this->createMock(EntityInterface::class);
|
||||
|
||||
$this->requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
$this->requestedEntity->method('getEntity')->willReturn($this->entity);
|
||||
|
||||
$this->requestedActionService = $this->createMock(RequestedActionServiceInterface::class);
|
||||
$this->requestedActionService->method('getRequestedEntity')->willReturn($this->requestedEntity);
|
||||
|
||||
$this->secureRequestedRightCheckerService = $this->createMock(SecureRequestedRightCheckerServiceInterface::class);
|
||||
$this->requestedActionFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
|
||||
$this->requestStack = $this->createMock(RequestStack::class);
|
||||
$this->layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
$this->entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$this->actionService = new ActionDependenciesDAOService($this->requestedActionService, $this->secureRequestedRightCheckerService, $this->requestStack, $this->layerRepositoryFactoryService, $this->requestedActionFormBuilderService, $this->entityManager);
|
||||
}
|
||||
|
||||
public function testIsRequestedActionSecure(): void
|
||||
{
|
||||
$this->secureRequestedRightCheckerService->method('check')->willReturn(true);
|
||||
$this->assertTrue($this->actionService->isRequestedActionSecure());
|
||||
}
|
||||
|
||||
public function testRequestedActionGetter(): void
|
||||
{
|
||||
$this->assertInstanceOf(RequestedActionInterface::class, $this->actionService->getRequestedAction());
|
||||
}
|
||||
|
||||
public function testGetEntityManager(): void
|
||||
{
|
||||
$this->assertEquals($this->entityManager, $this->actionService->getEntityManager());
|
||||
}
|
||||
|
||||
public function testGetRepository(): void
|
||||
{
|
||||
$repository = $this->createMock(RepositoryInterface::class);
|
||||
$this->layerRepositoryFactoryService->method('getRepository')->willReturn($repository);
|
||||
$result = $this->actionService->getRepository();
|
||||
$this->assertEquals($repository, $result);
|
||||
}
|
||||
|
||||
public function testGetRequest(): void
|
||||
{
|
||||
$request = $this->createMock(Request::class);
|
||||
$this->requestStack->method('getCurrentRequest')->willReturn($request);
|
||||
$result = $this->actionService->getRequest();
|
||||
$this->assertEquals($request, $result);
|
||||
}
|
||||
|
||||
public function testGetCurrentFormBuilder(): void
|
||||
{
|
||||
$form = $this->createMock(FormBuilderInterface::class);
|
||||
$this->requestedActionFormBuilderService->method('createByService')->willReturn($form);
|
||||
$result = $this->actionService->getCurrentFormBuilder();
|
||||
$this->assertEquals($form, $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\Action\Create;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\Action\Create\CreateSourceAction;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Infinito\Entity\Source\PureSource;
|
||||
use Infinito\Attribut\ClassAttributInterface;
|
||||
use Infinito\Attribut\SlugAttributInterface;
|
||||
use Infinito\Entity\Source\PureSourceInterface;
|
||||
use Infinito\Domain\Action\ActionService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
||||
use Infinito\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Infinito\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use Infinito\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class CreateSourceActionTest extends TestCase
|
||||
{
|
||||
// public function testCreatePureSource(): void
|
||||
// {
|
||||
// $request = new Request();
|
||||
// $request->setMethod(Request::METHOD_POST);
|
||||
// $request->query->set(ClassAttributInterface::CLASS_ATTRIBUT_NAME, PureSource::class);
|
||||
// $request->request->set(SlugAttributInterface::SLUG_ATTRIBUT_NAME, 'randomname');
|
||||
// $requestedActionService = $this->createMock(RequestedActionServiceInterface::class);
|
||||
// $secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerServiceInterface::class);
|
||||
// $entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
// $pureSourceType = $this->createMock(PureSourceTypeInterface::class);
|
||||
// $pureSourceType->method('isValid')->willReturn(true);
|
||||
// $formBuilderInterface = $this->createMock(FormBuilderInterface::class);
|
||||
// $formBuilderInterface->method('getForm')->willReturn($pureSourceType);
|
||||
// // $formBuilderInterface->method('isValid')->willReturn(true);
|
||||
// $requestedActionFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
|
||||
// $requestedActionFormBuilderService->method('createByService')->willReturn($formBuilderInterface);
|
||||
// $requestStack = $this->createMock(RequestStack::class);
|
||||
// $requestStack->method('getCurrentRequest')->willReturn($request);
|
||||
// $layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
// $actionService = new ActionService($requestedActionService, $secureRequestedRightChecker, $requestStack, $layerRepositoryFactoryService, $requestedActionFormBuilderService, $entityManager);
|
||||
// $createSourceAction = new CreateSourceAction($actionService);
|
||||
// $result = $createSourceAction->execute();
|
||||
// $this->assertInstanceOf(PureSourceInterface::class, $result);
|
||||
// }
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\Action\Read;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\Action\ActionInterface;
|
||||
use Infinito\Domain\Action\AbstractAction;
|
||||
use Infinito\Domain\Action\ActionDependenciesDAOServiceInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Infinito\Exception\Validation\FormInvalidException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class AbstractActionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ActionInterface
|
||||
*/
|
||||
private $action;
|
||||
|
||||
/**
|
||||
* @var ActionDependenciesDAOServiceInterface|MockObject
|
||||
*/
|
||||
private $actionService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->actionService = $this->createMock(ActionDependenciesDAOServiceInterface::class);
|
||||
$this->action = new class($this->actionService) extends AbstractAction {
|
||||
public $isSecure;
|
||||
public $validByForm;
|
||||
|
||||
protected function isSecure(): bool
|
||||
{
|
||||
return $this->isSecure;
|
||||
}
|
||||
|
||||
protected function isValid(): bool
|
||||
{
|
||||
return $this->validByForm;
|
||||
}
|
||||
|
||||
protected function proccess()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public function testNotValidByFormException(): void
|
||||
{
|
||||
$this->action->isSecure = true;
|
||||
$this->action->validByForm = false;
|
||||
$this->expectException(FormInvalidException::class);
|
||||
$this->action->execute();
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\SecureCRUDManagement\CRUD\Read;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\Action\Read\ReadAction;
|
||||
use Infinito\Domain\Action\ActionDependenciesDAOServiceInterface;
|
||||
use Infinito\Domain\Action\Read\ReadActionInterface;
|
||||
use Infinito\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Exception\Permission\NoPermissionException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class ReadSourceActionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var ActionDependenciesDAOServiceInterface
|
||||
*/
|
||||
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(ActionDependenciesDAOServiceInterface::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(NoPermissionException::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