mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-02 11:29:41 +00:00
Merge branch 'master' into ticket-app-master
# Conflicts: # .eslint-baseline.json # src/Bundle/ChillMainBundle/Entity/User.php # src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue # src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMore.vue # src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressSelection.vue # src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue # src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue # src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue # src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue # src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
<?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\PersonIdentifier\Rendering;
|
||||
|
||||
use Chill\PersonBundle\Entity\Identifier\PersonIdentifier;
|
||||
use Chill\PersonBundle\Entity\Identifier\PersonIdentifierDefinition;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\PersonIdentifier\Identifier\StringIdentifier;
|
||||
use Chill\PersonBundle\PersonIdentifier\PersonIdentifierEngineInterface;
|
||||
use Chill\PersonBundle\PersonIdentifier\PersonIdentifierManager;
|
||||
use Chill\PersonBundle\PersonIdentifier\PersonIdentifierManagerInterface;
|
||||
use Chill\PersonBundle\PersonIdentifier\PersonIdentifierWorker;
|
||||
use Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRendering;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class PersonIdRenderingTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider provideRenderCases
|
||||
*/
|
||||
public function testRenderPersonId(Person $person, string $idContentText, string $expected): void
|
||||
{
|
||||
// Parameter bag mock returning the provided id_content_text
|
||||
$parameterBag = $this->prophesize(ParameterBagInterface::class);
|
||||
$parameterBag->get('chill_person')
|
||||
->willReturn(['person_render' => ['id_content_text' => $idContentText]]);
|
||||
|
||||
// PersonIdentifierManager is explicitly requested to be mocked in the spec.
|
||||
// It will return a PersonIdentifierWorker whose renderAsString behaves like StringIdentifier::renderAsString
|
||||
$personIdentifierManager = $this->prophesize(PersonIdentifierManagerInterface::class);
|
||||
$personIdentifierManager
|
||||
->buildWorkerByPersonIdentifierDefinition(Argument::type(PersonIdentifierDefinition::class))
|
||||
->will(function ($args) {
|
||||
/** @var PersonIdentifierDefinition $definition */
|
||||
$definition = $args[0];
|
||||
|
||||
$engine = new class () implements PersonIdentifierEngineInterface {
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'test';
|
||||
}
|
||||
|
||||
public function canonicalizeValue(array $value, PersonIdentifierDefinition $definition): ?string
|
||||
{
|
||||
return $value['content'] ?? '';
|
||||
}
|
||||
|
||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, PersonIdentifierDefinition $personIdentifierDefinition): void {}
|
||||
|
||||
public function renderAsString(?PersonIdentifier $identifier, PersonIdentifierDefinition $definition): string
|
||||
{
|
||||
// same behavior as StringIdentifier::renderAsString
|
||||
return $identifier?->getValue()['content'] ?? '';
|
||||
}
|
||||
};
|
||||
|
||||
return new PersonIdentifierWorker($engine, $definition);
|
||||
});
|
||||
|
||||
$service = new PersonIdRendering($parameterBag->reveal(), $personIdentifierManager->reveal());
|
||||
|
||||
self::assertSame($expected, $service->renderPersonId($person));
|
||||
}
|
||||
|
||||
public function provideRenderCases(): iterable
|
||||
{
|
||||
// Case 1: one active identifier, one inactive identifier, should render person id and only active identifier
|
||||
$person1 = new Person();
|
||||
$this->setEntityId($person1, 123);
|
||||
|
||||
$defActive = new PersonIdentifierDefinition(label: ['en' => 'Active'], engine: 'string');
|
||||
$this->setEntityId($defActive, 10);
|
||||
$defActive->setActive(true);
|
||||
|
||||
$idActive = new PersonIdentifier($defActive);
|
||||
$idActive->setPerson($person1);
|
||||
$idActive->setValue(['content' => 'ABC']);
|
||||
$person1->addIdentifier($idActive);
|
||||
|
||||
$defInactive = new PersonIdentifierDefinition(label: ['en' => 'Inactive'], engine: 'string');
|
||||
$this->setEntityId($defInactive, 99);
|
||||
$defInactive->setActive(false);
|
||||
|
||||
$idInactive = new PersonIdentifier($defInactive);
|
||||
$idInactive->setPerson($person1);
|
||||
$idInactive->setValue(['content' => 'SHOULD_NOT_APPEAR']);
|
||||
$person1->addIdentifier($idInactive);
|
||||
|
||||
$template1 = 'ID: [[ person_id ]] - Active: [[ identifier_10 ]] - Inactive: [[ identifier_99 ]]';
|
||||
$expected1 = 'ID: 123 - Active: ABC - Inactive: [[ identifier_99 ]]';
|
||||
|
||||
yield
|
||||
'with active and inactive identifiers' => [$person1, $template1, $expected1]
|
||||
;
|
||||
|
||||
$template2 = 'ID: [[ person_id ]][[ if:identifier_10 ]] - Active: [[ identifier_10 ]][[ endif:identifier_10 ]]';
|
||||
$expected2 = 'ID: 123 - Active: ABC';
|
||||
|
||||
yield
|
||||
'rendering with conditional: condition are removed' => [$person1, $template2, $expected2]
|
||||
;
|
||||
|
||||
$template3 = 'ID: [[ person_id ]][[ if:identifier_99 ]] - Inactive: [[ identifier_10 ]][[ endif:identifier_99 ]]';
|
||||
$expected3 = 'ID: 123';
|
||||
|
||||
yield
|
||||
'rendering with conditional: the content between condition is removed' => [$person1, $template3, $expected3]
|
||||
;
|
||||
|
||||
$template4 = 'ID: [[ person_id ]][[ if:identifier_105 ]] - not present: [[ identifier_105 ]][[ endif:identifier_105 ]]';
|
||||
$expected4 = 'ID: 123';
|
||||
|
||||
yield
|
||||
'rendering with conditional: the content between condition is removed, the identifier is not associated with the person' => [$person1, $template4, $expected4]
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
private function setEntityId(object $entity, int $id): void
|
||||
{
|
||||
$refl = new \ReflectionClass($entity);
|
||||
$prop = $refl->getProperty('id');
|
||||
$prop->setAccessible(true);
|
||||
$prop->setValue($entity, $id);
|
||||
}
|
||||
}
|
@@ -14,22 +14,20 @@ namespace Chill\PersonBundle\Tests\Service\AccompanyingPeriodWork;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
use Chill\PersonBundle\Service\AccompanyingPeriodWork\AccompanyingPeriodWorkMergeService;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Monolog\Test\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccompanyingPeriodWorkMergeServiceTest extends TestCase
|
||||
class AccompanyingPeriodWorkMergeServiceTest extends KernelTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
@@ -160,46 +158,62 @@ class AccompanyingPeriodWorkMergeServiceTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testMerge(): void
|
||||
public function testMergeAccompanyingPeriodWorks(): void
|
||||
{
|
||||
$accompanyingPeriodWork = new AccompanyingPeriodWork();
|
||||
$accompanyingPeriodWork->setStartDate(new \DateTime('2022-01-01'));
|
||||
$accompanyingPeriodWork->addReferrer($userA = new User());
|
||||
$accompanyingPeriodWork->addReferrer($userC = new User());
|
||||
$accompanyingPeriodWork->addAccompanyingPeriodWorkEvaluation($evaluationA = new AccompanyingPeriodWorkEvaluation());
|
||||
$accompanyingPeriodWork->setNote('blabla');
|
||||
$accompanyingPeriodWork->addThirdParty($thirdPartyA = new ThirdParty());
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$userA = new User();
|
||||
$userA->setUsername('someUser');
|
||||
$userA->setEmail('someUser@example.com');
|
||||
$em->persist($userA);
|
||||
|
||||
$toKeep = new AccompanyingPeriodWork();
|
||||
$toKeep->setStartDate(new \DateTime('2022-01-02'));
|
||||
$toKeep->setNote('Keep note');
|
||||
$toKeep->setCreatedBy($userA);
|
||||
$toKeep->setUpdatedBy($userA);
|
||||
$toKeep->addReferrer($userA);
|
||||
$em->persist($toKeep);
|
||||
|
||||
$userB = new User();
|
||||
$userB->setUsername('anotherUser');
|
||||
$userB->setEmail('anotherUser@example.com');
|
||||
$em->persist($userB);
|
||||
|
||||
$toDelete = new AccompanyingPeriodWork();
|
||||
$toDelete->setStartDate(new \DateTime('2022-01-01'));
|
||||
$toDelete->addReferrer($userB = new User());
|
||||
$toDelete->addReferrer($userC);
|
||||
$toDelete->addAccompanyingPeriodWorkEvaluation($evaluationB = new AccompanyingPeriodWorkEvaluation());
|
||||
$toDelete->setNote('boum');
|
||||
$toDelete->addThirdParty($thirdPartyB = new ThirdParty());
|
||||
$toDelete->addGoal($goalA = new AccompanyingPeriodWorkGoal());
|
||||
$toDelete->addResult($resultA = new Result());
|
||||
$toDelete->setNote('Delete note');
|
||||
$toDelete->setCreatedBy($userB);
|
||||
$toDelete->setUpdatedBy($userB);
|
||||
$toDelete->addReferrer($userB);
|
||||
$em->persist($toDelete);
|
||||
|
||||
$service = $this->buildMergeService($toDelete);
|
||||
$service->merge($accompanyingPeriodWork, $toDelete);
|
||||
$evaluation = new AccompanyingPeriodWorkEvaluation();
|
||||
$evaluation->setAccompanyingPeriodWork($toDelete);
|
||||
$em->persist($evaluation);
|
||||
|
||||
self::assertTrue($accompanyingPeriodWork->getReferrers()->contains($userA));
|
||||
self::assertTrue($accompanyingPeriodWork->getReferrers()->contains($userB));
|
||||
self::assertTrue($accompanyingPeriodWork->getReferrers()->contains($userC));
|
||||
$em->flush();
|
||||
|
||||
self::assertTrue($accompanyingPeriodWork->getAccompanyingPeriodWorkEvaluations()->contains($evaluationA));
|
||||
self::assertTrue($accompanyingPeriodWork->getAccompanyingPeriodWorkEvaluations()->contains($evaluationB));
|
||||
foreach ($accompanyingPeriodWork->getAccompanyingPeriodWorkEvaluations() as $evaluation) {
|
||||
self::assertSame($accompanyingPeriodWork, $evaluation->getAccompanyingPeriodWork());
|
||||
}
|
||||
$service = new AccompanyingPeriodWorkMergeService($em);
|
||||
$merged = $service->merge($toKeep, $toDelete);
|
||||
|
||||
self::assertStringContainsString('blabla', $accompanyingPeriodWork->getNote());
|
||||
self::assertStringContainsString('boum', $toDelete->getNote());
|
||||
$em->refresh($merged);
|
||||
|
||||
self::assertTrue($accompanyingPeriodWork->getThirdParties()->contains($thirdPartyA));
|
||||
self::assertTrue($accompanyingPeriodWork->getThirdParties()->contains($thirdPartyB));
|
||||
// Assertions
|
||||
|
||||
self::assertTrue($accompanyingPeriodWork->getGoals()->contains($goalA));
|
||||
self::assertTrue($accompanyingPeriodWork->getResults()->contains($resultA));
|
||||
$this->assertEquals(new \DateTime('2022-01-01'), $merged->getStartDate());
|
||||
|
||||
$this->assertStringContainsString('Keep note', $merged->getNote());
|
||||
$this->assertStringContainsString('Delete note', $merged->getNote());
|
||||
|
||||
$em->refresh($evaluation);
|
||||
$this->assertEquals($toKeep->getId(), $evaluation->getAccompanyingPeriodWork()->getId());
|
||||
|
||||
$em->remove($evaluation);
|
||||
$em->remove($toKeep);
|
||||
$em->remove($toDelete);
|
||||
$em->remove($userA);
|
||||
$em->remove($userB);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user