2019-01-27 09:35:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace tests\Unit\Domain\ActionManagement;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Domain\ActionManagement\ActionService;
|
|
|
|
use Infinito\Domain\RequestManagement\Action\RequestedActionInterface;
|
2019-01-27 15:28:25 +01:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
|
|
|
use Infinito\Domain\ActionManagement\ActionServiceInterface;
|
|
|
|
use Infinito\Repository\RepositoryInterface;
|
2019-01-27 16:06:17 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
2019-01-27 16:06:17 +01:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\EntityInterface;
|
2019-01-27 16:06:17 +01:00
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
|
|
|
|
use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
|
|
|
use Infinito\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
|
2019-01-27 09:35:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
|
|
|
class ActionServiceTest extends TestCase
|
|
|
|
{
|
2019-01-27 15:28:25 +01:00
|
|
|
/**
|
2019-02-13 15:47:46 +01:00
|
|
|
* @var RequestedActionServiceInterface|MockObject
|
2019-01-27 15:28:25 +01:00
|
|
|
*/
|
2019-02-13 15:47:46 +01:00
|
|
|
private $requestedActionService;
|
2019-01-27 15:28:25 +01:00
|
|
|
|
|
|
|
/**
|
2019-02-16 09:19:49 +01:00
|
|
|
* @var SecureRequestedRightCheckerServiceInterface
|
2019-01-27 15:28:25 +01:00
|
|
|
*/
|
2019-02-16 09:19:49 +01:00
|
|
|
private $secureRequestedRightCheckerService;
|
2019-01-27 15:28:25 +01:00
|
|
|
|
|
|
|
/**
|
2019-02-03 16:32:57 +01:00
|
|
|
* @var RequestedActionFormBuilderServiceInterface|MockObject
|
2019-01-27 15:28:25 +01:00
|
|
|
*/
|
2019-02-03 16:32:57 +01:00
|
|
|
private $requestedActionFormBuilderService;
|
2019-01-27 15:28:25 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-27 16:06:17 +01:00
|
|
|
* @var RequestStack|MockObject
|
2019-01-27 15:28:25 +01:00
|
|
|
*/
|
|
|
|
private $requestStack;
|
|
|
|
|
|
|
|
/**
|
2019-01-27 16:06:17 +01:00
|
|
|
* @var LayerRepositoryFactoryServiceInterface|MockObject
|
2019-01-27 15:28:25 +01:00
|
|
|
*/
|
|
|
|
private $layerRepositoryFactoryService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ActionServiceInterface
|
|
|
|
*/
|
|
|
|
private $actionService;
|
|
|
|
|
|
|
|
/**
|
2019-01-27 16:06:17 +01:00
|
|
|
* @var EntityManagerInterface|MockObject
|
2019-01-27 15:28:25 +01:00
|
|
|
*/
|
|
|
|
private $entityManager;
|
|
|
|
|
2019-01-27 16:06:17 +01:00
|
|
|
/**
|
|
|
|
* @var RequestedEntityInterface|MockObject
|
|
|
|
*/
|
|
|
|
private $requestedEntity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EntityInterface|MockObject
|
|
|
|
*/
|
|
|
|
private $entity;
|
|
|
|
|
2019-01-27 15:28:25 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
2019-01-27 16:06:17 +01:00
|
|
|
$this->entity = $this->createMock(EntityInterface::class);
|
|
|
|
|
|
|
|
$this->requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
|
|
|
$this->requestedEntity->method('getEntity')->willReturn($this->entity);
|
|
|
|
|
2019-02-13 15:47:46 +01:00
|
|
|
$this->requestedActionService = $this->createMock(RequestedActionServiceInterface::class);
|
|
|
|
$this->requestedActionService->method('getRequestedEntity')->willReturn($this->requestedEntity);
|
2019-02-03 16:32:57 +01:00
|
|
|
|
2019-02-16 09:19:49 +01:00
|
|
|
$this->secureRequestedRightCheckerService = $this->createMock(SecureRequestedRightCheckerServiceInterface::class);
|
2019-02-03 16:32:57 +01:00
|
|
|
$this->requestedActionFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
|
2019-01-27 15:28:25 +01:00
|
|
|
$this->requestStack = $this->createMock(RequestStack::class);
|
|
|
|
$this->layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
|
|
|
$this->entityManager = $this->createMock(EntityManagerInterface::class);
|
2019-02-16 09:19:49 +01:00
|
|
|
$this->actionService = new ActionService($this->requestedActionService, $this->secureRequestedRightCheckerService, $this->requestStack, $this->layerRepositoryFactoryService, $this->requestedActionFormBuilderService, $this->entityManager);
|
2019-01-27 15:28:25 +01:00
|
|
|
}
|
|
|
|
|
2019-01-27 16:06:17 +01:00
|
|
|
public function testIsRequestedActionSecure(): void
|
2019-01-27 09:35:43 +01:00
|
|
|
{
|
2019-02-16 09:19:49 +01:00
|
|
|
$this->secureRequestedRightCheckerService->method('check')->willReturn(true);
|
2019-01-27 15:28:25 +01:00
|
|
|
$this->assertTrue($this->actionService->isRequestedActionSecure());
|
2019-01-27 09:35:43 +01:00
|
|
|
}
|
|
|
|
|
2019-01-27 16:06:17 +01:00
|
|
|
public function testRequestedActionGetter(): void
|
2019-01-27 09:35:43 +01:00
|
|
|
{
|
2019-01-27 15:28:25 +01:00
|
|
|
$this->assertInstanceOf(RequestedActionInterface::class, $this->actionService->getRequestedAction());
|
2019-01-27 09:35:43 +01:00
|
|
|
}
|
2019-01-27 16:06:17 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-02-06 18:38:20 +01:00
|
|
|
public function testGetCurrentFormBuilder(): void
|
2019-01-27 16:06:17 +01:00
|
|
|
{
|
|
|
|
$form = $this->createMock(FormBuilderInterface::class);
|
2019-02-03 16:32:57 +01:00
|
|
|
$this->requestedActionFormBuilderService->method('createByService')->willReturn($form);
|
2019-02-06 18:38:20 +01:00
|
|
|
$result = $this->actionService->getCurrentFormBuilder();
|
2019-01-27 16:06:17 +01:00
|
|
|
$this->assertEquals($form, $result);
|
|
|
|
}
|
2019-01-27 09:35:43 +01:00
|
|
|
}
|