Fix calendarControllerTest: fix acl, and add calendar acl on fixtures

This commit is contained in:
Julien Fastré 2023-08-25 23:09:46 +02:00
parent 410aa7098a
commit ea9c21e021
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 85 additions and 14 deletions

View File

@ -0,0 +1,55 @@
<?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\CalendarBundle\DataFixtures\ORM;
use Chill\CalendarBundle\Security\Voter\CalendarVoter;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\Entity\PermissionsGroup;
use Chill\MainBundle\Entity\RoleScope;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
class LoadCalendarACL extends Fixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager): void
{
$roleScopes = [];
foreach ([
CalendarVoter::CREATE,
CalendarVoter::DELETE,
CalendarVoter::DELETE
] as $role) {
$roleScopes[] = $r = (new RoleScope())
->setRole($role);
$manager->persist($r);
}
foreach (LoadPermissionsGroup::$refs as $permissionGroupRef) {
/** @var PermissionsGroup $group */
$group = $this->getReference($permissionGroupRef);
foreach ($roleScopes as $scope) {
$group->addRoleScope($scope);
}
}
$manager->flush();
}
public function getOrder(): int
{
return 16000;
}
}

View File

@ -1,13 +1,10 @@
--- ---
services: services:
Chill\CalendarBundle\DataFixtures\ORM\LoadCancelReason: _defaults:
tags:
- { 'name': doctrine.fixture.orm }
Chill\CalendarBundle\DataFixtures\ORM\LoadInvite:
tags:
- { 'name': doctrine.fixture.orm }
Chill\CalendarBundle\DataFixtures\ORM\LoadCalendarRange:
autowire: true autowire: true
autoconfigure: true autoconfigure: true
Chill\CalendarBundle\DataFixtures\ORM\:
resource: './../../../DataFixtures/ORM'
tags: tags:
- { 'name': doctrine.fixture.orm } - { 'name': doctrine.fixture.orm }

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Tests\Controller; namespace Chill\CalendarBundle\Tests\Controller;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -42,14 +43,32 @@ final class CalendarControllerTest extends WebTestCase
$nb = $em->createQueryBuilder() $nb = $em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac') ->from(AccompanyingPeriod::class, 'ac')
->select('COUNT(ac) AS nb') ->join('ac.participations', 'acp')
->join('acp.person', 'person')
->join('person.centerCurrent', 'pc')
->join('pc.center', 'center')
->where('center.name LIKE :n')
->setParameter('n', 'Center A')
->join('ac.scopes', 's')
->andWhere('JSON_EXTRACT(s.name,\'fr\') LIKE :s')
->setParameter('s', 'social')
->select('COUNT(DISTINCT ac) AS nb')
->getQuery() ->getQuery()
->getSingleScalarResult(); ->getSingleScalarResult();
yield [$em->createQueryBuilder() yield [$em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac') ->from(AccompanyingPeriod::class, 'ac')
->select('ac.id') ->select('ac.id')
->setFirstResult(random_int(0, $nb)) ->join('ac.participations', 'acp')
->join('acp.person', 'person')
->join('person.centerCurrent', 'pc')
->join('pc.center', 'center')
->where('center.name LIKE :n')
->setParameter('n', 'Center A')
->join('ac.scopes', 's')
->andWhere('JSON_EXTRACT(s.name,\'fr\') LIKE :s')
->setParameter('s', 'social')
->setFirstResult(random_int(0, $nb - 1))
->setMaxResults(1) ->setMaxResults(1)
->getQuery() ->getQuery()
->getSingleScalarResult(), ->getSingleScalarResult(),
@ -63,7 +82,7 @@ final class CalendarControllerTest extends WebTestCase
{ {
$this->client->request( $this->client->request(
Request::METHOD_GET, Request::METHOD_GET,
sprintf('/fr/calendar/calendar/?accompanying_period_id=%d', $accompanyingPeriodId) sprintf('/fr/calendar/calendar/by-period/%d', $accompanyingPeriodId)
); );
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());