mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 12:33:49 +00:00
fix cs
This commit is contained in:
@@ -12,7 +12,6 @@ declare(strict_types=1);
|
||||
namespace Chill\TaskBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -336,8 +335,7 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
|
||||
->leftJoin('course.participations', 'participation')
|
||||
->leftJoin('participation.person', 'person_p')
|
||||
->leftJoin('person.centerCurrent', 'center_current_person')
|
||||
->leftJoin('person_p.centerCurrent', 'center_current_participation')
|
||||
;
|
||||
->leftJoin('person_p.centerCurrent', 'center_current_participation');
|
||||
$qb->distinct(true);
|
||||
|
||||
$k = 0;
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\TaskBundle\Tests\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
@@ -7,14 +16,11 @@ use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\ScopeRepository;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\TaskBundle\Entity\SingleTask;
|
||||
use Chill\TaskBundle\Repository\SingleTaskAclAwareRepository;
|
||||
use Chill\TaskBundle\Security\Authorization\TaskVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -22,20 +28,30 @@ use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use function count;
|
||||
|
||||
class SingleTaskACLAwareRepositoryTest extends KernelTestCase
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class SingleTaskACLAwareRepositoryTest extends KernelTestCase
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
private UserRepository $userRepository;
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
private CenterRepositoryInterface $centerRepository;
|
||||
private ScopeRepository $scopeRepository;
|
||||
private PersonRepository $personRepository;
|
||||
|
||||
use PersonRandomHelper;
|
||||
|
||||
use ProphecyTrait;
|
||||
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
private CenterRepositoryInterface $centerRepository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private PersonRepository $personRepository;
|
||||
|
||||
private ScopeRepository $scopeRepository;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
@@ -47,97 +63,6 @@ class SingleTaskACLAwareRepositoryTest extends KernelTestCase
|
||||
$this->personRepository = self::$container->get(PersonRepository::class);
|
||||
}
|
||||
|
||||
public function testCountByPerson(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
$user = new User();
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
$person = $this->getRandomPerson($this->em);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
$centerResolverDispatcher = $this->prophesize(CenterResolverManagerInterface::class);
|
||||
$centerResolverDispatcher->resolveCenters(Argument::type(Person::class), Argument::any())
|
||||
->willReturn([$centerA]);
|
||||
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableScopes(Argument::exact($user), Argument::exact(TaskVoter::SHOW), Argument::exact($centerA))
|
||||
->willReturn($scopes);
|
||||
|
||||
$repository = new SingleTaskAclAwareRepository(
|
||||
$centerResolverDispatcher->reveal(),
|
||||
$this->em,
|
||||
$security->reveal(),
|
||||
$authorizationHelper->reveal()
|
||||
);
|
||||
|
||||
$nb = $repository->countByPerson($person, null, []);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, $nb);
|
||||
}
|
||||
|
||||
public function testFindByPerson(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
$user = new User();
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
$person = $this->getRandomPerson($this->em);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
$centerResolverDispatcher = $this->prophesize(CenterResolverManagerInterface::class);
|
||||
$centerResolverDispatcher->resolveCenters(Argument::type(Person::class), Argument::any())
|
||||
->willReturn([$centerA]);
|
||||
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableScopes(Argument::exact($user), Argument::exact(TaskVoter::SHOW), Argument::exact($centerA))
|
||||
->willReturn($scopes);
|
||||
|
||||
$repository = new SingleTaskAclAwareRepository(
|
||||
$centerResolverDispatcher->reveal(),
|
||||
$this->em,
|
||||
$security->reveal(),
|
||||
$authorizationHelper->reveal()
|
||||
);
|
||||
|
||||
$tasks = $repository->findByPerson($person, null, []);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, count($tasks));
|
||||
}
|
||||
|
||||
public function testFindByAllViewable(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
$user = new User();
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
$centerResolverDispatcher = $this->prophesize(CenterResolverManagerInterface::class);
|
||||
$centerResolverDispatcher->resolveCenters(Argument::type(Person::class), Argument::any())
|
||||
->willReturn([$centerA]);
|
||||
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableCenters(Argument::exact($user), Argument::exact(TaskVoter::SHOW))
|
||||
->willReturn([$centerA]);
|
||||
$authorizationHelper->getReachableScopes(Argument::exact($user), Argument::exact(TaskVoter::SHOW), Argument::exact($centerA))
|
||||
->willReturn($scopes);
|
||||
|
||||
$repository = new SingleTaskAclAwareRepository(
|
||||
$centerResolverDispatcher->reveal(),
|
||||
$this->em,
|
||||
$security->reveal(),
|
||||
$authorizationHelper->reveal()
|
||||
);
|
||||
|
||||
$tasks = $repository->findByAllViewable(null, []);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, count($tasks));
|
||||
}
|
||||
|
||||
public function testCountByAllViewable(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
@@ -169,6 +94,67 @@ class SingleTaskACLAwareRepositoryTest extends KernelTestCase
|
||||
$this->assertGreaterThanOrEqual(0, $nb);
|
||||
}
|
||||
|
||||
public function testCountByPerson(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
$user = new User();
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
$person = $this->getRandomPerson($this->em);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
$centerResolverDispatcher = $this->prophesize(CenterResolverManagerInterface::class);
|
||||
$centerResolverDispatcher->resolveCenters(Argument::type(Person::class), Argument::any())
|
||||
->willReturn([$centerA]);
|
||||
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableScopes(Argument::exact($user), Argument::exact(TaskVoter::SHOW), Argument::exact($centerA))
|
||||
->willReturn($scopes);
|
||||
|
||||
$repository = new SingleTaskAclAwareRepository(
|
||||
$centerResolverDispatcher->reveal(),
|
||||
$this->em,
|
||||
$security->reveal(),
|
||||
$authorizationHelper->reveal()
|
||||
);
|
||||
|
||||
$nb = $repository->countByPerson($person, null, []);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, $nb);
|
||||
}
|
||||
|
||||
public function testFindByAllViewable(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
$user = new User();
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
$centerResolverDispatcher = $this->prophesize(CenterResolverManagerInterface::class);
|
||||
$centerResolverDispatcher->resolveCenters(Argument::type(Person::class), Argument::any())
|
||||
->willReturn([$centerA]);
|
||||
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableCenters(Argument::exact($user), Argument::exact(TaskVoter::SHOW))
|
||||
->willReturn([$centerA]);
|
||||
$authorizationHelper->getReachableScopes(Argument::exact($user), Argument::exact(TaskVoter::SHOW), Argument::exact($centerA))
|
||||
->willReturn($scopes);
|
||||
|
||||
$repository = new SingleTaskAclAwareRepository(
|
||||
$centerResolverDispatcher->reveal(),
|
||||
$this->em,
|
||||
$security->reveal(),
|
||||
$authorizationHelper->reveal()
|
||||
);
|
||||
|
||||
$tasks = $repository->findByAllViewable(null, []);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, count($tasks));
|
||||
}
|
||||
|
||||
public function testFindByCourse(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
@@ -176,14 +162,13 @@ class SingleTaskACLAwareRepositoryTest extends KernelTestCase
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
/** @var Person $person */
|
||||
$person = $this->em->createQuery(
|
||||
'SELECT p FROM '.Person::class.' p JOIN p.centerCurrent cc
|
||||
WHERE SIZE(p.accompanyingPeriodParticipations) > 0
|
||||
'SELECT p FROM ' . Person::class . ' p JOIN p.centerCurrent cc
|
||||
WHERE SIZE(p.accompanyingPeriodParticipations) > 0
|
||||
AND cc.center = :center'
|
||||
)
|
||||
->setParameter('center', $centerA)
|
||||
->setMaxResults(1)
|
||||
->getSingleResult()
|
||||
;
|
||||
->getSingleResult();
|
||||
$period = $person->getAccompanyingPeriodParticipations()->first()->getAccompanyingPeriod();
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
@@ -208,4 +193,34 @@ class SingleTaskACLAwareRepositoryTest extends KernelTestCase
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, count($tasks));
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindByPerson(): void
|
||||
{
|
||||
$centerA = $this->centerRepository->findOneBy(['name' => 'Center A']);
|
||||
$user = new User();
|
||||
$scopes = $this->scopeRepository->findAll();
|
||||
$person = $this->getRandomPerson($this->em);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($user);
|
||||
|
||||
$centerResolverDispatcher = $this->prophesize(CenterResolverManagerInterface::class);
|
||||
$centerResolverDispatcher->resolveCenters(Argument::type(Person::class), Argument::any())
|
||||
->willReturn([$centerA]);
|
||||
|
||||
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
|
||||
$authorizationHelper->getReachableScopes(Argument::exact($user), Argument::exact(TaskVoter::SHOW), Argument::exact($centerA))
|
||||
->willReturn($scopes);
|
||||
|
||||
$repository = new SingleTaskAclAwareRepository(
|
||||
$centerResolverDispatcher->reveal(),
|
||||
$this->em,
|
||||
$security->reveal(),
|
||||
$authorizationHelper->reveal()
|
||||
);
|
||||
|
||||
$tasks = $repository->findByPerson($person, null, []);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, count($tasks));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user