From fd79692f6df24c0aae361f64ecc6e96eb186eaa6 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 3 Aug 2023 11:38:13 +0200 Subject: [PATCH] FEATURE [relationships] Add personMoveRelationHandler and test for this --- .../Handler/PersonMoveRelationHandler.php | 38 +++++++++++++++++++ .../Tests/Action/Remove/PersonMoveTest.php | 30 +++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php diff --git a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php new file mode 100644 index 000000000..3454fce24 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php @@ -0,0 +1,38 @@ +getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId()); + + $deleteSql = sprintf(<<getId(), $from->getId()); + + return [$insertSql, $deleteSql]; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php b/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php index 613baaf44..d0ebf9a85 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php @@ -4,6 +4,7 @@ namespace Action\Remove; use Chill\ActivityBundle\Entity\Activity; use Chill\MainBundle\Entity\Center; +use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Actions\Remove\PersonMove; use Chill\PersonBundle\Actions\Remove\PersonMoveManager; use Chill\PersonBundle\Entity\AccompanyingPeriod; @@ -11,6 +12,9 @@ use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Entity\Relationships\Relation; +use Chill\PersonBundle\Entity\Relationships\Relationship; +use Chill\PersonBundle\Repository\PersonRepository; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -200,6 +204,32 @@ class PersonMoveTest extends KernelTestCase yield [$personA, $personB, "move 2 people participating to the same parcours"]; + $personA = new Person(); + $personB = new Person(); + $relationship = new Relationship(); + $relation = new Relation(); + $user = new User(); + + $relationship->setRelation($relation); + $relationship->setToPerson($personA); + $relationship->setFromPerson($personB); + $relationship->setReverse(false); + $relationship->setCreatedBy($user); + + $this->em->persist($personA); + $this->em->persist($personB); + $this->em->persist($relation); + $this->em->persist($user); + $this->em->persist($relationship); + + self::$entitiesToDelete[] = [Person::class, $personA]; + self::$entitiesToDelete[] = [Person::class, $personB]; + self::$entitiesToDelete[] = [Relation::class, $relation]; + self::$entitiesToDelete[] = [User::class, $user]; + self::$entitiesToDelete[] = [Relationship::class, $relationship]; + + yield [$personA, $personB, "move 2 people with a relationship"]; + $this->em->flush(); $this->em->clear(); }