mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-30 14:06:13 +00:00
Fix calendarControllerTest: fix acl, and add calendar acl on fixtures
This commit is contained in:
parent
410aa7098a
commit
ea9c21e021
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,10 @@
|
|||||||
---
|
---
|
||||||
services:
|
services:
|
||||||
Chill\CalendarBundle\DataFixtures\ORM\LoadCancelReason:
|
_defaults:
|
||||||
tags:
|
autowire: true
|
||||||
- { 'name': doctrine.fixture.orm }
|
autoconfigure: true
|
||||||
Chill\CalendarBundle\DataFixtures\ORM\LoadInvite:
|
|
||||||
tags:
|
Chill\CalendarBundle\DataFixtures\ORM\:
|
||||||
- { 'name': doctrine.fixture.orm }
|
resource: './../../../DataFixtures/ORM'
|
||||||
Chill\CalendarBundle\DataFixtures\ORM\LoadCalendarRange:
|
tags:
|
||||||
autowire: true
|
- { 'name': doctrine.fixture.orm }
|
||||||
autoconfigure: true
|
|
||||||
tags:
|
|
||||||
- { 'name': doctrine.fixture.orm }
|
|
||||||
|
@ -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());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user