diff --git a/docs/source/installation/index.rst b/docs/source/installation/index.rst
index 00f27ed69..01a8c4aee 100644
--- a/docs/source/installation/index.rst
+++ b/docs/source/installation/index.rst
@@ -265,7 +265,7 @@ Tests reside inside the installed bundles. You must `cd` into that directory, do
**Note**: some bundle require the fixture to be executed. See the dedicated _how-tos_.
-Exemple, for running test inside `main` bundle:
+Exemple, for running unit test inside `main` bundle:
.. code-block:: bash
@@ -280,6 +280,30 @@ Exemple, for running test inside `main` bundle:
# run tests
bin/phpunit src/Bundle/path/to/your/test
+Or for running tests to check code style and php conventions with csfixer and phpstan:
+
+.. code-block:: bash
+
+ # run code style fixer
+ bin/grumphp run --tasks=phpcsfixer
+ # run phpstan
+ bin/grumphp run --tasks=phpstan
+
+
+.. note::
+
+ To avoid phpstan block your commits:
+
+ .. code-block:: bash
+
+ git commit -n ...
+
+ To avoid phpstan block your commits permanently:
+
+ .. code-block:: bash
+
+ ./bin/grumphp git:deinit
+
How to run webpack interactively
================================
diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php
index bb65fb5b2..c365b5e06 100644
--- a/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php
+++ b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php
@@ -14,6 +14,8 @@ namespace Chill\DocGeneratorBundle\Controller;
use Chill\DocGeneratorBundle\Context\ContextManager;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\MainBundle\CRUD\Controller\CRUDController;
+use Chill\MainBundle\Pagination\PaginatorInterface;
+use Doctrine\ORM\QueryBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@@ -84,4 +86,16 @@ class AdminDocGeneratorTemplateController extends CRUDController
return $entity;
}
+
+ /**
+ * @param QueryBuilder $query
+ *
+ * @return QueryBuilder|mixed
+ */
+ protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
+ {
+ return $query->addSelect('JSON_EXTRACT(e.name, :lang) AS HIDDEN name_lang')
+ ->setParameter('lang', $request->getLocale())
+ ->addOrderBy('name_lang', 'ASC');
+ }
}
diff --git a/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php b/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php
index 4f800fd6a..6a80c34dc 100644
--- a/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php
+++ b/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php
@@ -15,14 +15,18 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
+use Symfony\Component\HttpFoundation\RequestStack;
final class DocGeneratorTemplateRepository implements ObjectRepository
{
private EntityRepository $repository;
- public function __construct(EntityManagerInterface $entityManager)
+ private RequestStack $requestStack;
+
+ public function __construct(EntityManagerInterface $entityManager, RequestStack $requestStack)
{
$this->repository = $entityManager->getRepository(DocGeneratorTemplate::class);
+ $this->requestStack = $requestStack;
}
public function countByEntity(string $entity): int
@@ -71,7 +75,10 @@ final class DocGeneratorTemplateRepository implements ObjectRepository
$builder
->where('t.entity LIKE :entity')
->andWhere($builder->expr()->eq('t.active', "'TRUE'"))
- ->setParameter('entity', addslashes($entity));
+ ->setParameter('entity', addslashes($entity))
+ ->addSelect('JSON_EXTRACT(t.name, :lang) AS HIDDEN name_lang')
+ ->setParameter('lang', $this->requestStack->getCurrentRequest()->getLocale())
+ ->addOrderBy('name_lang', 'ASC');
return $builder
->getQuery()
diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig
index 7b24eae0d..35fa6e319 100644
--- a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig
+++ b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig
@@ -2,6 +2,14 @@
{% block title 'docgen.Generate a document'|trans %}
+{% block js %}
+ {{ encore_entry_script_tags('mod_pickentity_type') }}
+{% endblock %}
+
+{% block css %}
+ {{ encore_entry_link_tags('mod_pickentity_type') }}
+{% endblock %}
+
{% block content %}
{{ block('title') }}
diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Context/BaseContextData.php b/src/Bundle/ChillDocGeneratorBundle/Service/Context/BaseContextData.php
index cbeeaeb16..e7b56ed88 100644
--- a/src/Bundle/ChillDocGeneratorBundle/Service/Context/BaseContextData.php
+++ b/src/Bundle/ChillDocGeneratorBundle/Service/Context/BaseContextData.php
@@ -42,6 +42,9 @@ class BaseContextData
$data['createdAt'] = $this->normalizer->normalize(new DateTimeImmutable(), 'docgen', [
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
]);
+ $data['createdAtDate'] = $this->normalizer->normalize(new DateTimeImmutable('today'), 'docgen', [
+ 'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
+ ]);
$data['location'] = $this->normalizer->normalize(
$user instanceof User ? $user->getCurrentLocation() : null,
'docgen',
diff --git a/src/Bundle/ChillDocGeneratorBundle/tests/Serializer/Normalizer/DocGenObjectNormalizerTest.php b/src/Bundle/ChillDocGeneratorBundle/tests/Serializer/Normalizer/DocGenObjectNormalizerTest.php
index de2a8775a..3250d4d5a 100644
--- a/src/Bundle/ChillDocGeneratorBundle/tests/Serializer/Normalizer/DocGenObjectNormalizerTest.php
+++ b/src/Bundle/ChillDocGeneratorBundle/tests/Serializer/Normalizer/DocGenObjectNormalizerTest.php
@@ -77,6 +77,19 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
$this->assertArrayNotHasKey('baz', $actual['child']);
}
+ public function testNormalizableBooleanPropertyOrMethodOnNull()
+ {
+ $actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => TestableClassWithBool::class]);
+
+ $expected = [
+ 'foo' => null,
+ 'thing' => null,
+ 'isNull' => true,
+ ];
+
+ $this->assertEquals($expected, $actual);
+ }
+
public function testNormalizationBasic()
{
$scope = new Scope();
@@ -93,6 +106,22 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
$this->assertEquals($expected, $normalized, 'test normalization fo a scope');
}
+ public function testNormalizeBooleanPropertyOrMethod()
+ {
+ $testable = new TestableClassWithBool();
+ $testable->foo = false;
+
+ $actual = $this->normalizer->normalize($testable, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => TestableClassWithBool::class]);
+
+ $expected = [
+ 'foo' => false,
+ 'thing' => true,
+ 'isNull' => false,
+ ];
+
+ $this->assertEquals($expected, $actual);
+ }
+
public function testNormalizeNull()
{
$actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Scope::class]);
@@ -170,3 +199,19 @@ class TestableChildClass
*/
public string $foo = 'bar';
}
+
+class TestableClassWithBool
+{
+ /**
+ * @Serializer\Groups("docgen:read")
+ */
+ public bool $foo;
+
+ /**
+ * @Serializer\Groups("docgen:read")
+ */
+ public function getThing(): bool
+ {
+ return true;
+ }
+}
diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php
index f1fe4c44d..17c6e0b64 100644
--- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php
+++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php
@@ -28,6 +28,7 @@ use Chill\MainBundle\Doctrine\DQL\GetJsonFieldByKey;
use Chill\MainBundle\Doctrine\DQL\JsonAggregate;
use Chill\MainBundle\Doctrine\DQL\JsonbArrayLength;
use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray;
+use Chill\MainBundle\Doctrine\DQL\JsonExtract;
use Chill\MainBundle\Doctrine\DQL\OverlapsI;
use Chill\MainBundle\Doctrine\DQL\Replace;
use Chill\MainBundle\Doctrine\DQL\Similarity;
@@ -232,6 +233,7 @@ class ChillMainExtension extends Extension implements
'GET_JSON_FIELD_BY_KEY' => GetJsonFieldByKey::class,
'AGGREGATE' => JsonAggregate::class,
'REPLACE' => Replace::class,
+ 'JSON_EXTRACT' => JsonExtract::class,
],
'numeric_functions' => [
'JSONB_EXISTS_IN_ARRAY' => JsonbExistsInArray::class,
diff --git a/src/Bundle/ChillMainBundle/Doctrine/DQL/JsonExtract.php b/src/Bundle/ChillMainBundle/Doctrine/DQL/JsonExtract.php
new file mode 100644
index 000000000..9f93c437e
--- /dev/null
+++ b/src/Bundle/ChillMainBundle/Doctrine/DQL/JsonExtract.php
@@ -0,0 +1,43 @@
+>%s', $this->element->dispatch($sqlWalker), $this->keyToExtract->dispatch($sqlWalker));
+ }
+
+ public function parse(Parser $parser)
+ {
+ $parser->match(Lexer::T_IDENTIFIER);
+ $parser->match(Lexer::T_OPEN_PARENTHESIS);
+
+ $this->element = $parser->ArithmeticPrimary();
+
+ $parser->match(Lexer::T_COMMA);
+
+ $this->keyToExtract = $parser->ArithmeticExpression();
+
+ $parser->match(Lexer::T_CLOSE_PARENTHESIS);
+ }
+}
diff --git a/src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/JsonExtractTest.php b/src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/JsonExtractTest.php
new file mode 100644
index 000000000..3f2b3eb2f
--- /dev/null
+++ b/src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/JsonExtractTest.php
@@ -0,0 +1,52 @@
+em = self::$container->get(EntityManagerInterface::class);
+ }
+
+ public function dataGenerateDql(): iterable
+ {
+ yield ['SELECT JSON_EXTRACT(c.name, \'fr\') FROM ' . Country::class . ' c', []];
+
+ yield ['SELECT JSON_EXTRACT(c.name, :lang) FROM ' . Country::class . ' c', ['lang' => 'fr']];
+ }
+
+ /**
+ * @dataProvider dataGenerateDql
+ */
+ public function testJsonExtract(string $dql, array $args)
+ {
+ $results = $this->em->createQuery($dql)
+ ->setMaxResults(2)
+ ->setParameters($args)
+ ->getResult();
+
+ $this->assertIsArray($results, 'simply test that the query return a result');
+ }
+}
diff --git a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php
index 905ca1185..9305cbf09 100644
--- a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php
+++ b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php
@@ -72,7 +72,7 @@ final class ValidPhonenumber extends ConstraintValidator
}
if (false === $isValid) {
- $this->context->addViolation($message, ['%phonenumber%' => $value]);
+ $this->context->addViolation($message, ['%phonenumber%' => $value, '%formatted%' => $this->phonenumberHelper->format($value)]);
}
}
}
diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php
index a9ebdc0bb..af6c6e114 100644
--- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php
+++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php
@@ -11,8 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Service\DocGenerator;
-use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
-use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
@@ -34,6 +32,7 @@ use Doctrine\ORM\EntityRepository;
use LogicException;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
+use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -42,7 +41,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
use function count;
-class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
+final class PersonContext implements PersonContextInterface
{
private AuthorizationHelperInterface $authorizationHelper;
@@ -129,6 +128,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
'choice_label' => function ($entity = null) {
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
},
+ 'required' => true,
]);
}
@@ -137,11 +137,19 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
{
- $builder->add('scope', ScopePickerType::class, [
- 'center' => $this->centerResolverManager->resolveCenters($entity),
- 'role' => PersonDocumentVoter::CREATE,
- 'label' => 'Scope',
+ $builder->add('title', TextType::class, [
+ 'required' => true,
+ 'label' => 'docgen.Document title',
+ 'data' => $this->translatableStringHelper->localize($template->getName()),
]);
+
+ if ($this->isScopeNecessary($entity)) {
+ $builder->add('scope', ScopePickerType::class, [
+ 'center' => $this->centerResolverManager->resolveCenters($entity),
+ 'role' => PersonDocumentVoter::CREATE,
+ 'label' => 'Scope',
+ ]);
+ }
}
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
@@ -200,7 +208,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
*/
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
{
- return $this->isScopeNecessary($entity);
+ return true;
}
/**
@@ -210,7 +218,9 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
{
$doc = new PersonDocument();
$doc->setTemplate($template)
- ->setTitle($this->translatableStringHelper->localize($template->getName()))
+ ->setTitle(
+ $contextGenerationData['title'] ?? $this->translatableStringHelper->localize($template->getName())
+ )
->setDate(new DateTime())
->setDescription($this->translatableStringHelper->localize($template->getName()))
->setPerson($entity)
diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php
new file mode 100644
index 000000000..58a6b5863
--- /dev/null
+++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php
@@ -0,0 +1,55 @@
+personContext = $personContext;
+ $this->normalizer = $normalizer;
+ }
+
+ public function adminFormReverseTransform(array $data): array
+ {
+ return array_merge(
+ $this->personContext->adminFormReverseTransform($data),
+ ['label' => $data['label']]
+ );
+ }
+
+ public function adminFormTransform(array $data): array
+ {
+ return array_merge(
+ $this->personContext->adminFormTransform($data),
+ ['label' => $data['label'] ?? '']
+ );
+ }
+
+ public function buildAdminForm(FormBuilderInterface $builder): void
+ {
+ $this->personContext->buildAdminForm($builder);
+
+ $builder->add('label', TextType::class, [
+ 'label' => 'docgen.Label for third party',
+ 'required' => true,
+ ]);
+ }
+
+ public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
+ {
+ $this->personContext->buildPublicForm($builder, $template, $entity);
+
+ $builder->add('thirdParty', PickThirdpartyDynamicType::class, [
+ 'multiple' => false,
+ 'label' => $template->getOptions()['label'] ?? 'ThirdParty',
+ 'validation_groups' => ['__none__'],
+ ]);
+ }
+
+ public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
+ {
+ $data = $this->personContext->getData($template, $entity, $contextGenerationData);
+
+ $data['thirdParty'] = $this->normalizer->normalize(
+ $contextGenerationData['thirdParty'],
+ 'docgen',
+ ['docgen:expects' => ThirdParty::class, 'groups' => ['docgen:read']]
+ );
+
+ return $data;
+ }
+
+ public function getDescription(): string
+ {
+ return 'docgen.A context for person with a third party (for sending mail)';
+ }
+
+ public function getEntityClass(): string
+ {
+ return $this->personContext->getEntityClass();
+ }
+
+ public function getFormData(DocGeneratorTemplate $template, $entity): array
+ {
+ return $this->personContext->getFormData($template, $entity);
+ }
+
+ public static function getKey(): string
+ {
+ return self::class;
+ }
+
+ public function getName(): string
+ {
+ return 'docgen.Person with third party';
+ }
+
+ public function hasAdminForm(): bool
+ {
+ return true;
+ }
+
+ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
+ {
+ return true;
+ }
+
+ public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
+ {
+ $this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData);
+ }
+}
diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodResourceNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodResourceNormalizerTest.php
new file mode 100644
index 000000000..0c4188826
--- /dev/null
+++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodResourceNormalizerTest.php
@@ -0,0 +1,67 @@
+normalizer = self::$container->get(NormalizerInterface::class);
+ }
+
+ public function testNormalizeNullHasSameValueAsNotNull()
+ {
+ $nullResource = $this->normalizer->normalize(null, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
+ $notNull = $this->normalizer->normalize(new Resource(), 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
+
+ $this->assertEqualsCanonicalizing(array_keys($notNull), array_keys($nullResource));
+ }
+
+ public function testNormalizeResource()
+ {
+ $resource = new Resource();
+ $resource
+ ->setComment('blabla')
+ ->setResource(new ThirdParty());
+
+ $expected = [
+ 'type' => 'accompanying_period_resource',
+ 'isNull' => false,
+ 'comment' => 'blabla',
+ ];
+
+ $actual = $this->normalizer->normalize($resource, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
+
+ // we do not test for sub array (person, thirdparty). We then check first for base value...
+ foreach ($expected as $key => $value) {
+ $this->assertArrayHasKey($key, $actual);
+ $this->assertEquals($value, $actual[$key]);
+ }
+
+ // ... and then for the existence of some values
+ $this->assertArrayHasKey('person', $actual);
+ $this->assertArrayHasKey('thirdParty', $actual);
+ }
+}
diff --git a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php
index c7c9a00e4..44414cdba 100644
--- a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php
+++ b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextTest.php
@@ -21,6 +21,7 @@ use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
+use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
@@ -33,6 +34,8 @@ use Prophecy\Exception\Prediction\FailedPredictionException;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
+use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -82,7 +85,7 @@ final class PersonContextTest extends TestCase
$parameter
);
- $this->assertFalse($personContext->hasPublicForm($docGen, $person));
+ $personContext->buildPublicForm($this->buildFormBuilder(false), $docGen, $person);
$personContext->storeGenerated(
$docGen,
@@ -126,7 +129,7 @@ final class PersonContextTest extends TestCase
$em->reveal(),
);
- $this->assertTrue($personContext->hasPublicForm($docGen, $person));
+ $personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
$personContext->storeGenerated(
$docGen,
@@ -170,7 +173,7 @@ final class PersonContextTest extends TestCase
$em->reveal(),
);
- $this->assertTrue($personContext->hasPublicForm($docGen, $person));
+ $personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
$personContext->storeGenerated(
$docGen,
@@ -180,6 +183,24 @@ final class PersonContextTest extends TestCase
);
}
+ private function buildFormBuilder(bool $withScope): FormBuilderInterface
+ {
+ $builder = $this->prophesize(FormBuilderInterface::class);
+
+ $builder->add('title', TextType::class, Argument::type('array'))
+ ->shouldBeCalled(1);
+
+ if ($withScope) {
+ $builder->add('scope', ScopePickerType::class, Argument::type('array'))
+ ->shouldBeCalled();
+ } else {
+ $builder->add('scope', ScopePickerType::class, Argument::type('array'))
+ ->shouldNotBeCalled();
+ }
+
+ return $builder->reveal();
+ }
+
private function buildPersonContext(
?AuthorizationHelperInterface $authorizationHelper = null,
?BaseContextData $baseContextData = null,
diff --git a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextWithThirdPartyTest.php b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextWithThirdPartyTest.php
new file mode 100644
index 000000000..a4f08e7c1
--- /dev/null
+++ b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextWithThirdPartyTest.php
@@ -0,0 +1,93 @@
+buildPersonContextWithThirdParty();
+
+ $actual = $personContext->adminFormReverseTransform(['label' => 'bloup']);
+
+ $this->assertArrayHasKey('category', $actual);
+ $this->assertArrayHasKey('label', $actual);
+ $this->assertEquals('bloup', $actual['label']);
+ }
+
+ public function testAdminFormTransform()
+ {
+ $personContext = $this->buildPersonContextWithThirdParty();
+
+ $actual = $personContext->adminFormTransform(['label' => 'bloup']);
+
+ $this->assertArrayHasKey('from_person', $actual);
+ $this->assertArrayHasKey('label', $actual);
+ $this->assertEquals('bloup', $actual['label']);
+ }
+
+ public function testGetData()
+ {
+ $personContext = $this->buildPersonContextWithThirdParty();
+
+ $actual = $personContext->getData(
+ (new DocGeneratorTemplate())->setOptions(['label' => 'bloup']),
+ new Person(),
+ ['thirdParty' => $tp = new ThirdParty()]
+ );
+
+ $this->assertArrayHasKey('person', $actual);
+ $this->assertArrayHasKey('thirdParty', $actual);
+ $this->assertEquals(spl_object_hash($tp), $actual['thirdParty']['hash']);
+ }
+
+ private function buildPersonContextWithThirdParty(): PersonContextWithThirdParty
+ {
+ $normalizer = $this->prophesize(NormalizerInterface::class);
+ $normalizer->normalize(Argument::type(ThirdParty::class), 'docgen', Argument::type('array'))
+ ->will(static function ($args): array {
+ return ['class' => '3party', 'hash' => spl_object_hash($args[0])];
+ });
+
+ $personContext = $this->prophesize(PersonContextInterface::class);
+
+ $personContext->adminFormReverseTransform(Argument::type('array'))->willReturn(
+ ['category' => ['idInsideBundle' => 1, 'bundleId' => 'abc']]
+ );
+ $personContext->adminFormTransform(Argument::type('array'))->willReturn(
+ ['from_person' => 'kept']
+ );
+ $personContext->getData(Argument::type(DocGeneratorTemplate::class), Argument::type(Person::class), Argument::type('array'))
+ ->willReturn(['person' => 'data']);
+
+ return new PersonContextWithThirdParty(
+ $personContext->reveal(),
+ $normalizer->reveal()
+ );
+ }
+}
diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml
index 191ef6091..f3fd6c430 100644
--- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml
+++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml
@@ -889,6 +889,10 @@ docgen:
A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement
Person basic: Personne (basique)
A basic context for person: Contexte pour les personnes
+ Person with third party: Personne avec choix d'un tiers
+ A context for person with a third party (for sending mail): Un contexte d'une personne avec un tiers (pour envoyer un courrier à ce tiers, par exemple)
+ Label for third party: Label à afficher aux utilisateurs
+ Document title: Titre du document généré
period_notification:
period_designated_subject: Vous êtes référent d'un parcours d'accompagnement
diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php
index 119afff11..2e8cebfb6 100644
--- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php
+++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php
@@ -214,7 +214,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(name="kind", type="string", length="20", options={"default": ""})
- * @Groups({"write"})
+ * @Groups({"write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?string $kind = '';