mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-03 12:39:42 +00:00
Merge branch 'master' into migrate_to_sf72
# Conflicts: # docs/source/_static/code/exports/BirthdateFilter.php # rector.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByActivityTypeAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialActionAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialIssueAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityLocationAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityPresenceAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUserAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersJobAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersScopeAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ByCreatorAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/ByThirdpartyAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/CreatorJobAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/CreatorScopeAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/DateAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/LocationTypeAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/HouseholdAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/PersonAggregator.php # src/Bundle/ChillActivityBundle/Export/Aggregator/PersonsAggregator.php # src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php # src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php # src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/ActivityTypeFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/HasNoActivityFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/PeriodHavingActivityBetweenDatesFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ActivityPresenceFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ActivityUsersFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/ByCreatorFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/CreatorJobFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/CreatorScopeFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/EmergencyFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/LocationFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/LocationTypeFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/PersonFilters/ActivityReasonFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/PersonsFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/SentReceivedFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/UserFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/UsersJobFilter.php # src/Bundle/ChillActivityBundle/Export/Filter/UsersScopeFilter.php # src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php # src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByActivityTypeAggregator.php # src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserJobAggregator.php # src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserScopeAggregator.php # src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByActivityTypeFilter.php # src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php # src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByUserFilter.php # src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByUserJobFilter.php # src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByUserScopeFilter.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/AgentAggregator.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/CancelReasonAggregator.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/JobAggregator.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationAggregator.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationTypeAggregator.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/MonthYearAggregator.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/ScopeAggregator.php # src/Bundle/ChillCalendarBundle/Export/Aggregator/UrgencyAggregator.php # src/Bundle/ChillCalendarBundle/Export/Filter/AgentFilter.php # src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php # src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php # src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php # src/Bundle/ChillCalendarBundle/Export/Filter/ScopeFilter.php # src/Bundle/ChillEventBundle/Export/Aggregator/EventDateAggregator.php # src/Bundle/ChillEventBundle/Export/Aggregator/EventTypeAggregator.php # src/Bundle/ChillEventBundle/Export/Aggregator/RoleAggregator.php # src/Bundle/ChillEventBundle/Export/Filter/EventDateFilter.php # src/Bundle/ChillEventBundle/Export/Filter/EventTypeFilter.php # src/Bundle/ChillEventBundle/Export/Filter/RoleFilter.php # src/Bundle/ChillMainBundle/Controller/ExportController.php # src/Bundle/ChillMainBundle/Controller/SavedExportController.php # src/Bundle/ChillMainBundle/DependencyInjection/CompilerPass/ExportsCompilerPass.php # src/Bundle/ChillMainBundle/Entity/Notification.php # src/Bundle/ChillMainBundle/Export/ExportManager.php # src/Bundle/ChillMainBundle/Export/Formatter/CSVFormatter.php # src/Bundle/ChillMainBundle/Export/Formatter/CSVListFormatter.php # src/Bundle/ChillMainBundle/Export/Formatter/CSVPivotedListFormatter.php # src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php # src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php # src/Bundle/ChillMainBundle/Form/SavedExportType.php # src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php # src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php # src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingDateAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/CreatorJobAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/IntensityAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobWorkingOnCourseAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/OpeningDateAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/OriginAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/PersonParticipatingAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeWorkingOnCourseAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialIssueAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/StepAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserWorkingOnCourseAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingPeriodStepHistoryAggregators/ByClosingMotiveAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingPeriodStepHistoryAggregators/ByDateAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingPeriodStepHistoryAggregators/ByStepAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/ByEndDateAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/ByMaxDateAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/ByStartDateAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/EvaluationTypeAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/HavingEndDateAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AdministrativeStatusAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AgeAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/CenterAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/EmploymentStatusAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GenderAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/MaritalStatusAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/PostalCodeAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorJobAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorScopeAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/HandlingThirdPartyAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php # src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ClosingMotiveFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ConfidentialFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorJobFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/EmergencyFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/EvaluationFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HandlingThirdPartyFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/IntensityFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/NotAssociatedWithAReferenceAddressFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/OpenBetweenDatesFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/OriginFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilterBetweenDates.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/RequestorFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterBetweenDates.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterOnDate.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingPeriodStepHistoryFilters/ByDateFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingPeriodStepHistoryFilters/ByStepFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/EvaluationTypeFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/MaxDateFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AddressRefStatusFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ByHouseholdCompositionFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeadOrAliveFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/MaritalStatusFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/NationalityFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithoutHouseholdComposition.php # src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithoutParticipationBetweenDatesFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorJobFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorScopeFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ReferrerFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php # src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php # src/Bundle/ChillPersonBundle/Export/Helper/FilterListAccompanyingPeriodHelper.php # src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodVoter.php # src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php # src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/AccompanyingPeriodValidity.php # src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ConfidentialCourseMustHaveReferrer.php # src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidity.php # src/Bundle/ChillPersonBundle/Validator/Constraints/Household/MaxHolder.php # src/Bundle/ChillReportBundle/Export/Export/ReportList.php # src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php
This commit is contained in:
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Test\Export;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||
use Doctrine\ORM\AbstractQuery;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
@@ -64,6 +66,19 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
*/
|
||||
abstract public static function getQueryBuilders();
|
||||
|
||||
protected function getUser(): User
|
||||
{
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
if (null === $user = $em->createQueryBuilder()->select('u')
|
||||
->from(User::class, 'u')
|
||||
->setMaxResults(1)
|
||||
->getQuery()->getOneOrNullResult()) {
|
||||
throw new \RuntimeException('User not found');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare aliases array before and after that aggregator alter query.
|
||||
*
|
||||
@@ -75,7 +90,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
{
|
||||
$aliases = $qb->getAllAliases();
|
||||
|
||||
$this->getAggregator()->alterQuery($qb, $data);
|
||||
$this->getAggregator()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
$alteredQuery = $qb->getAllAliases();
|
||||
|
||||
@@ -115,7 +130,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
*/
|
||||
public function testQueryExecution(QueryBuilder $qb, array $data): void
|
||||
{
|
||||
$this->getAggregator()->alterQuery($qb, $data);
|
||||
$this->getAggregator()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
$actual = $qb->getQuery()->getResult();
|
||||
|
||||
@@ -158,7 +173,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
$nbOfSelect = null !== $query->getDQLPart('select') ?
|
||||
\count($query->getDQLPart('select')) : 0;
|
||||
|
||||
$this->getAggregator()->alterQuery($query, $data);
|
||||
$this->getAggregator()->alterQuery($query, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
$nbOfFrom,
|
||||
@@ -218,6 +233,44 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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::assertEqualsCanonicalizing(array_keys($data), array_keys($actual));
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
self::assertArrayHasKey($key, $actual);
|
||||
if (array_key_exists($key, $customAssert)) {
|
||||
call_user_func($customAssert[$key], $actual[$key], $value);
|
||||
} elseif (is_iterable($value)) {
|
||||
continue;
|
||||
} elseif (is_object($value) && method_exists($value, 'getId')) {
|
||||
self::assertEquals($value->getId(), $actual[$key]->getId());
|
||||
} else {
|
||||
self::assertEquals($value, $actual[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of data to normalize.
|
||||
*
|
||||
* @return iterable{array}
|
||||
*/
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
foreach (static::getFormData() as $data) {
|
||||
yield [$data, 1, []];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the query keys are strings.
|
||||
*
|
||||
@@ -280,7 +333,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
$qb->setMaxResults(1);
|
||||
|
||||
$queryKeys = $this->getAggregator()->getQueryKeys($data);
|
||||
$this->getAggregator()->alterQuery($qb, $data);
|
||||
$this->getAggregator()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
$results = $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Test\Export;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Export\DirectExportInterface;
|
||||
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||
use Chill\MainBundle\Export\ExportInterface;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -99,6 +101,19 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
*/
|
||||
abstract public static function getModifiersCombination(): array;
|
||||
|
||||
protected function getUser(): User
|
||||
{
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
if (null === $user = $em->createQueryBuilder()->select('u')
|
||||
->from(User::class, 'u')
|
||||
->setMaxResults(1)
|
||||
->getQuery()->getOneOrNullResult()) {
|
||||
throw new \RuntimeException('User not found');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function getParameters(bool $filterStatsByCenter): ParameterBagInterface
|
||||
{
|
||||
return new ParameterBag(['chill_main' => ['acl' => ['filter_stats_by_center' => $filterStatsByCenter]]]);
|
||||
@@ -118,6 +133,55 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
return [$exports];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderFormDataToNormalize
|
||||
*/
|
||||
public function testDataNormalization(array $data, int $version, array $customAssert): void
|
||||
{
|
||||
$export = $this->getExport();
|
||||
|
||||
if (is_iterable($export)) {
|
||||
foreach ($export as $e) {
|
||||
$this->testOneDataNormalization($e, $data, $version, $customAssert);
|
||||
}
|
||||
} else {
|
||||
$this->testOneDataNormalization($export, $data, $version, $customAssert);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of data to normalize.
|
||||
*
|
||||
* @return iterable{array}
|
||||
*/
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
foreach (static::getFormData() as $data) {
|
||||
yield [$data, 1, []];
|
||||
}
|
||||
}
|
||||
|
||||
private function testOneDataNormalization(ExportInterface|DirectExportInterface $export, array $data, int $version, array $customAssert): void
|
||||
{
|
||||
$normalized = $export->normalizeFormData($data);
|
||||
$actual = $export->denormalizeFormData($normalized, $version);
|
||||
|
||||
self::assertEqualsCanonicalizing(array_keys($data), array_keys($actual));
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
self::assertArrayHasKey($key, $actual);
|
||||
if (array_key_exists($key, $customAssert)) {
|
||||
call_user_func($customAssert[$key], $actual[$key], $value);
|
||||
} elseif (is_iterable($value)) {
|
||||
continue;
|
||||
} elseif (is_object($value) && method_exists($value, 'getId')) {
|
||||
self::assertEquals($value->getId(), $actual[$key]->getId());
|
||||
} else {
|
||||
self::assertEquals($value, $actual[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the formatters type are string.
|
||||
*/
|
||||
@@ -205,7 +269,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
// due to the fact that testing both methods use the same tools.
|
||||
|
||||
$queryKeys = $export->getQueryKeys($data);
|
||||
$query = $export->initiateQuery($modifiers, $acl, $data);
|
||||
$query = $export->initiateQuery($modifiers, $acl, $data, $exportGenerationContext = new ExportGenerationContext($this->getUser()));
|
||||
|
||||
// limit the result for the query for performance reason (only for QueryBuilder,
|
||||
// not possible in NativeQuery)
|
||||
@@ -213,7 +277,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
$query->setMaxResults(1);
|
||||
}
|
||||
|
||||
$results = $export->getResult($query, $data);
|
||||
$results = $export->getResult($query, $data, $exportGenerationContext);
|
||||
|
||||
$this->assertIsArray(
|
||||
$results,
|
||||
@@ -295,7 +359,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
public function testInitiateQuery(mixed $modifiers, mixed $acl, mixed $data): void
|
||||
{
|
||||
foreach ($this->getExports() as $export) {
|
||||
$query = $export->initiateQuery($modifiers, $acl, $data);
|
||||
$query = $export->initiateQuery($modifiers, $acl, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
$this->assertTrue(
|
||||
$query instanceof QueryBuilder || $query instanceof NativeQuery,
|
||||
@@ -350,7 +414,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
public function testSupportsModifier(mixed $modifiers, mixed $acl, mixed $data): void
|
||||
{
|
||||
foreach ($this->getExports() as $export) {
|
||||
$query = $export->initiateQuery($modifiers, $acl, $data);
|
||||
$query = $export->initiateQuery($modifiers, $acl, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
if ($query instanceof QueryBuilder) {
|
||||
$this->assertContainsOnly(
|
||||
|
||||
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Test\Export;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
@@ -23,16 +25,6 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @var \Prophecy\Prophet
|
||||
*/
|
||||
private $prophet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->prophet = $this->getProphet();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
if (null !== self::getContainer()) {
|
||||
@@ -43,6 +35,19 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
|
||||
protected function getUser(): User
|
||||
{
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
if (null === $user = $em->createQueryBuilder()->select('u')
|
||||
->from(User::class, 'u')
|
||||
->setMaxResults(1)
|
||||
->getQuery()->getOneOrNullResult()) {
|
||||
throw new \RuntimeException('User not found');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a filter which will be used in tests.
|
||||
*
|
||||
@@ -74,6 +79,44 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
*/
|
||||
abstract public static function getQueryBuilders();
|
||||
|
||||
/**
|
||||
* @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::assertEqualsCanonicalizing(array_keys($data), array_keys($actual));
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
self::assertArrayHasKey($key, $actual);
|
||||
if (array_key_exists($key, $customAssert)) {
|
||||
call_user_func($customAssert[$key], $actual[$key], $value);
|
||||
} elseif (is_iterable($value)) {
|
||||
continue;
|
||||
} elseif (is_object($value) && method_exists($value, 'getId')) {
|
||||
self::assertEquals($value->getId(), $actual[$key]->getId());
|
||||
} else {
|
||||
self::assertEquals($value, $actual[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of data to normalize.
|
||||
*
|
||||
* @return iterable{array}
|
||||
*/
|
||||
public static function dataProviderFormDataToNormalize(): iterable
|
||||
{
|
||||
foreach (static::getFormData() as $data) {
|
||||
yield [$data, 1, []];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare aliases array before and after that filter alter query.
|
||||
*
|
||||
@@ -83,7 +126,7 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
{
|
||||
$aliases = $qb->getAllAliases();
|
||||
|
||||
$this->getFilter()->alterQuery($qb, $data);
|
||||
$this->getFilter()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
$alteredQuery = $qb->getAllAliases();
|
||||
|
||||
@@ -129,7 +172,9 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
$nbOfSelect = null !== $query->getDQLPart('select') ?
|
||||
\count($query->getDQLPart('select')) : 0;
|
||||
|
||||
$this->getFilter()->alterQuery($query, $data);
|
||||
$context = new ExportGenerationContext($this->getUser());
|
||||
|
||||
$this->getFilter()->alterQuery($query, $data, $context);
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
$nbOfFrom,
|
||||
@@ -170,7 +215,7 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
*/
|
||||
public function testQueryExecution(QueryBuilder $qb, mixed $data): void
|
||||
{
|
||||
$this->getFilter()->alterQuery($qb, $data);
|
||||
$this->getFilter()->alterQuery($qb, $data, new ExportGenerationContext($this->getUser()));
|
||||
|
||||
$actual = $qb->getQuery()->getResult();
|
||||
|
||||
@@ -206,7 +251,8 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
*/
|
||||
public function testDescriptionAction($data): void
|
||||
{
|
||||
$description = $this->getFilter()->describeAction($data);
|
||||
$context = new ExportGenerationContext((new User())->setLabel('test user'));
|
||||
$description = $this->getFilter()->describeAction($data, $context);
|
||||
|
||||
$this->assertTrue(
|
||||
\is_string($description) || \is_array($description),
|
||||
@@ -262,15 +308,4 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
yield [$data];
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetTitle()
|
||||
{
|
||||
$title = $this->getFilter()->getTitle();
|
||||
|
||||
$this->assertIsString($title);
|
||||
$this->assertNotEmpty(
|
||||
$title,
|
||||
'test that the title is not empty'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user