mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
138 lines
4.5 KiB
PHP
138 lines
4.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Serializer\Normalizer;
|
|
|
|
use Chill\MainBundle\Entity\Scope;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
|
|
/**
|
|
* @internal
|
|
* @coversNothing
|
|
*/
|
|
final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|
{
|
|
private NormalizerInterface $normalizer;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
self::bootKernel();
|
|
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
|
}
|
|
|
|
public function testNormalize()
|
|
{
|
|
$period = new AccompanyingPeriod();
|
|
$period->setConfidential(true);
|
|
$period->setEmergency(true);
|
|
$period->setOrigin((new AccompanyingPeriod\Origin())->setLabel(['fr' => 'origin']));
|
|
$period->setClosingMotive((new AccompanyingPeriod\ClosingMotive())->setName(['closing']));
|
|
$period->addScope((new Scope())->setName(['fr' => 'scope1']));
|
|
$period->addScope((new Scope())->setName(['fr' => 'scope2']));
|
|
$period->addSocialIssue((new SocialIssue())->setTitle(['fr' => 'issue1']));
|
|
$period->addSocialIssue((new SocialIssue())->setTitle(['fr' => 'issue2']));
|
|
$data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
|
|
|
$expected = [
|
|
'id' => null,
|
|
'closingDate' => '@ignored',
|
|
'confidential' => true,
|
|
'confidentialText' => 'confidentiel',
|
|
'createdAt' => '@ignored',
|
|
'createdBy' => '@ignored',
|
|
'emergency' => true,
|
|
'emergencyText' => 'Urgent',
|
|
'openingDate' => '@ignored',
|
|
'originText' => 'origin',
|
|
'requestorAnonymous' => false,
|
|
'socialIssues' => '@ignored',
|
|
'intensity' => 'ponctuel',
|
|
'step' => 'Brouillon',
|
|
'closingMotiveText' => 'closing',
|
|
'socialIssuesText' => 'issue1, issue2',
|
|
'scopes' => '@ignored',
|
|
'scopesText' => 'scope1, scope2',
|
|
'ref' => '@ignored',
|
|
'participations' => '@ignored',
|
|
];
|
|
|
|
$this->assertIsArray($data);
|
|
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
|
|
|
|
foreach ($expected as $key => $item) {
|
|
if ('@ignored' === $item) {
|
|
continue;
|
|
}
|
|
|
|
$this->assertEquals($item, $data[$key]);
|
|
}
|
|
}
|
|
|
|
public function testNormalizeNull()
|
|
{
|
|
$data = $this->normalizer->normalize(null, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
|
|
|
$expected = [
|
|
'id' => '',
|
|
'closingDate' => '@ignored',
|
|
'confidential' => '',
|
|
'confidentialText' => '',
|
|
'createdAt' => '@ignored',
|
|
'createdBy' => '@ignored',
|
|
'emergency' => '',
|
|
'emergencyText' => '',
|
|
'openingDate' => '@ignored',
|
|
'originText' => '',
|
|
'requestorAnonymous' => '',
|
|
'socialIssues' => '@ignored',
|
|
'intensity' => '',
|
|
'step' => '',
|
|
'closingMotiveText' => '',
|
|
'socialIssuesText' => '',
|
|
'scopes' => '@ignored',
|
|
'scopesText' => '',
|
|
'ref' => '@ignored',
|
|
'participations' => '@ignored',
|
|
];
|
|
|
|
$this->assertIsArray($data);
|
|
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
|
|
|
|
foreach ($expected as $key => $item) {
|
|
if ('@ignored' === $item) {
|
|
continue;
|
|
}
|
|
|
|
$this->assertEquals($item, $data[$key]);
|
|
}
|
|
}
|
|
|
|
public function testNormalizeParticipations()
|
|
{
|
|
$period = new AccompanyingPeriod();
|
|
$period->addPerson($person = new Person());
|
|
$person->setFirstName('test');
|
|
|
|
$data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
|
|
|
$this->assertIsArray($data);
|
|
$this->assertArrayHasKey('participations', $data);
|
|
$this->assertCount(1, $data['participations']);
|
|
|
|
$this->assertArrayHasKey('currentParticipations', $data);
|
|
$this->assertCount(1, $data['currentParticipations']);
|
|
}
|
|
}
|