diff --git a/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentDuplicatorTest.php b/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentDuplicatorTest.php new file mode 100644 index 000000000..fd920c7a9 --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentDuplicatorTest.php @@ -0,0 +1,72 @@ +setDate($date = new \DateTimeImmutable()) + ->setObject($object) + ->setTitle('Title') + ->setUser($user = new User()) + ->setCategory($category = new DocumentCategory('bundle', 10)) + ->setDescription($description = 'Description'); + + $actual = $this->buildDuplicator()->duplicate($document); + + self::assertSame($date, $actual->getDate()); + // FYI, the duplication of object is checked by the mock + self::assertNotNull($actual->getObject()); + self::assertStringStartsWith('Title', $actual->getTitle()); + self::assertSame($user, $actual->getUser()); + self::assertSame($category, $actual->getCategory()); + self::assertEquals($description, $actual->getDescription()); + } + + private function buildDuplicator(): AccompanyingCourseDocumentDuplicator + { + $storedObjectDuplicate = $this->createMock(StoredObjectDuplicate::class); + $storedObjectDuplicate->expects($this->once())->method('duplicate') + ->with($this->isInstanceOf(StoredObject::class))->willReturn(new StoredObject()); + $translator = $this->createMock(TranslatorInterface::class); + $translator->method('trans')->withAnyParameters()->willReturn('duplicated'); + $clock = new MockClock(); + + return new AccompanyingCourseDocumentDuplicator( + $storedObjectDuplicate, + $translator, + $clock + ); + } +} diff --git a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentDuplicator.php b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentDuplicator.php new file mode 100644 index 000000000..b4c15fc22 --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentDuplicator.php @@ -0,0 +1,48 @@ +setCourse($document->getCourse()) + ->setTitle($document->getTitle().' ('.$this->translator->trans('acc_course_document.duplicated_at', ['at' => $this->clock->now()]).')') + ->setDate($document->getDate()) + ->setDescription($document->getDescription()) + ->setCategory($document->getCategory()) + ->setUser($document->getUser()) + ->setObject($this->storedObjectDuplicate->duplicate($document->getObject())) + ; + + return $newDoc; + } +} diff --git a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php index bc8de6587..ba7c477e5 100644 --- a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php +++ b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php @@ -17,6 +17,7 @@ use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; +use Chill\MainBundle\Workflow\EntityWorkflowWithDuplicableRelatedEntityInterface; use Chill\MainBundle\Workflow\EntityWorkflowWithStoredObjectHandlerInterface; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Symfony\Contracts\Translation\TranslatorInterface; @@ -27,8 +28,8 @@ use Symfony\Contracts\Translation\TranslatorInterface; readonly class AccompanyingCourseDocumentWorkflowHandler implements EntityWorkflowWithStoredObjectHandlerInterface { public function __construct( - private TranslatorInterface $translator, - private EntityWorkflowRepository $workflowRepository, + private TranslatorInterface $translator, + private EntityWorkflowRepository $workflowRepository, private AccompanyingCourseDocumentRepository $repository, ) {} diff --git a/src/Bundle/ChillDocStoreBundle/translations/messages+intl-icu.fr.yml b/src/Bundle/ChillDocStoreBundle/translations/messages+intl-icu.fr.yml new file mode 100644 index 000000000..0132cdc4f --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/translations/messages+intl-icu.fr.yml @@ -0,0 +1,3 @@ +acc_course_document: + duplicated_at: >- + Dupliqué le {at, date, long} à {at, time, short}