mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 22:35:01 +00:00
Add message handling for public view creation
Introduce `PostPublicViewMessage` and `PostPublicViewMessageHandler` to handle external user views on public links by applying workflow transitions. Integrate with `WorkflowViewSendPublicController` and add relevant tests.
This commit is contained in:
@@ -18,6 +18,8 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflowSendView;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowWithPublicViewInterface;
|
||||
use Chill\MainBundle\Workflow\Messenger\PostPublicViewMessage;
|
||||
use Chill\MainBundle\Workflow\Templating\EntityWorkflowViewMetadataDTO;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -27,6 +29,8 @@ use Psr\Log\NullLogger;
|
||||
use Symfony\Component\Clock\MockClock;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Twig\Environment;
|
||||
|
||||
@@ -44,8 +48,10 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
$environment = $this->prophesize(Environment::class);
|
||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entityManager->flush()->shouldNotBeCalled();
|
||||
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||
$messageBus->dispatch(Argument::type(PostPublicViewMessage::class))->shouldNotBeCalled();
|
||||
|
||||
$controller = new WorkflowViewSendPublicController($entityManager->reveal(), new NullLogger(), new EntityWorkflowManager([], new Registry()), new MockClock(), $environment->reveal());
|
||||
$controller = new WorkflowViewSendPublicController($entityManager->reveal(), new NullLogger(), new EntityWorkflowManager([], new Registry()), new MockClock(), $environment->reveal(), $messageBus->reveal());
|
||||
|
||||
self::expectException(AccessDeniedHttpException::class);
|
||||
|
||||
@@ -63,8 +69,10 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
$environment = $this->prophesize(Environment::class);
|
||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entityManager->flush()->shouldBeCalled();
|
||||
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||
$messageBus->dispatch(Argument::type(PostPublicViewMessage::class))->shouldNotBeCalled();
|
||||
|
||||
$controller = new WorkflowViewSendPublicController($entityManager->reveal(), new NullLogger(), new EntityWorkflowManager([], new Registry()), new MockClock(), $environment->reveal());
|
||||
$controller = new WorkflowViewSendPublicController($entityManager->reveal(), new NullLogger(), new EntityWorkflowManager([], new Registry()), new MockClock(), $environment->reveal(), $messageBus->reveal());
|
||||
|
||||
self::expectException(AccessDeniedHttpException::class);
|
||||
|
||||
@@ -86,8 +94,10 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
|
||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entityManager->flush()->shouldNotBeCalled();
|
||||
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||
$messageBus->dispatch(Argument::type(PostPublicViewMessage::class))->shouldNotBeCalled();
|
||||
|
||||
$controller = new WorkflowViewSendPublicController($entityManager->reveal(), new NullLogger(), new EntityWorkflowManager([], new Registry()), new MockClock('next year'), $environment->reveal());
|
||||
$controller = new WorkflowViewSendPublicController($entityManager->reveal(), new NullLogger(), new EntityWorkflowManager([], new Registry()), new MockClock('next year'), $environment->reveal(), $messageBus->reveal());
|
||||
|
||||
$send = $this->buildEntityWorkflowSend();
|
||||
|
||||
@@ -102,6 +112,8 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
$environment = $this->prophesize(Environment::class);
|
||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entityManager->flush()->shouldNotBeCalled();
|
||||
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||
$messageBus->dispatch(Argument::type(PostPublicViewMessage::class))->shouldNotBeCalled();
|
||||
|
||||
$controller = new WorkflowViewSendPublicController(
|
||||
$entityManager->reveal(),
|
||||
@@ -109,6 +121,7 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
new EntityWorkflowManager([], new Registry()),
|
||||
new MockClock(),
|
||||
$environment->reveal(),
|
||||
$messageBus->reveal(),
|
||||
);
|
||||
|
||||
self::expectException(\RuntimeException::class);
|
||||
@@ -123,9 +136,18 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
$environment = $this->prophesize(Environment::class);
|
||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entityManager->persist(Argument::that(function (EntityWorkflowSendView $view) use ($send) {
|
||||
$reflection = new \ReflectionClass($view);
|
||||
$idProperty = $reflection->getProperty('id');
|
||||
$idProperty->setAccessible(true);
|
||||
$idProperty->setValue($view, 5);
|
||||
|
||||
return $send === $view->getSend();
|
||||
}))->shouldBeCalled();
|
||||
$entityManager->flush()->shouldBeCalled();
|
||||
$messageBus = $this->prophesize(MessageBusInterface::class);
|
||||
$messageBus->dispatch(Argument::type(PostPublicViewMessage::class))->shouldBeCalled()
|
||||
->will(fn ($args) => new Envelope($args[0]));
|
||||
|
||||
|
||||
$controller = new WorkflowViewSendPublicController(
|
||||
$entityManager->reveal(),
|
||||
@@ -135,6 +157,7 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
], new Registry()),
|
||||
new MockClock(),
|
||||
$environment->reveal(),
|
||||
$messageBus->reveal(),
|
||||
);
|
||||
|
||||
$response = $controller($send, $send->getPrivateToken(), $this->buildRequest());
|
||||
@@ -211,7 +234,7 @@ class WorkflowViewSendPublicControllerTest extends TestCase
|
||||
throw new \BadMethodCallException('not implemented');
|
||||
}
|
||||
|
||||
public function renderPublicView(EntityWorkflowSend $entityWorkflowSend): string
|
||||
public function renderPublicView(EntityWorkflowSend $entityWorkflowSend, EntityWorkflowViewMetadataDTO $metadata): string
|
||||
{
|
||||
return 'content';
|
||||
}
|
||||
|
Reference in New Issue
Block a user