mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Generate a context for docgen, on accompanying period
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
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 ($item === '@ignored') {
|
||||
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 ($item === '@ignored') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertEquals($item, $data[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user