Merge branch 'signature-app-master' into 'master'

Signature app master

Closes #307

See merge request Chill-Projet/chill-bundles!743
This commit is contained in:
2024-11-12 20:30:00 +00:00
426 changed files with 22236 additions and 2253 deletions

View File

@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Controller\WorkflowSignatureCancelController;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Routing\ChillUrlGeneratorInterface;
use Chill\MainBundle\Security\Authorization\EntityWorkflowStepSignatureVoter;
use Chill\MainBundle\Workflow\SignatureStepStateChanger;
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Security\Core\Security;
use Twig\Environment;
/**
* @internal
*
* @coversNothing
*/
class WorkflowSignatureCancelControllerStepTest extends WebTestCase
{
private FormFactoryInterface $formFactory;
private SignatureStepStateChanger $signatureStepStateChanger;
private ChillUrlGeneratorInterface $chillUrlGenerator;
private RequestStack $requestStack;
protected function setUp(): void
{
self::bootKernel();
$this->formFactory = self::getContainer()->get('form.factory');
$this->signatureStepStateChanger = self::getContainer()->get(SignatureStepStateChanger::class);
$this->chillUrlGenerator = self::getContainer()->get(ChillUrlGeneratorInterface::class);
$requestContext = self::getContainer()->get(RequestContext::class);
$requestContext->setParameter('_locale', 'fr');
$this->requestStack = self::getContainer()->get(RequestStack::class);
}
public function testCancelSignatureGet(): void
{
$entityWorkflow = new EntityWorkflow();
$dto = new WorkflowTransitionContextDTO($entityWorkflow);
$dto->futureUserSignature = new User();
$entityWorkflow->setStep('signature', $dto, 'to_signature', new \DateTimeImmutable(), new User());
$signature = $entityWorkflow->getCurrentStep()->getSignatures()->first();
$security = $this->createMock(Security::class);
$security->expects($this->once())->method('isGranted')
->with(EntityWorkflowStepSignatureVoter::CANCEL, $signature)->willReturn(true);
$entityManager = $this->createMock(EntityManager::class);
$twig = $this->createMock(Environment::class);
$twig->expects($this->once())->method('render')->withAnyParameters()
->willReturn('template');
$controller = new WorkflowSignatureCancelController($entityManager, $security, $this->formFactory, $twig, $this->signatureStepStateChanger, $this->chillUrlGenerator);
$request = new Request();
$request->setMethod('GET');
$this->requestStack->push($request);
$response = $controller->cancelSignature($signature, $request);
self::assertEquals(200, $response->getStatusCode());
}
}

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Service\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Service\AccompanyingPeriod\ProvideThirdPartiesAssociated;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class ProvideThirdPartiesAssociatedTest extends TestCase
{
public function testGetThirdPartiesAssociated()
{
$period = new AccompanyingPeriod();
$period->setRequestor($tp1 = new ThirdParty());
$period->addResource((new AccompanyingPeriod\Resource())->setResource($tp1));
$period->addResource((new AccompanyingPeriod\Resource())->setResource($tp2 = new ThirdParty()));
$period->addResource((new AccompanyingPeriod\Resource())->setResource($p1 = new Person()));
$provider = new ProvideThirdPartiesAssociated();
$thirdParties = $provider->getThirdPartiesAssociated($period);
self::assertCount(2, $thirdParties);
self::assertContains($tp1, $thirdParties);
self::assertContains($tp2, $thirdParties);
self::assertNotContains($p1, $thirdParties);
self::assertNotContains(null, $thirdParties);
}
}

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Service\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class ProvideThirdPartiesAssociatedTest extends TestCase
{
public function testGetThirdPartiesAssociated()
{
$period = new AccompanyingPeriod();
$period->setRequestor($tp1 = new ThirdParty());
$period->addResource((new AccompanyingPeriod\Resource())->setResource($tp1));
$period->addResource((new AccompanyingPeriod\Resource())->setResource($tp2 = new ThirdParty()));
$period->addResource((new AccompanyingPeriod\Resource())->setResource($p1 = new Person()));
$period->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork());
$work->addThirdParty($tp3 = new ThirdParty());
$work->addThirdParty($tp1);
$work->setHandlingThierParty($tp4 = new ThirdParty());
$providerAccPeriod = new \Chill\PersonBundle\Service\AccompanyingPeriod\ProvideThirdPartiesAssociated();
$provider = new ProvideThirdPartiesAssociated($providerAccPeriod);
$thirdParties = $provider->getThirdPartiesAssociated($work);
self::assertContains($tp1, $thirdParties);
self::assertContains($tp2, $thirdParties);
self::assertContains($tp3, $thirdParties);
self::assertContains($tp4, $thirdParties);
self::assertNotContains($p1, $thirdParties);
self::assertCount(4, $thirdParties);
}
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Service\AccompanyingPeriodWorkEvaluationDocument;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Service\StoredObjectDuplicate;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
use Chill\PersonBundle\Service\AccompanyingPeriodWorkEvaluationDocument\AccompanyingPeriodWorkEvaluationDocumentDuplicator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Clock\MockClock;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @internal
*
* @coversNothing
*/
class AccompanyingPeriodWorkEvaluationDocumentDuplicatorTest extends TestCase
{
public function testDuplicate()
{
$storedObject = new StoredObject();
$evaluation = new AccompanyingPeriodWorkEvaluation();
$document = new AccompanyingPeriodWorkEvaluationDocument();
$document
->setStoredObject($storedObject)
->setTitle('test title')
->setAccompanyingPeriodWorkEvaluation($evaluation);
$storedObjectDuplicator = $this->createMock(StoredObjectDuplicate::class);
$storedObjectDuplicator->expects($this->once())->method('duplicate')->with($storedObject)->willReturn($newStoredObject = new StoredObject());
$translator = $this->createMock(TranslatorInterface::class);
$translator->method('trans')->willReturn('test translated');
$clock = new MockClock();
$duplicator = new AccompanyingPeriodWorkEvaluationDocumentDuplicator($storedObjectDuplicator, $translator, $clock);
$actual = $duplicator->duplicate($document);
self::assertNotSame($document, $actual);
self::assertStringStartsWith('test title', $actual->getTitle());
self::assertSame($newStoredObject, $actual->getStoredObject());
self::assertSame($evaluation, $actual->getAccompanyingPeriodWorkEvaluation());
}
}

View File

@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Workflow;
use Chill\DocStoreBundle\Workflow\WorkflowWithPublicViewDocumentHelper;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated;
use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated;
use Chill\PersonBundle\Workflow\AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
/**
* @internal
*
* @coversNothing
*/
class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest extends TestCase
{
use ProphecyTrait;
public function testGetSuggestedUsers()
{
$accompanyingCourse = new AccompanyingPeriod();
$accompanyingCourse->setUser($referrer = new User());
$accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork());
$work->addReferrer($workReferrer1 = new User());
$work->addReferrer($workReferrer2 = new User());
$work->addReferrer($referrer);
$work->addAccompanyingPeriodWorkEvaluation($eval = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation());
$eval->addDocument($doc = new AccompanyingPeriodWorkEvaluationDocument());
$entityWorkflow = new EntityWorkflow();
// Prophesize each dependency
$workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class);
$translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class);
$translatorProphecy = $this->prophesize(TranslatorInterface::class);
$twig = $this->prophesize(Environment::class);
// Create an instance of the class under test using revealed prophecies directly
$handler = new AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler(
$this->buildRepository($doc, 1),
$workflowRepositoryProphecy->reveal(),
$translatableStringHelperProphecy->reveal(),
$translatorProphecy->reveal(),
new WorkflowWithPublicViewDocumentHelper($twig->reveal()),
$this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(),
$this->prophesize(ProvidePersonsAssociated::class)->reveal(),
);
$entityWorkflow->setRelatedEntityId(1);
$entityWorkflow->setRelatedEntityClass(AccompanyingPeriodWorkEvaluationDocument::class);
$users = $handler->getSuggestedUsers($entityWorkflow);
self::assertContains($referrer, $users);
self::assertContains($workReferrer1, $users);
self::assertContains($workReferrer2, $users);
}
private function buildRepository(AccompanyingPeriodWorkEvaluationDocument $document, int $id): AccompanyingPeriodWorkEvaluationDocumentRepository
{
$repository = $this->prophesize(AccompanyingPeriodWorkEvaluationDocumentRepository::class);
$repository->find($id)->willReturn($document);
return $repository->reveal();
}
}

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationRepository;
use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated;
use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated;
use Chill\PersonBundle\Workflow\AccompanyingPeriodWorkEvaluationWorkflowHandler;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @internal
*
* @coversNothing
*/
class AccompanyingPeriodWorkEvaluationWorkflowHandlerTest extends TestCase
{
use ProphecyTrait;
public function testGetSuggestedUsers()
{
$accompanyingCourse = new AccompanyingPeriod();
$accompanyingCourse->setUser($referrer = new User());
$accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork());
$work->addReferrer($workReferrer1 = new User());
$work->addReferrer($workReferrer2 = new User());
$work->addReferrer($referrer);
$work->addAccompanyingPeriodWorkEvaluation($eval = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation());
$entityWorkflow = new EntityWorkflow();
$entityWorkflow->setRelatedEntityId(1);
// Prophesize each dependency
$workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class);
$translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class);
$translatorProphecy = $this->prophesize(TranslatorInterface::class);
// Create an instance of the class under test using revealed prophecies directly
$handler = new AccompanyingPeriodWorkEvaluationWorkflowHandler(
$this->buildRepository($eval, 1),
$workflowRepositoryProphecy->reveal(),
$translatableStringHelperProphecy->reveal(),
$translatorProphecy->reveal(),
$this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(),
$this->prophesize(ProvidePersonsAssociated::class)->reveal(),
);
$users = $handler->getSuggestedUsers($entityWorkflow);
self::assertContains($referrer, $users);
self::assertContains($workReferrer1, $users);
self::assertContains($workReferrer2, $users);
}
private function buildRepository(AccompanyingPeriod\AccompanyingPeriodWorkEvaluation $evaluation, int $id): AccompanyingPeriodWorkEvaluationRepository
{
$evaluationRepositoryProphecy = $this->prophesize(AccompanyingPeriodWorkEvaluationRepository::class);
$evaluationRepositoryProphecy->find($id)->willReturn($evaluation);
return $evaluationRepositoryProphecy->reveal();
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated;
use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated;
use Chill\PersonBundle\Workflow\AccompanyingPeriodWorkWorkflowHandler;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @internal
*
* @coversNothing
*/
class AccompanyingPeriodWorkWorkflowHandlerTest extends TestCase
{
use ProphecyTrait;
public function testGetSuggestedUsers()
{
$accompanyingCourse = new AccompanyingPeriod();
$accompanyingCourse->setUser($referrer = new User());
$accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork());
$work->addReferrer($workReferrer1 = new User());
$work->addReferrer($workReferrer2 = new User());
$work->addReferrer($referrer);
$entityWorkflow = new EntityWorkflow();
$entityWorkflow->setRelatedEntityId(1);
// Prophesize each dependency
$workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class);
$translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class);
$translatorProphecy = $this->prophesize(TranslatorInterface::class);
// Create an instance of the class under test using revealed prophecies directly
$handler = new AccompanyingPeriodWorkWorkflowHandler(
$this->buildRepository($work, 1),
$workflowRepositoryProphecy->reveal(),
$translatableStringHelperProphecy->reveal(),
$translatorProphecy->reveal(),
$this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(),
$this->prophesize(ProvidePersonsAssociated::class)->reveal(),
);
$users = $handler->getSuggestedUsers($entityWorkflow);
self::assertContains($referrer, $users);
self::assertContains($workReferrer1, $users);
self::assertContains($workReferrer2, $users);
}
private function buildRepository(AccompanyingPeriod\AccompanyingPeriodWork $work, int $int): AccompanyingPeriodWorkRepository
{
$accompanyingPeriodWorkRepositoryProphecy = $this->prophesize(AccompanyingPeriodWorkRepository::class);
$accompanyingPeriodWorkRepositoryProphecy
->find($int)
->willReturn($work);
return $accompanyingPeriodWorkRepositoryProphecy->reveal();
}
}