mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
show documents from person in list of document from course
This commit is contained in:
@@ -21,12 +21,14 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -66,7 +68,8 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
|
||||
$repository = new PersonDocumentACLAwareRepository(
|
||||
$this->entityManager,
|
||||
$centerManager->reveal(),
|
||||
$authorizationHelper->reveal()
|
||||
$authorizationHelper->reveal(),
|
||||
$this->prophesize(Security::class)->reveal()
|
||||
);
|
||||
|
||||
$person = $this->entityManager->createQuery("SELECT p FROM " . Person::class . " p")
|
||||
@@ -86,6 +89,62 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
|
||||
self::assertIsInt($nb, "test that the query could be executed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDateForFetchQueryForAccompanyingPeriod
|
||||
*/
|
||||
public function testBuildFetchQueryForAccompanyingPeriod(
|
||||
AccompanyingPeriod $period,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null
|
||||
): void {
|
||||
$centerManager = $this->prophesize(CenterResolverManagerInterface::class);
|
||||
$centerManager->resolveCenters(Argument::type(Person::class))
|
||||
->willReturn([new Center()]);
|
||||
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperForCurrentUserInterface::class);
|
||||
$authorizationHelper->getReachableScopes(PersonDocumentVoter::SEE, Argument::any())->willReturn($scopes);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted(PersonDocumentVoter::SEE, Argument::type(Person::class))->willReturn(true);
|
||||
|
||||
$repository = new PersonDocumentACLAwareRepository(
|
||||
$this->entityManager,
|
||||
$centerManager->reveal(),
|
||||
$authorizationHelper->reveal(),
|
||||
$security->reveal()
|
||||
);
|
||||
|
||||
$query = $repository->buildFetchQueryForAccompanyingPeriod($period, $startDate, $endDate, $content);
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query);
|
||||
|
||||
$nb = $this->entityManager->getConnection()
|
||||
->fetchOne("SELECT COUNT(*) FROM ({$sql}) AS sq", $params, $types);
|
||||
|
||||
self::assertIsInt($nb, "test that the query could be executed");
|
||||
}
|
||||
|
||||
public function provideDateForFetchQueryForAccompanyingPeriod(): iterable
|
||||
{
|
||||
$this->setUp();
|
||||
|
||||
if (null === $period = $this->entityManager->createQuery(
|
||||
"SELECT p FROM " . AccompanyingPeriod::class . " p WHERE SIZE(p.participations) > 0"
|
||||
)
|
||||
->setMaxResults(1)->getSingleResult()) {
|
||||
throw new \RuntimeException("no course found");
|
||||
}
|
||||
|
||||
yield [$period, null, null, null];
|
||||
yield [$period, new DateTimeImmutable('1 year ago'), null, null];
|
||||
yield [$period, null, new DateTimeImmutable('1 year ago'), null];
|
||||
yield [$period, new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), null];
|
||||
yield [$period, null, null, 'test'];
|
||||
yield [$period, new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), 'test'];
|
||||
|
||||
}
|
||||
|
||||
public function provideDataBuildFetchQueryForPerson(): iterable
|
||||
{
|
||||
yield [null, null, null];
|
||||
|
Reference in New Issue
Block a user