Create a PickUserGroupOrUserDynamicType

- add necessary vue component to render usergroup within the component AddPersons;
- add necessary normalization and denormalization process for matching the selected usergroup with entities in database
This commit is contained in:
2024-09-26 15:10:34 +02:00
parent 9e69c97250
commit 82cd77678b
12 changed files with 340 additions and 8 deletions

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 Serializer\Normalizer;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
use Chill\MainBundle\Serializer\Normalizer\UserGroupDenormalizer;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class UserGroupDenormalizerTest extends TestCase
{
/**
* @throws \PHPUnit\Framework\MockObject\Exception
*
* @dataProvider provideSupportsDenormalization
*/
public function testSupportsDenormalization($data, string $type, bool $expected): void
{
$repository = $this->createMock(UserGroupRepositoryInterface::class);
$denormalizer = new UserGroupDenormalizer($repository);
$actual = $denormalizer->supportsDenormalization($data, $type, 'json');
self::assertSame($expected, $actual);
}
public static function provideSupportsDenormalization(): iterable
{
yield [['type' => 'user_group', 'id' => 10], UserGroup::class, true];
yield [['type' => 'person', 'id' => 10], UserGroup::class, false];
yield [['type' => 'user_group', 'id' => 10], \stdClass::class, false];
}
public function testDenormalize(): void
{
$repository = $this->createMock(UserGroupRepositoryInterface::class);
$repository->expects($this->once())
->method('find')
->with(10)
->willReturn($userGroup = new UserGroup());
$denormalizer = new UserGroupDenormalizer($repository);
$actual = $denormalizer->denormalize(['type' => 'user_group', 'id' => 10], UserGroup::class, 'json');
self::assertSame($userGroup, $actual);
}
}

View File

@@ -0,0 +1,56 @@
<?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\MainBundle\Tests\Serializer\Normalizer;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Serializer\Normalizer\UserGroupNormalizer;
use Chill\MainBundle\Templating\Entity\UserGroupRenderInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
/**
* @internal
*
* @coversNothing
*/
class UserGroupNormalizerTest extends TestCase
{
public function testNormalize()
{
$userGroup = new UserGroup();
$userGroup
->setLabel(['fr' => 'test'])
->setExcludeKey('top')
->setForegroundColor('#123456')
->setBackgroundColor('#456789');
$entityRender = $this->createMock(UserGroupRenderInterface::class);
$entityRender->expects($this->once())
->method('renderString')
->with($userGroup, [])
->willReturn('text');
$normalizer = new UserGroupNormalizer($entityRender);
$actual = $normalizer->normalize($userGroup, 'json', [AbstractNormalizer::GROUPS => ['read']]);
self::assertEqualsCanonicalizing([
'type' => 'user_group',
'text' => 'text',
'label' => ['fr' => 'test'],
'excludeKey' => 'top',
'foregroundColor' => '#123456',
'backgroundColor' => '#456789',
'id' => null,
], $actual);
}
}