Merge branch 'refs/heads/master' into ticket-app-master

# Conflicts:
#	composer.json
#	config/bundles.php
#	config/packages/doctrine_migrations_chill.yaml
#	package.json
#	src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadUserGroup.php
#	src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php
#	src/Bundle/ChillMainBundle/Entity/UserGroup.php
#	src/Bundle/ChillMainBundle/Resources/public/chill/js/date.ts
#	src/Bundle/ChillMainBundle/Resources/public/lib/download-report/download-report.js
#	src/Bundle/ChillMainBundle/Resources/public/module/ckeditor5/editor_config.ts
#	src/Bundle/ChillMainBundle/Resources/public/module/ckeditor5/index.ts
#	src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js
#	src/Bundle/ChillMainBundle/Resources/public/types.ts
#	src/Bundle/ChillMainBundle/Resources/views/Dev/dev.assets.html.twig
#	src/Bundle/ChillMainBundle/Templating/Entity/UserGroupRender.php
#	src/Bundle/ChillMainBundle/chill.api.specs.yaml
#	src/Bundle/ChillMainBundle/chill.webpack.config.js
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Resources.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Resources/WriteComment.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/Household.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/MemberDetails.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/PersonComment.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonText.vue
#	src/Bundle/ChillPersonBundle/Resources/public/vuejs/_js/i18n.ts
#	tests/app/config/bootstrap.php
This commit is contained in:
2025-05-27 09:37:04 +02:00
1735 changed files with 82701 additions and 27873 deletions

View File

@@ -247,7 +247,7 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
?\Twig\Environment $engine = null,
?NotificationPersisterInterface $notificationPersister = null,
?Security $security = null,
?TranslatorInterface $translator = null
?TranslatorInterface $translator = null,
): PersonAddressMoveEventSubscriber {
if (null === $translator) {
$double = $this->prophesize(TranslatorInterface::class);

View File

@@ -11,6 +11,9 @@ declare(strict_types=1);
namespace Tests\Controller\AccompanyingCoursWorkApiController;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\MainBundle\Entity\GenderIconEnum;
use Chill\MainBundle\Repository\UserRepositoryInterface;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
@@ -129,8 +132,15 @@ class ConflictTest extends WebTestCase
$period = new AccompanyingPeriod();
$em->persist($period);
$gender = new Gender();
$gender->setGenderTranslation(GenderEnum::MALE);
$gender->setLabel(['fr' => 'homme']);
$gender->setIcon(GenderIconEnum::MALE);
$em->persist($gender);
$period->addPerson(($p = new Person())->setFirstName('test')->setLastName('test')
->setBirthdate(new \DateTime('1980-01-01'))->setGender(Person::BOTH_GENDER));
->setBirthdate(new \DateTime('1980-01-01'))->setGender($gender));
$em->persist($p);
$issue = (new SocialIssue())->setTitle(['fr' => 'test']);
$em->persist($issue);

View File

@@ -74,7 +74,7 @@ final class AccompanyingCourseControllerTest extends WebTestCase
$this->assertResponseRedirects();
$location = $this->client->getResponse()->headers->get('Location');
$this->assertEquals(1, \preg_match('|^\\/[^\\/]+\\/parcours/([\\d]+)/edit$|', (string) $location));
$this->assertEquals(1, \preg_match('|^\/[^\/]+\/parcours/([\d]+)/edit$|', (string) $location));
}
/**
@@ -93,7 +93,7 @@ final class AccompanyingCourseControllerTest extends WebTestCase
$location = $this->client->getResponse()->headers->get('Location');
$matches = [];
$this->assertEquals(1, \preg_match('|^\\/[^\\/]+\\/parcours/([\\d]+)/edit$|', (string) $location, $matches));
$this->assertEquals(1, \preg_match('|^\/[^\/]+\/parcours/([\d]+)/edit$|', (string) $location, $matches));
$id = $matches[1];
$period = self::getContainer()->get(EntityManagerInterface::class)

View File

@@ -14,6 +14,9 @@ namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\AddressReference;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\MainBundle\Entity\GenderIconEnum;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\Household\Household;
@@ -51,9 +54,15 @@ final class HouseholdApiControllerTest extends WebTestCase
->setMaxResults(1)
->getQuery()->getSingleResult();
$gender = new Gender();
$gender->setGenderTranslation(GenderEnum::MALE);
$gender->setLabel(['fr' => 'homme']);
$gender->setIcon(GenderIconEnum::MALE);
$em->persist($gender);
$p = new Person();
$p->setFirstname('test')->setLastName('test lastname')
->setGender(Person::BOTH_GENDER)
->setGender($gender)
->setCenter($centerA);
$em->persist($p);
$h = new Household();

View File

@@ -112,24 +112,24 @@ final class PersonControllerCreateTest extends WebTestCase
$genderType = $form->get(self::GENDER_INPUT);
$this->assertEquals(
'radio',
'select',
$genderType->getType(),
'The gender input has radio buttons'
'The gender input is a select form to select a gender entity'
);
$this->assertEquals(
3,
\count($genderType->availableOptionValues()),
'The gender input has three options: man, women and undefined'
);
$this->assertTrue(
\in_array('man', $genderType->availableOptionValues(), true),
'gender has "homme" option'
);
$this->assertTrue(
\in_array('woman', $genderType->availableOptionValues(), true),
'gender has "femme" option'
);
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked');
/* $this->assertEquals(
3,
\count($genderType->availableOptionValues()),
'The gender input has three options: man, women and undefined'
);
$this->assertTrue(
\in_array('man', $genderType->availableOptionValues(), true),
'gender has "homme" option'
);
$this->assertTrue(
\in_array('woman', $genderType->availableOptionValues(), true),
'gender has "femme" option'
);
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked');*/
return $form;
}
@@ -222,11 +222,12 @@ final class PersonControllerCreateTest extends WebTestCase
Form &$creationForm,
string $firstname = 'God',
string $lastname = 'Jesus',
?\DateTime $birthdate = null
?\DateTime $birthdate = null,
) {
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname.'_'.uniqid());
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname.'_'.uniqid());
$creationForm->get(self::GENDER_INPUT)->select('man');
// Todo change hardcoded id
$creationForm->get(self::GENDER_INPUT)->select(5);
$date = $birthdate ?? new \DateTime('1947-02-01');
$creationForm->get(self::BIRTHDATE_INPUT)->setValue($date->format('Y-m-d'));

View File

@@ -12,6 +12,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\MainBundle\Entity\GenderIconEnum;
use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\Person;
@@ -160,12 +163,18 @@ final class PersonControllerUpdateTest extends WebTestCase
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $centerRepository->findOneBy(['name' => 'Center A']);
$gender = new Gender();
$gender->setGenderTranslation(GenderEnum::MALE);
$gender->setLabel(['fr' => 'homme']);
$gender->setIcon(GenderIconEnum::MALE);
$em->persist($gender);
$person = new Person();
$person
->setFirstName('Foo')
->setLastName('Bar')
->setBirthdate(new \DateTime('2017-09-30'))
->setGender(Person::MALE_GENDER)
->setGender($gender)
->setCenter($center);
$em->persist($person);

View File

@@ -11,6 +11,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\MainBundle\Entity\GenderIconEnum;
use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\Person;
@@ -99,12 +102,18 @@ final class PersonControllerViewTest extends WebTestCase
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $centerRepository->findOneBy(['name' => 'Center A']);
$gender = new Gender();
$gender->setGenderTranslation(GenderEnum::MALE);
$gender->setLabel(['fr' => 'homme']);
$gender->setIcon(GenderIconEnum::MALE);
$em->persist($gender);
$person = new Person();
$person
->setFirstName('Foo')
->setLastName('Bar')
->setBirthdate(new \DateTime('2017-09-30'))
->setGender(Person::MALE_GENDER)
->setGender($gender)
->setCenter($center);
$em->persist($person);

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\WorkflowSignatureStateChangeController;
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 WorkflowSignatureStateChangeController($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

@@ -33,7 +33,40 @@ final class ReferrerAggregatorTest extends AbstractAggregatorTest
$this->aggregator = self::getContainer()->get('chill.person.export.aggregator_referrer');
}
public function getAggregator()
/**
* @dataProvider provideBeforeData
*/
public function testDataTransformer(?array $before, array $expected): void
{
$actual = $this->getAggregator()->transformData($before);
self::assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
foreach (['start_date', 'end_date'] as $key) {
self::assertInstanceOf(RollingDate::class, $actual[$key]);
self::assertEquals($expected[$key]->getRoll(), $actual[$key]->getRoll(), "Check that the roll is the same for {$key}");
}
}
public static function provideBeforeData(): iterable
{
yield [
['date_calc' => new RollingDate(RollingDate::T_TODAY)],
['start_date' => new RollingDate(RollingDate::T_TODAY), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
yield [
['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
yield [
null,
// this is the default configuration
['start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
}
public function getAggregator(): ReferrerAggregator
{
return $this->aggregator;
}
@@ -41,7 +74,10 @@ final class ReferrerAggregatorTest extends AbstractAggregatorTest
public static function getFormData(): array
{
return [
['date_calc' => new RollingDate(RollingDate::T_TODAY)],
[
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
],
];
}

View File

@@ -14,6 +14,7 @@ namespace Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
@@ -48,16 +49,46 @@ final class ReferrerScopeAggregatorTest extends AbstractAggregatorTest
return new ReferrerScopeAggregator(
$scopeRepository->reveal(),
$translatableStringHelper->reveal(),
$dateConverter->reveal()
new RollingDateConverter(),
);
}
public static function getFormData(): array
{
return [
[
'date_calc' => new RollingDate(RollingDate::T_TODAY),
],
['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
}
/**
* @dataProvider provideBeforeData
*/
public function testDataTransformer(?array $before, array $expected): void
{
$actual = $this->getAggregator()->transformData($before);
self::assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
foreach (['start_date', 'end_date'] as $key) {
self::assertInstanceOf(RollingDate::class, $actual[$key]);
self::assertEquals($expected[$key]->getRoll(), $actual[$key]->getRoll(), "Check that the roll is the same for {$key}");
}
}
public static function provideBeforeData(): iterable
{
yield [
null,
['start_date' => new RollingDate(RollingDate::T_FIXED_DATE, new \DateTimeImmutable('1970-01-01')), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
yield [
[],
['start_date' => new RollingDate(RollingDate::T_FIXED_DATE, new \DateTimeImmutable('1970-01-01')), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
yield [
['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
}

View File

@@ -33,7 +33,39 @@ final class UserJobAggregatorTest extends AbstractAggregatorTest
$this->aggregator = self::getContainer()->get('chill.person.export.aggregator_referrer_job');
}
public function getAggregator()
/**
* @dataProvider provideBeforeData
*/
public function testDataTransformer(?array $before, array $expected): void
{
$actual = $this->getAggregator()->transformData($before);
self::assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
foreach (['start_date', 'end_date'] as $key) {
self::assertInstanceOf(RollingDate::class, $actual[$key]);
self::assertEquals($expected[$key]->getRoll(), $actual[$key]->getRoll(), "Check that the roll is the same for {$key}");
}
}
public static function provideBeforeData(): iterable
{
yield [
null,
['start_date' => new RollingDate(RollingDate::T_FIXED_DATE, new \DateTimeImmutable('1970-01-01')), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
yield [
[],
['start_date' => new RollingDate(RollingDate::T_FIXED_DATE, new \DateTimeImmutable('1970-01-01')), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
yield [
['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
['start_date' => new RollingDate(RollingDate::T_WEEK_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
}
public function getAggregator(): UserJobAggregator
{
return $this->aggregator;
}
@@ -41,9 +73,7 @@ final class UserJobAggregatorTest extends AbstractAggregatorTest
public static function getFormData(): array
{
return [
[
'job_at' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01')),
],
['start_date' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)],
];
}
@@ -56,7 +86,7 @@ final class UserJobAggregatorTest extends AbstractAggregatorTest
$em->createQueryBuilder()
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp')
->join('acp.job', 'acpjob'),
->leftJoin('acp.job', 'acpjob'),
$em->createQueryBuilder()
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp'),

View File

@@ -50,11 +50,13 @@ final class UserJobFilterTest extends AbstractFilterTest
$data = [];
$data[] = [
'jobs' => new ArrayCollection($jobs),
'date_calc' => new RollingDate(RollingDate::T_TODAY),
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
];
$data[] = [
'jobs' => $jobs,
'date_calc' => new RollingDate(RollingDate::T_TODAY),
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
];
return $data;

View File

@@ -50,11 +50,13 @@ final class UserScopeFilterTest extends AbstractFilterTest
return [
[
'date_calc' => new RollingDate(RollingDate::T_TODAY),
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
'scopes' => new ArrayCollection($scopes),
],
[
'date_calc' => new RollingDate(RollingDate::T_TODAY),
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
'scopes' => $scopes,
],
];

View File

@@ -41,13 +41,13 @@ final class GenderFilterTest extends AbstractFilterTest
{
return [
[
'accepted_genders' => [Person::FEMALE_GENDER],
'accepted_genders' => ['man'],
],
[
'accepted_genders' => [Person::MALE_GENDER],
'accepted_genders' => ['woman'],
],
[
'accepted_genders' => [Person::MALE_GENDER, Person::BOTH_GENDER],
'accepted_genders' => ['man', 'both'],
],
];
}

View File

@@ -0,0 +1,62 @@
<?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 Export\Filter\PersonFilters;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Filter\PersonFilters\WithoutParticipationBetweenDatesFilter;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class WithoutParticipationBetweenDatesFilterTest extends AbstractFilterTest
{
private WithoutParticipationBetweenDatesFilter $filter;
protected function setUp(): void
{
self::bootKernel();
$this->filter = self::getContainer()->get(WithoutParticipationBetweenDatesFilter::class);
}
public function getFilter()
{
return $this->filter;
}
public static function getFormData(): array
{
return [
[
'date_after' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'date_before' => new RollingDate(RollingDate::T_TODAY),
],
];
}
public static function getQueryBuilders(): iterable
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
return [
$em->createQueryBuilder()
->select('person.id')
->from(Person::class, 'person'),
];
}
}

View File

@@ -0,0 +1,106 @@
<?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 Bundle\ChillPersonBundle\Tests\Exporters;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Entity\SocialWork\Result;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Service\SocialWork\SocialActionCSVExportService;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @internal
*
* @coversNothing
*/
class SocialActionCsvExporterTest extends TestCase
{
public function testGenerateCsv(): void
{
$translator = $this->createMock(TranslatorInterface::class);
$translator->method('trans')->willReturnArgument(0);
$socialIssueRender = $this->createMock(SocialIssueRender::class);
$socialIssueRender->method('renderString')->willReturnCallback(static fn (SocialIssue $socialIssue) => $socialIssue->getTitle()['fr'] ?? '');
$socialActionRender = $this->createMock(SocialActionRender::class);
$socialActionRender->method('renderString')->willReturnCallback(static fn (SocialAction $socialAction) => $socialAction->getTitle()['fr'] ?? '');
$stringHelper = $this->createMock(TranslatableStringHelperInterface::class);
$stringHelper->method('localize')
->willReturnCallback(static fn (array $messages) => $messages['fr'] ?? 'not found');
$exporter = new SocialActionCSVExportService($socialIssueRender, $socialActionRender, $stringHelper, $translator);
// Mock social issue
// Création d'une instance réelle de SocialIssue
$socialIssue = new SocialIssue();
$socialIssue->setTitle(['fr' => 'Issue Title']); // Exemple de définition d'une propriété
// Création d'une instance réelle de SocialAction sans objectifs ni résultats
$actionWithoutGoalsOrResults = new SocialAction();
$actionWithoutGoalsOrResults->setIssue($socialIssue);
$actionWithoutGoalsOrResults->setDesactivationDate(new \DateTime('2025-05-21'));
$actionWithoutGoalsOrResults->setTitle(['fr' => 'Action without goals or results']);
// Création d'une instance réelle de SocialAction avec des objectifs et des résultats
$goalWithResult = new Goal();
$resultWithAction = new Result();
$goalWithResult->addResult($resultWithAction);
$actionWithGoalsAndResults = new SocialAction();
$actionWithGoalsAndResults->setIssue($socialIssue);
$actionWithGoalsAndResults->setDesactivationDate(new \DateTime('2025-05-21'));
$actionWithGoalsAndResults->setTitle(['fr' => 'Action with goals and results']);
$actionWithGoalsAndResults->addGoal($goalWithResult);
// Création d'une instance réelle de SocialAction avec des objectifs mais sans résultats
$goalWithoutResult = new Goal();
$actionWithGoalsNoResults = new SocialAction();
$actionWithGoalsNoResults->setIssue($socialIssue);
$actionWithGoalsNoResults->setDesactivationDate(new \DateTime('2025-05-21'));
$actionWithGoalsNoResults->setTitle(['fr' => 'Action with goals and no results']);
$actionWithGoalsNoResults->addGoal($goalWithoutResult);
// Création d'une instance réelle de SocialAction avec des résultats mais sans objectifs
$resultWithNoAction = new Result();
$resultWithNoAction->setTitle(['fr' => 'Result without objectives']);
$actionWithResultsNoGoals = new SocialAction();
$actionWithResultsNoGoals->setIssue($socialIssue);
$actionWithResultsNoGoals->setDesactivationDate(new \DateTime('2025-05-21'));
$actionWithResultsNoGoals->setTitle(['fr' => 'Action with results and no goals']);
$actionWithResultsNoGoals->addResult($resultWithNoAction);
// generate
$csv = $exporter->generateCsv([$actionWithGoalsAndResults, $actionWithoutGoalsOrResults,
$actionWithGoalsNoResults, $actionWithResultsNoGoals]);
$content = $csv->toString();
// Assert CSV contains expected values
$this->assertStringContainsString('Action without goals or results', $content);
$this->assertStringContainsString('Action with goals and results', $content);
$this->assertStringContainsString('Action with goals and no results', $content);
$this->assertStringContainsString('Action with results and no goals', $content);
self::assertEquals(<<<'CSV'
export.social_action_list.action_id,export.social_action_list.social_issue_id,export.social_action_list.problematique_label,export.social_action_list.desactivation_date,export.social_action_list.social_issue_ordering,export.social_action_list.action_label,export.social_action_list.action_ordering,export.social_action_list.goal_label,export.social_action_list.goal_id,export.social_action_list.goal_result_label,export.social_action_list.goal_result_id,export.social_action_list.result_without_goal_label,export.social_action_list.result_without_goal_id,export.social_action_list.evaluation_title,export.social_action_list.evaluation_id,export.social_action_list.evaluation_url,export.social_action_list.evaluation_delay_month,export.social_action_list.evaluation_delay_week,export.social_action_list.evaluation_delay_day
,,"Issue Title",2025-05-21,0,"Action with goals and results",0,"not found",,"not found",,,,,,,,,
,,"Issue Title",2025-05-21,0,"Action without goals or results",0,,,,,,,,,,,,
,,"Issue Title",2025-05-21,0,"Action with goals and no results",0,"not found",,,,,,,,,,,
,,"Issue Title",2025-05-21,0,"Action with results and no goals",0,,,,,"Result without objectives",,,,,,,
CSV, $content);
}
}

View File

@@ -562,7 +562,7 @@ final class MembersEditorTest extends TestCase
private function buildMembersEditorFactory(
?EventDispatcherInterface $eventDispatcher = null,
?ValidatorInterface $validator = null
?ValidatorInterface $validator = null,
) {
if (null === $eventDispatcher) {
$double = $this->getProphet()->prophesize();

View File

@@ -11,13 +11,13 @@ declare(strict_types=1);
namespace Serializer\Normalizer;
use Chill\DocGeneratorBundle\Test\DocGenNormalizerTestAbstract;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Entity\SocialWork\Result;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -25,8 +25,10 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
* @internal
*
* @coversNothing
*
* @template-extends DocGenNormalizerTestAbstract<AccompanyingPeriodWork>
*/
final class AccompanyingPeriodWorkDocGenNormalizerTest extends KernelTestCase
final class AccompanyingPeriodWorkDocGenNormalizerTest extends DocGenNormalizerTestAbstract
{
private NormalizerInterface $normalizer;
@@ -36,28 +38,31 @@ final class AccompanyingPeriodWorkDocGenNormalizerTest extends KernelTestCase
$this->normalizer = self::getContainer()->get(NormalizerInterface::class);
}
public function testNormalizationNull()
public function provideNotNullObject(): object
{
$actual = $this->normalizer->normalize(null, 'docgen', [
'docgen:expects' => AccompanyingPeriodWork::class,
AbstractNormalizer::GROUPS => ['docgen:read'],
]);
$work = new AccompanyingPeriodWork();
$work
->addPerson((new Person())->setFirstName('hello')->setLastName('name'))
->addGoal($g = new AccompanyingPeriodWorkGoal())
->addResult($r = new Result())
->setCreatedAt(new \DateTimeImmutable())
->setUpdatedAt(new \DateTimeImmutable())
->setCreatedBy($user = new User())
->setUpdatedBy($user);
$g->addResult($r)->setGoal($goal = new Goal());
$goal->addResult($r);
$expected = [
'id' => '',
];
return $work;
}
$this->assertIsArray($actual);
$this->markTestSkipped('specification still not finalized');
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
public function provideDocGenExpectClass(): string
{
return AccompanyingPeriodWork::class;
}
foreach ($expected as $key => $item) {
if ('@ignored' === $item) {
continue;
}
$this->assertEquals($item, $actual[$key]);
}
public function getNormalizer(): NormalizerInterface
{
return $this->normalizer;
}
public function testNormalize()
@@ -79,20 +84,6 @@ final class AccompanyingPeriodWorkDocGenNormalizerTest extends KernelTestCase
AbstractNormalizer::GROUPS => ['docgen:read'],
]);
$expected = [
'id' => 0,
];
$this->assertIsArray($actual);
$this->markTestSkipped('specification still not finalized');
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
foreach ($expected as $key => $item) {
if (0 === $item) {
continue;
}
$this->assertEquals($item, $actual[$key]);
}
}
}

View File

@@ -40,7 +40,6 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
private const BLANK = [
'id' => '',
'center' => '',
'firstName' => '',
'lastName' => '',
'altNames' => '',
@@ -50,6 +49,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
'birthdate' => ['short' => '', 'long' => ''],
'deathdate' => ['short' => '', 'long' => ''],
'gender' => '',
'genderEntity' => '',
'civility' => '@ignored',
'address' => '@ignored',
'maritalStatus' => '',
@@ -242,7 +242,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
?TranslatorInterface $translator = null,
?TranslatableStringHelper $translatableStringHelper = null,
?NormalizerInterface $normalizer = null,
?SummaryBudgetInterface $summaryBudget = null
?SummaryBudgetInterface $summaryBudget = null,
): PersonDocGenNormalizer {
if (null === $summaryBudget) {
$summaryBudget = $this->prophesize(SummaryBudgetInterface::class);
@@ -257,7 +257,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
$personDocGenNormalizer = new PersonDocGenNormalizer(
$personRender ?? self::getContainer()->get(PersonRender::class),
$relationshipRepository ?? self::getContainer()->get(RelationshipRepository::class),
$translator ?? self::getContainer()->get(TranslatorInterface::class),
// $translator ?? self::getContainer()->get(TranslatorInterface::class),
$translatableStringHelper ?? self::getContainer()->get(TranslatableStringHelperInterface::class),
$summaryBudget->reveal(),
);
@@ -278,7 +278,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
?RelationshipRepository $relationshipRepository = null,
?TranslatorInterface $translator = null,
?TranslatableStringHelper $translatableStringHelper = null,
?SummaryBudgetInterface $summaryBudget = null
?SummaryBudgetInterface $summaryBudget = null,
): PersonDocGenNormalizer {
if (null === $relationshipRepository) {
$relationshipRepository = $this->prophesize(RelationshipRepository::class);
@@ -299,7 +299,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
$normalizer = new PersonDocGenNormalizer(
$personRender ?? self::getContainer()->get(PersonRender::class),
$relationshipRepository,
$translator ?? self::getContainer()->get(TranslatorInterface::class),
// $translator ?? self::getContainer()->get(TranslatorInterface::class),
$translatableStringHelper ?? self::getContainer()->get(TranslatableStringHelperInterface::class),
$summaryBudget->reveal()
);

View File

@@ -68,7 +68,7 @@ final class PersonJsonNormalizerTest extends KernelTestCase
CenterResolverManagerInterface $centerResolverManager,
ResidentialAddressRepository $residentialAddressRepository,
PhoneNumberHelperInterface $phoneNumberHelper,
NormalizerInterface $normalizer
NormalizerInterface $normalizer,
): PersonJsonNormalizer {
$personJsonNormalizer = new PersonJsonNormalizer(
$render,

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

@@ -105,7 +105,7 @@ class AccompanyingPeriodContextTest extends KernelTestCase
AccompanyingPeriod $entity,
array $data,
array $expectedNormalized,
callable $assertionsOnData
callable $assertionsOnData,
): void {
$context = $this->buildContext();
$template = new DocGeneratorTemplate();

View File

@@ -77,7 +77,7 @@ final class PersonContextTest extends KernelTestCase
Person $entity,
array $data,
array $expectedNormalized,
callable $assertionsOnData
callable $assertionsOnData,
): void {
// we boot kernel only for this test
self::bootKernel();
@@ -354,7 +354,7 @@ final class PersonContextTest extends KernelTestCase
?TranslatableStringHelperInterface $translatableStringHelper = null,
?ThirdPartyRender $thirdPartyRender = null,
?ThirdPartyRepository $thirdPartyRepository = null,
?ResidentialAddressRepository $residentialAddressRepository = null
?ResidentialAddressRepository $residentialAddressRepository = null,
): PersonContext {
if (null === $authorizationHelper) {
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class)->reveal();

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Service\GenericDoc\Providers;
use Chill\CalendarBundle\Repository\CalendarDocRepositoryInterface;
use Chill\CalendarBundle\Security\Voter\CalendarVoter;
use Chill\CalendarBundle\Service\GenericDoc\Providers\AccompanyingPeriodCalendarGenericDocProvider;
use Chill\DocStoreBundle\GenericDoc\FetchQueryToSqlBuilder;
@@ -35,11 +36,14 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
private EntityManagerInterface $entityManager;
private CalendarDocRepositoryInterface $calendarDocRepository;
protected function setUp(): void
{
self::bootKernel();
$this->security = self::getContainer()->get(Security::class);
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->calendarDocRepository = self::getContainer()->get(CalendarDocRepositoryInterface::class);
}
/**
@@ -47,7 +51,7 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
*/
public function testBuildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?string $content): void
{
$provider = new AccompanyingPeriodCalendarGenericDocProvider($this->security, $this->entityManager);
$provider = new AccompanyingPeriodCalendarGenericDocProvider($this->security, $this->entityManager, $this->calendarDocRepository);
$query = $provider->buildFetchQueryForAccompanyingPeriod($accompanyingPeriod, $startDate, $endDate, $content);
@@ -66,7 +70,7 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
$security = $this->prophesize(Security::class);
$security->isGranted(CalendarVoter::SEE, Argument::any())->willReturn(true);
$provider = new AccompanyingPeriodCalendarGenericDocProvider($security->reveal(), $this->entityManager);
$provider = new AccompanyingPeriodCalendarGenericDocProvider($security->reveal(), $this->entityManager, $this->calendarDocRepository);
$query = $provider->buildFetchQueryForPerson($person, $startDate, $endDate, $content);
@@ -87,7 +91,7 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
$security = $this->prophesize(Security::class);
$security->isGranted(CalendarVoter::SEE, Argument::any())->willReturn(false);
$provider = new AccompanyingPeriodCalendarGenericDocProvider($security->reveal(), $this->entityManager);
$provider = new AccompanyingPeriodCalendarGenericDocProvider($security->reveal(), $this->entityManager, $this->calendarDocRepository);
$query = $provider->buildFetchQueryForPerson($person, $startDate, $endDate, $content);

View File

@@ -9,10 +9,11 @@ declare(strict_types=1);
* the LICENSE file that was distributed with this source code.
*/
namespace Service\GenericDoc\Providers;
namespace Chill\PersonBundle\Tests\Service\GenericDoc\Providers;
use Chill\DocStoreBundle\GenericDoc\FetchQueryToSqlBuilder;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
use Chill\PersonBundle\Service\GenericDoc\Providers\AccompanyingPeriodWorkEvaluationGenericDocProvider;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
@@ -29,10 +30,13 @@ class AccompanyingPeriodWorkEvaluationGenericDocProviderTest extends KernelTestC
use ProphecyTrait;
private EntityManagerInterface $entityManager;
private AccompanyingPeriodWorkEvaluationDocumentRepository $repository;
protected function setUp(): void
{
self::bootKernel();
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->repository = self::getContainer()->get(AccompanyingPeriodWorkEvaluationDocumentRepository::class);
}
/**
@@ -41,7 +45,7 @@ class AccompanyingPeriodWorkEvaluationGenericDocProviderTest extends KernelTestC
public function testBuildFetchQueryForAccompanyingPeriod(
?\DateTimeImmutable $startDate = null,
?\DateTimeImmutable $endDate = null,
?string $content = null
?string $content = null,
): void {
$period = $this->entityManager->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a')
->setMaxResults(1)
@@ -55,7 +59,8 @@ class AccompanyingPeriodWorkEvaluationGenericDocProviderTest extends KernelTestC
$provider = new AccompanyingPeriodWorkEvaluationGenericDocProvider(
$security->reveal(),
$this->entityManager
$this->entityManager,
$this->repository,
);
$query = $provider->buildFetchQueryForAccompanyingPeriod($period, $startDate, $endDate, $content);

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();
}
}