[export] Add referrer on accompanying course filter between dates feature and relevant tests

Implemented a new filter to the software for social workers. This filter, ReferrerFilterBetweenDates, enables filtering of query results based on a range of dates and accepted referrers. Tests for this new functionality have also been added to ensure the feature works as expected.
This commit is contained in:
2024-01-23 14:20:27 +01:00
parent 3871299346
commit c707a34f16
5 changed files with 227 additions and 2 deletions

View File

@@ -0,0 +1,89 @@
<?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 src\Bundle\ChillPersonBundle\Tests\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ReferrerFilterBetweenDates;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ReferrerFilterBetweenDatesTest extends AbstractFilterTest
{
private RollingDateConverterInterface $rollingDateConverter;
private UserRender $userRender;
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$this->rollingDateConverter = self::$container->get(RollingDateConverterInterface::class);
$this->userRender = self::$container->get(UserRender::class);
}
public function getFilter()
{
return new ReferrerFilterBetweenDates($this->rollingDateConverter, $this->userRender);
}
public function getFormData()
{
self:self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$users = $em->createQueryBuilder()
->from(User::class, 'u')
->select('u')
->getQuery()
->setMaxResults(1)
->getResult();
return [
[
'accepted_referrers' => $users[0],
'start_date' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
],
];
}
public function getQueryBuilders()
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
yield $em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'acp')
->select('acp.id');
$qb = $em->createQueryBuilder();
$qb
->from(AccompanyingPeriod\AccompanyingPeriodWork::class, 'acpw')
->join('acpw.accompanyingPeriod', 'acp')
->join('acp.participations', 'acppart')
->join('acppart.person', 'person')
;
$qb->select('COUNT(DISTINCT acpw.id) as export_result');
yield $qb;
}
}