mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-01 10:59:45 +00:00
Partage d'export enregistré et génération asynchrone des exports
This commit is contained in:
@@ -23,6 +23,7 @@ use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ReferrerS
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\Clock\MockClock;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -49,7 +50,7 @@ final class ReferrerScopeAggregatorTest extends AbstractAggregatorTest
|
||||
return new ReferrerScopeAggregator(
|
||||
$scopeRepository->reveal(),
|
||||
$translatableStringHelper->reveal(),
|
||||
new RollingDateConverter(),
|
||||
new RollingDateConverter(new MockClock()),
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -60,4 +60,29 @@ final class ReferrerAggregatorTest extends AbstractAggregatorTest
|
||||
->from(AccompanyingPeriodWork::class, 'acpw'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderFormDataToNormalize
|
||||
*/
|
||||
public function testDataNormalization(array $data, int $version, array $customAssert): void
|
||||
{
|
||||
$aggregator = $this->getAggregator();
|
||||
|
||||
$normalized = $aggregator->normalizeFormData($data);
|
||||
$actual = $aggregator->denormalizeFormData($normalized, $version);
|
||||
|
||||
self::assertIsArray($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of data to normalize.
|
||||
*
|
||||
* @return iterable{array}
|
||||
*/
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
foreach (self::getFormData() as $data) {
|
||||
yield [$data, 1, []];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Chill\MainBundle\Test\Export\AbstractExportTest;
|
||||
@@ -27,7 +27,6 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -57,22 +56,13 @@ class ListAccompanyingPeriodTest extends AbstractExportTest
|
||||
$centerRepository = self::getContainer()->get(CenterRepositoryInterface::class);
|
||||
$scopeRepository = self::getContainer()->get(ScopeRepositoryInterface::class);
|
||||
|
||||
// mock security
|
||||
$user = $em->createQuery('SELECT u FROM '.User::class.' u')
|
||||
->setMaxResults(1)->getSingleResult();
|
||||
if (null === $user) {
|
||||
throw new \RuntimeException('no user found');
|
||||
}
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
// mock authorization helper
|
||||
$scopes = $scopeRepository->findAll();
|
||||
$scopesConfidentials = [] !== $scopes ? [$scopes[0]] : [];
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperForCurrentUserInterface::class);
|
||||
$authorizationHelper->getReachableScopes(AccompanyingPeriodVoter::SEE_DETAILS, Argument::type(Center::class))
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableScopes(Argument::type(User::class), AccompanyingPeriodVoter::SEE_DETAILS, Argument::type(Center::class))
|
||||
->willReturn($scopes);
|
||||
$authorizationHelper->getReachableScopes(AccompanyingPeriodVoter::SEE_CONFIDENTIAL_ALL, Argument::type(Center::class))
|
||||
$authorizationHelper->getReachableScopes(Argument::type(User::class), AccompanyingPeriodVoter::SEE_CONFIDENTIAL_ALL, Argument::type(Center::class))
|
||||
->willReturn($scopesConfidentials);
|
||||
|
||||
yield new ListAccompanyingPeriod(
|
||||
@@ -80,7 +70,6 @@ class ListAccompanyingPeriodTest extends AbstractExportTest
|
||||
$rollingDateConverter,
|
||||
$listAccompanyingPeriodHelper,
|
||||
new FilterListAccompanyingPeriodHelper(
|
||||
$security->reveal(),
|
||||
$centerRepository,
|
||||
$authorizationHelper->reveal(),
|
||||
$this->getParameters(true)
|
||||
@@ -92,7 +81,6 @@ class ListAccompanyingPeriodTest extends AbstractExportTest
|
||||
$rollingDateConverter,
|
||||
$listAccompanyingPeriodHelper,
|
||||
new FilterListAccompanyingPeriodHelper(
|
||||
$security->reveal(),
|
||||
$centerRepository,
|
||||
$authorizationHelper->reveal(),
|
||||
$this->getParameters(false)
|
||||
|
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace src\Bundle\ChillPersonBundle\Tests\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||
@@ -30,17 +31,20 @@ class ReferrerFilterBetweenDatesTest extends AbstractFilterTest
|
||||
private RollingDateConverterInterface $rollingDateConverter;
|
||||
private UserRender $userRender;
|
||||
|
||||
private UserRepositoryInterface $userRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
self::bootKernel();
|
||||
$this->rollingDateConverter = self::getContainer()->get(RollingDateConverterInterface::class);
|
||||
$this->userRender = self::getContainer()->get(UserRender::class);
|
||||
$this->userRepository = self::getContainer()->get(UserRepositoryInterface::class);
|
||||
}
|
||||
|
||||
public function getFilter()
|
||||
{
|
||||
return new ReferrerFilterBetweenDates($this->rollingDateConverter, $this->userRender);
|
||||
return new ReferrerFilterBetweenDates($this->rollingDateConverter, $this->userRender, $this->userRepository);
|
||||
}
|
||||
|
||||
public static function getFormData(): array
|
||||
@@ -61,6 +65,11 @@ class ReferrerFilterBetweenDatesTest extends AbstractFilterTest
|
||||
'start_date' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
|
||||
'end_date' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
[
|
||||
'accepted_referrers' => 'me',
|
||||
'start_date' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
|
||||
'end_date' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -55,6 +55,8 @@ final class ReferrerFilterTest extends AbstractFilterTest
|
||||
$data[] = ['accepted_referrers' => $u, 'date_calc' => new RollingDate(RollingDate::T_TODAY)];
|
||||
}
|
||||
|
||||
$data[] = ['accepted_referrers' => 'me', 'date_calc' => new RollingDate(RollingDate::T_TODAY)];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class StepFilterTest extends AbstractFilterTest
|
||||
final class StepFilterOnDateTest extends AbstractFilterTest
|
||||
{
|
||||
private StepFilterOnDate $filter;
|
||||
|
@@ -41,17 +41,44 @@ final class GenderFilterTest extends AbstractFilterTest
|
||||
{
|
||||
return [
|
||||
[
|
||||
'accepted_genders' => ['man'],
|
||||
],
|
||||
[
|
||||
'accepted_genders' => ['woman'],
|
||||
],
|
||||
[
|
||||
'accepted_genders' => ['man', 'both'],
|
||||
'accepted_genders_entity' => [null, '1'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderFormDataToNormalize
|
||||
*/
|
||||
public function testDataNormalization(array $data, int $version, array $customAssert): void
|
||||
{
|
||||
$filter = $this->getFilter();
|
||||
|
||||
$normalized = $filter->normalizeFormData($data);
|
||||
$actual = $filter->denormalizeFormData($normalized, $version);
|
||||
|
||||
self::assertIsArray($actual);
|
||||
self::assertArrayHasKey('accepted_genders_entity', $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of data to normalize.
|
||||
*
|
||||
* @return iterable{array}
|
||||
*/
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
yield [
|
||||
['accepted_genders_entity' => [null, '1']],
|
||||
1,
|
||||
[],
|
||||
];
|
||||
yield [
|
||||
['accepted_genders' => ['man']],
|
||||
1,
|
||||
[],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
@@ -50,6 +50,9 @@ class CreatorFilterTest extends AbstractFilterTest
|
||||
[
|
||||
'creators' => $creators,
|
||||
],
|
||||
[
|
||||
'creators' => [...$creators, 'me'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@ use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\HandlingThirdPartyFilter;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
@@ -27,16 +28,19 @@ class HandlingThirdPartyFilterTest extends AbstractFilterTest
|
||||
{
|
||||
private ThirdPartyRender $thirdPartyRender;
|
||||
|
||||
private ThirdPartyRepository $thirdPartyRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
self::bootKernel();
|
||||
$this->thirdPartyRender = self::getContainer()->get(ThirdPartyRender::class);
|
||||
$this->thirdPartyRepository = self::getContainer()->get(ThirdPartyRepository::class);
|
||||
}
|
||||
|
||||
public function getFilter()
|
||||
{
|
||||
return new HandlingThirdPartyFilter($this->thirdPartyRender);
|
||||
return new HandlingThirdPartyFilter($this->thirdPartyRender, $this->thirdPartyRepository);
|
||||
}
|
||||
|
||||
public static function getFormData(): array
|
||||
|
@@ -56,9 +56,57 @@ final class ReferrerFilterTest extends AbstractFilterTest
|
||||
];
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'accepted_agents' => 'me',
|
||||
'agent_at' => new RollingDate(RollingDate::T_TODAY),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderFormDataToNormalize
|
||||
*/
|
||||
public function testDataNormalization(array $data, int $version, array $expected): void
|
||||
{
|
||||
$filter = $this->getFilter();
|
||||
|
||||
$normalized = $filter->normalizeFormData($data);
|
||||
$actual = $filter->denormalizeFormData($normalized, $version);
|
||||
|
||||
self::assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
|
||||
}
|
||||
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
$users = array_slice($em->getRepository(User::class)->findAll(), 0, 1);
|
||||
|
||||
yield [
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
'agent_at' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
1,
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
'agent_at' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
],
|
||||
1,
|
||||
[
|
||||
'accepted_agents' => [$users[0]],
|
||||
'agent_at' => new RollingDate(RollingDate::T_TODAY),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
@@ -16,7 +16,7 @@ use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Export\Helper\FilterListAccompanyingPeriodHelper;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
@@ -63,26 +63,23 @@ final class FilterListAccompanyingPeriodHelperTest extends KernelTestCase
|
||||
if (null === $user) {
|
||||
throw new \RuntimeException('no user found');
|
||||
}
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
// mock authorization helper
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
$scopesConfidentials = [] !== $scopes ? [$scopes[0]] : [];
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperForCurrentUserInterface::class);
|
||||
$authorizationHelper->getReachableScopes(AccompanyingPeriodVoter::SEE_DETAILS, Argument::type(Center::class))
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableScopes($user, AccompanyingPeriodVoter::SEE_DETAILS, Argument::type(Center::class))
|
||||
->willReturn($scopes);
|
||||
$authorizationHelper->getReachableScopes(AccompanyingPeriodVoter::SEE_CONFIDENTIAL_ALL, Argument::type(Center::class))
|
||||
$authorizationHelper->getReachableScopes($user, AccompanyingPeriodVoter::SEE_CONFIDENTIAL_ALL, Argument::type(Center::class))
|
||||
->willReturn($scopesConfidentials);
|
||||
|
||||
$filter = new FilterListAccompanyingPeriodHelper(
|
||||
$security->reveal(),
|
||||
$this->centerRepository,
|
||||
$authorizationHelper->reveal(),
|
||||
$parameterBag
|
||||
);
|
||||
|
||||
$filter->addFilterAccompanyingPeriods($qb, [], $this->getACL(), []);
|
||||
$filter->addFilterAccompanyingPeriods($qb, [], $this->getACL(), $user, []);
|
||||
|
||||
$qb->setMaxResults(1);
|
||||
$result = $qb->getQuery()->getResult();
|
||||
|
Reference in New Issue
Block a user