Add workflow title to notification emails for workflow transition, to user groups

Incorporated the workflow title into notification emails to provide more context to users. Updated the NotificationToUserGroupsOnTransition class and its tests to include the title from EntityWorkflowManager. Adjusted the French email templates to display the workflow title correctly.
This commit is contained in:
2024-11-18 15:03:33 +01:00
parent 723ca8db6a
commit 9a44cf060f
4 changed files with 28 additions and 6 deletions

View File

@@ -14,6 +14,8 @@ namespace Chill\MainBundle\Tests\Workflow\EventSubscriber;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
use Chill\MainBundle\Workflow\EntityWorkflowManager;
use Chill\MainBundle\Workflow\EntityWorkflowMarkingStore;
use Chill\MainBundle\Workflow\EventSubscriber\NotificationToUserGroupsOnTransition;
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
@@ -82,7 +84,12 @@ class NotificationToUserGroupsOnTransitionTest extends KernelTestCase
$metadataExtractor->buildArrayPresentationForWorkflow(Argument::type(Workflow::class))->willReturn(['name' => 'dummy', 'text' => 'Dummy Workflow']);
$metadataExtractor->buildArrayPresentationForPlace($entityWorkflow)->willReturn(['name' => 'to_one', 'text' => 'Dummy Place']);
$registry = $this->buildRegistryWithEventSubscriber($mailer->reveal(), $metadataExtractor->reveal());
$entityWorkflowHandler = $this->prophesize(EntityWorkflowHandlerInterface::class);
$entityWorkflowHandler->getEntityTitle($entityWorkflow)->willReturn('My title');
$entityWorkflowManager = $this->prophesize(EntityWorkflowManager::class);
$entityWorkflowManager->getHandler($entityWorkflow)->willReturn($entityWorkflowHandler->reveal());
$registry = $this->buildRegistryWithEventSubscriber($mailer->reveal(), $metadataExtractor->reveal(), $entityWorkflowManager->reveal());
$workflow = $registry->get($entityWorkflow, 'dummy');
$workflow->apply($entityWorkflow, 'to_one', ['context' => $dto, 'transition' => 'to_one', 'transitionAt' => new \DateTimeImmutable(), 'byUser' => new User()]);
@@ -106,13 +113,18 @@ class NotificationToUserGroupsOnTransitionTest extends KernelTestCase
$metadataExtractor->buildArrayPresentationForWorkflow(Argument::type(Workflow::class))->willReturn(['name' => 'dummy', 'text' => 'Dummy Workflow']);
$metadataExtractor->buildArrayPresentationForPlace($entityWorkflow)->willReturn(['name' => 'to_one', 'text' => 'Dummy Place']);
$registry = $this->buildRegistryWithEventSubscriber($mailer->reveal(), $metadataExtractor->reveal());
$entityWorkflowHandler = $this->prophesize(EntityWorkflowHandlerInterface::class);
$entityWorkflowHandler->getEntityTitle($entityWorkflow)->willReturn('My title');
$entityWorkflowManager = $this->prophesize(EntityWorkflowManager::class);
$entityWorkflowManager->getHandler($entityWorkflow)->willReturn($entityWorkflowHandler->reveal());
$registry = $this->buildRegistryWithEventSubscriber($mailer->reveal(), $metadataExtractor->reveal(), $entityWorkflowManager->reveal());
$workflow = $registry->get($entityWorkflow, 'dummy');
$workflow->apply($entityWorkflow, 'to_one', ['context' => $dto, 'transition' => 'to_one', 'transitionAt' => new \DateTimeImmutable(), 'byUser' => new User()]);
}
private function buildRegistryWithEventSubscriber(MailerInterface $mailer, MetadataExtractor $metadataExtractor): Registry
private function buildRegistryWithEventSubscriber(MailerInterface $mailer, MetadataExtractor $metadataExtractor, EntityWorkflowManager $entityWorkflowManager): Registry
{
$builder = new DefinitionBuilder();
$builder
@@ -134,7 +146,7 @@ class NotificationToUserGroupsOnTransitionTest extends KernelTestCase
}
});
$notificationEventSubscriber = new NotificationToUserGroupsOnTransition($this->twig, $metadataExtractor, $registry, $mailer, $this->em);
$notificationEventSubscriber = new NotificationToUserGroupsOnTransition($this->twig, $metadataExtractor, $registry, $mailer, $this->em, $entityWorkflowManager);
$eventDispatcher->addSubscriber($notificationEventSubscriber);
return $registry;