Add support for user signatures in workflow transitions

This update introduces the ability to specify user signatures in workflow transitions. It allows a nullable user to be declared that may be requested to apply a signature. The code now handles the use-case of signing a transition by a user in addition to previous functionality of having it signed by a "Person" entity. Corresponding tests are also updated to validate this new feature.
This commit is contained in:
2024-07-10 12:47:02 +02:00
parent 3e8805bdda
commit db94af0958
3 changed files with 55 additions and 5 deletions

View File

@@ -13,7 +13,9 @@ namespace Chill\MainBundle\Tests\Entity\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
use Chill\PersonBundle\Entity\Person;
use PHPUnit\Framework\TestCase;
/**
@@ -105,4 +107,35 @@ final class EntityWorkflowTest extends TestCase
self::assertEquals('2024-01-02', $previous->getTransitionAt()?->format('Y-m-d'));
self::assertEquals('to_step_two', $previous->getTransitionAfter());
}
public function testSetStepSignatureForUserIsCreated()
{
$entityWorkflow = new EntityWorkflow();
$dto = new WorkflowTransitionContextDTO($entityWorkflow);
$dto->futureUserSignature = $user = new User();
$entityWorkflow->setStep('new', $dto, 'to_new', new \DateTimeImmutable());
$actual = $entityWorkflow->getCurrentStep();
self::assertCount(1, $actual->getSignatures());
self::assertSame($user, $actual->getSignatures()->first()->getSigner());
}
public function testSetStepSignatureForPersonIsCreated()
{
$entityWorkflow = new EntityWorkflow();
$dto = new WorkflowTransitionContextDTO($entityWorkflow);
$dto->futurePersonSignatures[] = $person1 = new Person();
$dto->futurePersonSignatures[] = $person2 = new Person();
$entityWorkflow->setStep('new', $dto, 'to_new', new \DateTimeImmutable());
$actual = $entityWorkflow->getCurrentStep();
$persons = $actual->getSignatures()->map(fn (EntityWorkflowStepSignature $signature) => $signature->getSigner());
self::assertCount(2, $actual->getSignatures());
self::assertContains($person1, $persons);
self::assertContains($person2, $persons);
}
}