mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Merge branch '111_exports_suite' into calendar/finalization
This commit is contained in:
79
src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/AgeTest.php
Normal file
79
src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/AgeTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?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\Doctrine\DQL;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AgeTest extends KernelTestCase
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function generateQueries(): iterable
|
||||
{
|
||||
yield [
|
||||
'SELECT AGE(a.validFrom, a.validTo) FROM ' . Address::class . ' a',
|
||||
[],
|
||||
];
|
||||
|
||||
yield [
|
||||
'SELECT AGE(:date0, :date1) FROM ' . Address::class . ' a',
|
||||
[
|
||||
'date0' => new DateTimeImmutable('now'),
|
||||
'date1' => new DateTimeImmutable('2020-01-01'),
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'SELECT AGE(a.validFrom, :date1) FROM ' . Address::class . ' a',
|
||||
[
|
||||
'date1' => new DateTimeImmutable('now'),
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
'SELECT AGE(:date0, a.validFrom) FROM ' . Address::class . ' a',
|
||||
[
|
||||
'date0' => new DateTimeImmutable('now'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateQueries
|
||||
*/
|
||||
public function testWorking(string $dql, array $args)
|
||||
{
|
||||
$dql = $this->entityManager->createQuery($dql)->setMaxResults(3);
|
||||
|
||||
foreach ($args as $key => $value) {
|
||||
$dql->setParameter($key, $value);
|
||||
}
|
||||
|
||||
$results = $dql->getResult();
|
||||
|
||||
$this->assertIsArray($results);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?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 Doctrine\DQL;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class JsonbExistsInArrayTest extends KernelTestCase
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->em = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testDQLFunctionWorks()
|
||||
{
|
||||
$result = $this->em
|
||||
->createQuery('SELECT JSONB_EXISTS_IN_ARRAY(u.attributes, :param) FROM ' . User::class . ' u')
|
||||
->setParameter('param', 'fr')
|
||||
->getResult();
|
||||
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,127 @@
|
||||
<?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 Form\Type;
|
||||
|
||||
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\Templating\TranslatableStringHelperInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\PreloadedExtension;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ScopePickerTypeTest extends TypeTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testBuildOneScopeIsSuccessful()
|
||||
{
|
||||
$form = $this->factory->create(ScopePickerType::class, null, [
|
||||
'center' => new Center(),
|
||||
'role' => 'ONE_SCOPE',
|
||||
]);
|
||||
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertContains('hidden', $view['scope']->vars['block_prefixes']);
|
||||
}
|
||||
|
||||
public function testBuildThreeScopesIsSuccessful()
|
||||
{
|
||||
$form = $this->factory->create(ScopePickerType::class, null, [
|
||||
'center' => new Center(),
|
||||
'role' => 'THREE_SCOPE',
|
||||
]);
|
||||
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertContains('entity', $view['scope']->vars['block_prefixes']);
|
||||
}
|
||||
|
||||
public function testBuildTwoScopesIsSuccessful()
|
||||
{
|
||||
$form = $this->factory->create(ScopePickerType::class, null, [
|
||||
'center' => new Center(),
|
||||
'role' => 'TWO_SCOPE',
|
||||
]);
|
||||
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertContains('entity', $view['scope']->vars['block_prefixes']);
|
||||
}
|
||||
|
||||
protected function getExtensions()
|
||||
{
|
||||
$user = new User();
|
||||
$role1Scope = 'ONE_SCOPE';
|
||||
$role2Scope = 'TWO_SCOPE';
|
||||
$role3Scope = 'THREE_SCOPE';
|
||||
$scopeA = (new Scope())->setName(['fr' => 'scope a']);
|
||||
$scopeB = (new Scope())->setName(['fr' => 'scope b']);
|
||||
$scopeC = (new Scope())->setName(['fr' => 'scope b'])->setActive(false);
|
||||
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableScopes($user, $role1Scope, Argument::any())
|
||||
->willReturn([$scopeA]);
|
||||
$authorizationHelper->getReachableScopes($user, $role2Scope, Argument::any())
|
||||
->willReturn([$scopeA, $scopeB]);
|
||||
$authorizationHelper->getReachableScopes($user, $role3Scope, Argument::any())
|
||||
->willReturn([$scopeA, $scopeB, $scopeC]);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
|
||||
$translatableStringHelper->localize(Argument::type('array'))->will(
|
||||
static function ($args) { return $args[0]['fr']; }
|
||||
);
|
||||
|
||||
$type = new ScopePickerType(
|
||||
$authorizationHelper->reveal(),
|
||||
$security->reveal(),
|
||||
$translatableStringHelper->reveal()
|
||||
);
|
||||
|
||||
// add the mocks for creating EntityType
|
||||
$entityManager = DoctrineTestHelper::createTestEntityManager();
|
||||
$em = $this->prophesize(EntityManagerInterface::class);
|
||||
$em->getClassMetadata(Scope::class)->willReturn($entityManager->getClassMetadata(Scope::class));
|
||||
$em->contains(Argument::type(Scope::class))->willReturn(true);
|
||||
$em->initializeObject(Argument::type(Scope::class))->will(static fn ($o) => $o);
|
||||
$emRevealed = $em->reveal();
|
||||
$managerRegistry = $this->prophesize(ManagerRegistry::class);
|
||||
$managerRegistry->getManager(Argument::any())->willReturn($emRevealed);
|
||||
$managerRegistry->getManagerForClass(Scope::class)->willReturn($emRevealed);
|
||||
|
||||
$entityType = $this->prophesize(EntityType::class);
|
||||
$entityType->getParent()->willReturn(ChoiceType::class);
|
||||
|
||||
return [
|
||||
new PreloadedExtension([$type], []),
|
||||
new DoctrineOrmExtension($managerRegistry->reveal()),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user