Merge branch 'fix-tests-2022-02-11' into 'master'

fix ci

See merge request Chill-Projet/chill-bundles!335
This commit is contained in:
Julien Fastré 2022-02-11 13:18:32 +00:00
commit a6e9cbdece
13 changed files with 63 additions and 67 deletions

View File

@ -927,15 +927,6 @@ parameters:
count: 1 count: 1
path: src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php path: src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php
-
message:
"""
#^Parameter \\$trans of method Chill\\\\PersonBundle\\\\Controller\\\\AccompanyingCourseWorkController\\:\\:__construct\\(\\) has typehint with deprecated interface Symfony\\\\Component\\\\Translation\\\\TranslatorInterface\\:
since Symfony 4\\.2, use Symfony\\\\Contracts\\\\Translation\\\\TranslatorInterface instead$#
"""
count: 1
path: src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php
- -
message: message:
""" """

View File

@ -167,6 +167,7 @@ class WorkflowController extends AbstractController
$handler = $this->entityWorkflowManager->getHandler($entityWorkflow); $handler = $this->entityWorkflowManager->getHandler($entityWorkflow);
$workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()); $workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName());
$errors = [];
if (count($workflow->getEnabledTransitions($entityWorkflow)) > 0) { if (count($workflow->getEnabledTransitions($entityWorkflow)) > 0) {
// possible transition // possible transition
@ -245,7 +246,7 @@ class WorkflowController extends AbstractController
'handler_template_data' => $handler->getTemplateData($entityWorkflow), 'handler_template_data' => $handler->getTemplateData($entityWorkflow),
'transition_form' => isset($transitionForm) ? $transitionForm->createView() : null, 'transition_form' => isset($transitionForm) ? $transitionForm->createView() : null,
'entity_workflow' => $entityWorkflow, 'entity_workflow' => $entityWorkflow,
'transition_form_errors' => $errors ?? [], 'transition_form_errors' => $errors,
//'comment_form' => $commentForm->createView(), //'comment_form' => $commentForm->createView(),
] ]
); );

View File

@ -135,6 +135,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
if (!$this->steps->contains($step)) { if (!$this->steps->contains($step)) {
$this->steps[] = $step; $this->steps[] = $step;
$step->setEntityWorkflow($this); $step->setEntityWorkflow($this);
$this->stepsChainedCache = null;
} }
return $this; return $this;
@ -332,32 +333,26 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
public function isFinal(): bool public function isFinal(): bool
{ {
$steps = $this->getStepsChained(); foreach ($this->getStepsChained() as $step) {
if ($step->isFinal()) {
if (1 === count($steps)) { return true;
// the initial step cannot be finalized }
return false;
} }
/** @var EntityWorkflowStep $last */ return false;
$last = end($steps);
return $last->isFinal();
} }
public function isFreeze(): bool public function isFreeze(): bool
{ {
$steps = $this->getStepsChained(); $steps = $this->getStepsChained();
if (1 === count($steps)) { foreach ($this->getStepsChained() as $step) {
// the initial step cannot be finalized if ($step->isFreezeAfter()) {
return false; return true;
}
} }
/** @var EntityWorkflowStep $last */ return false;
$last = end($steps);
return $last->getPrevious()->isFreezeAfter();
} }
public function isUserSubscribedToFinal(User $user): bool public function isUserSubscribedToFinal(User $user): bool
@ -434,7 +429,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
$newStep->setCurrentStep($step); $newStep->setCurrentStep($step);
// copy the freeze // copy the freeze
if ($this->getCurrentStep()->isFreezeAfter()) { if ($this->isFreeze()) {
$newStep->setFreezeAfter(true); $newStep->setFreezeAfter(true);
} }

View File

@ -56,7 +56,7 @@ class EntityWorkflowStepRepository implements ObjectRepository
public function getClassName() public function getClassName()
{ {
return EntityWorkflow::class; return EntityWorkflowStep::class;
} }
private function buildQueryByUser(User $user): QueryBuilder private function buildQueryByUser(User $user): QueryBuilder

View File

@ -24,30 +24,30 @@ final class EntityWorkflowTest extends TestCase
{ {
$entityWorkflow = new EntityWorkflow(); $entityWorkflow = new EntityWorkflow();
$entityWorkflow->getCurrentStep()->setFinalizeAfter(true);
$entityWorkflow->setStep('final'); $entityWorkflow->setStep('final');
$entityWorkflow->getCurrentStep()->setIsFinal(true);
$this->assertTrue($entityWorkflow->isFinalize()); $this->assertTrue($entityWorkflow->isFinal());
} }
public function testIsFinalizeWith4Steps() public function testIsFinalizeWith4Steps()
{ {
$entityWorkflow = new EntityWorkflow(); $entityWorkflow = new EntityWorkflow();
$this->assertFalse($entityWorkflow->isFinalize()); $this->assertFalse($entityWorkflow->isFinal());
$entityWorkflow->setStep('two'); $entityWorkflow->setStep('two');
$this->assertFalse($entityWorkflow->isFinalize()); $this->assertFalse($entityWorkflow->isFinal());
$entityWorkflow->setStep('previous_final'); $entityWorkflow->setStep('previous_final');
$this->assertFalse($entityWorkflow->isFinalize()); $this->assertFalse($entityWorkflow->isFinal());
$entityWorkflow->getCurrentStep()->setFinalizeAfter(true); $entityWorkflow->getCurrentStep()->setIsFinal(true);
$entityWorkflow->setStep('final'); $entityWorkflow->setStep('final');
$this->assertTrue($entityWorkflow->isFinalize()); $this->assertTrue($entityWorkflow->isFinal());
} }
public function testIsFreeze() public function testIsFreeze()
@ -64,11 +64,8 @@ final class EntityWorkflowTest extends TestCase
$this->assertFalse($entityWorkflow->isFreeze()); $this->assertFalse($entityWorkflow->isFreeze());
$entityWorkflow->getCurrentStep()->setFreezeAfter(true);
$this->assertFalse($entityWorkflow->isFreeze());
$entityWorkflow->setStep('freezed'); $entityWorkflow->setStep('freezed');
$entityWorkflow->getCurrentStep()->setFreezeAfter(true);
$this->assertTrue($entityWorkflow->isFreeze()); $this->assertTrue($entityWorkflow->isFreeze());

View File

@ -32,20 +32,20 @@ final class WorkflowByUserCounter implements NotificationCounterInterface, Event
$this->cacheItemPool = $cacheItemPool; $this->cacheItemPool = $cacheItemPool;
} }
public function addNotification(UserInterface $user): int public function addNotification(UserInterface $u): int
{ {
if (!$user instanceof User) { if (!$u instanceof User) {
return 0; return 0;
} }
$key = self::generateCacheKeyWorkflowByUser($user); $key = self::generateCacheKeyWorkflowByUser($u);
$item = $this->cacheItemPool->getItem($key); $item = $this->cacheItemPool->getItem($key);
if ($item->isHit()) { if ($item->isHit()) {
return $item->get(); return $item->get();
} }
$nb = $this->getCountUnreadByUser($user); $nb = $this->getCountUnreadByUser($u);
$item->set($nb) $item->set($nb)
->expiresAfter(60 * 15); ->expiresAfter(60 * 15);

View File

@ -72,17 +72,18 @@ class MetadataExtractor
foreach ($transitions as $transition) { foreach ($transitions as $transition) {
if ($transition->getName() === $transitionName) { if ($transition->getName() === $transitionName) {
break; $metadata = $workflow->getMetadataStore()->getTransitionMetadata($transition);
return [
'name' => $transition->getName(),
'text' => array_key_exists('label', $metadata) ?
$this->translatableStringHelper->localize($metadata['label']) : $transition->getName(),
'isForward' => $metadata['isForward'] ?? null,
];
} }
} }
$metadata = $workflow->getMetadataStore()->getTransitionMetadata($transition);
return [ return [];
'name' => $transition->getName(),
'text' => array_key_exists('label', $metadata) ?
$this->translatableStringHelper->localize($metadata['label']) : $transition->getName(),
'isForward' => $metadata['isForward'] ?? null,
];
} }
public function buildArrayPresentationForWorkflow(WorkflowInterface $workflow): array public function buildArrayPresentationForWorkflow(WorkflowInterface $workflow): array

View File

@ -50,7 +50,6 @@ class HouseholdApiController extends ApiController
*/ */
public function getHouseholdByAddressReference(AddressReference $addressReference): Response public function getHouseholdByAddressReference(AddressReference $addressReference): Response
{ {
// TODO ACL
$this->denyAccessUnlessGranted('ROLE_USER'); $this->denyAccessUnlessGranted('ROLE_USER');
$total = $this->householdACLAwareRepository->countByAddressReference($addressReference); $total = $this->householdACLAwareRepository->countByAddressReference($addressReference);

View File

@ -1153,11 +1153,8 @@ class AccompanyingPeriod implements
$this->removeComment($this->pinnedComment); $this->removeComment($this->pinnedComment);
} }
if ($comment instanceof Comment) { if (null !== $this->pinnedComment) {
if (null !== $this->pinnedComment) { $this->addComment($this->pinnedComment);
$this->addComment($this->pinnedComment);
}
$this->addComment($comment);
} }
$this->pinnedComment = $comment; $this->pinnedComment = $comment;

View File

@ -14,7 +14,7 @@ namespace Chill\PersonBundle\Repository\Household;
use Chill\MainBundle\Entity\AddressReference; use Chill\MainBundle\Entity\AddressReference;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter; use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTime; use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
@ -39,7 +39,7 @@ final class HouseholdACLAwareRepository implements HouseholdACLAwareRepositoryIn
{ {
$centers = $this->authorizationHelper->getReachableCenters( $centers = $this->authorizationHelper->getReachableCenters(
$this->security->getUser(), $this->security->getUser(),
HouseholdVoter::SEE PersonVoter::SEE // the authorization to see a household is the same as seeing a person
); );
if ([] === $centers) { if ([] === $centers) {

View File

@ -91,7 +91,7 @@ class PersonJsonNormalizer implements
'deathdate', 'deathdate',
'center', 'center',
'altNames', 'altNames',
'email' 'email',
]; ];
$fields = array_filter( $fields = array_filter(

View File

@ -21,6 +21,7 @@ use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use DateTime; use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use function array_map; use function array_map;
@ -58,10 +59,16 @@ final class HouseholdApiControllerTest extends WebTestCase
$centerA = $em->getRepository(Center::class)->findOneBy(['name' => 'Center A']); $centerA = $em->getRepository(Center::class)->findOneBy(['name' => 'Center A']);
$nbReference = $em->createQueryBuilder()->select('count(ar)')->from(AddressReference::class, 'ar') $nbReference = $em->createQueryBuilder()->select('count(ar)')->from(AddressReference::class, 'ar')
->getQuery()->getSingleScalarResult(); ->getQuery()->getSingleScalarResult();
if (0 === $nbReference) {
throw new RuntimeException('any reference found. Add a reference in database to perform this test');
}
$reference = $em->createQueryBuilder()->select('ar')->from(AddressReference::class, 'ar') $reference = $em->createQueryBuilder()->select('ar')->from(AddressReference::class, 'ar')
->setFirstResult(random_int(0, $nbReference)) ->setFirstResult(random_int(0, $nbReference))
->setMaxResults(1) ->setMaxResults(1)
->getQuery()->getSingleResult(); ->getQuery()->getSingleResult();
$p = new Person(); $p = new Person();
$p->setFirstname('test')->setLastName('test lastname') $p->setFirstname('test')->setLastName('test lastname')
->setGender(Person::BOTH_GENDER) ->setGender(Person::BOTH_GENDER)
@ -79,6 +86,7 @@ final class HouseholdApiControllerTest extends WebTestCase
[HouseholdMember::class, $m->getId()], [HouseholdMember::class, $m->getId()],
[User::class, $p->getId()], [User::class, $p->getId()],
[Household::class, $h->getId()], [Household::class, $h->getId()],
[Person::class, $p->getId()],
]; ];
yield [$reference->getId(), $h->getId()]; yield [$reference->getId(), $h->getId()];

View File

@ -129,20 +129,27 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$this->assertNull($period->getPinnedComment()); $this->assertNull($period->getPinnedComment());
$period->setPinnedComment($comment); $period->setPinnedComment($comment);
$this->assertSame($period->getPinnedComment(), $comment); $this->assertSame($period->getPinnedComment(), $comment);
$this->assertSame($period, $comment->getAccompanyingPeriod()); $this->assertNull($comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertEquals(0, count($period->getComments()));
$period->setPinnedComment($replacingComment); $period->setPinnedComment($replacingComment);
$this->assertSame($period->getPinnedComment(), $replacingComment); $this->assertSame($period->getPinnedComment(), $replacingComment);
$this->assertSame($period, $replacingComment->getAccompanyingPeriod()); $this->assertNull($replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertNull($comment->getAccompanyingPeriod()); $this->assertEquals(1, count($period->getComments()));
$this->assertContains($comment, $period->getComments());
$period->setPinnedComment(null); $period->setPinnedComment(null);
$this->assertNull($period->getPinnedComment()); $this->assertNull($period->getPinnedComment());
$this->assertNull($replacingComment->getAccompanyingPeriod()); $this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertSame($period, $replacingComment->getAccompanyingPeriod());
$this->assertEquals(2, count($period->getComments()));
$this->assertContains($comment, $period->getComments());
$this->assertContains($replacingComment, $period->getComments());
} }
public function testRequestor() public function testRequestor()