mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
Household members editor: leave household when repositionning to same
household, not sharing household
This commit is contained in:
parent
de4f65fede
commit
df24d085ca
@ -98,6 +98,12 @@ class MembersEditor
|
|||||||
$participation->setEndDate($membership->getStartDate());
|
$participation->setEndDate($membership->getStartDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// if a members is moved to the same household than the one he belongs to,
|
||||||
|
// we should make it leave the household
|
||||||
|
if ($person->getCurrentHousehold($date) === $this->household) {
|
||||||
|
$this->leaveMovement($date, $person);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->membershipsAffected[] = $membership;
|
$this->membershipsAffected[] = $membership;
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Tests\Household;
|
namespace Chill\PersonBundle\Tests\Household;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
use Chill\PersonBundle\Entity\Household\Position;
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
|
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
|
||||||
@ -39,6 +40,46 @@ final class MembersEditorTest extends TestCase
|
|||||||
$this->factory = $this->buildMembersEditorFactory();
|
$this->factory = $this->buildMembersEditorFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We test here a move for a person:.
|
||||||
|
*
|
||||||
|
* * which was in a position "sharing household"
|
||||||
|
* * which move to the same household, in a position "not sharing household"
|
||||||
|
*/
|
||||||
|
public function testMoveFromSharingHouseholdToNotSharingHousehouldInSamehousehold()
|
||||||
|
{
|
||||||
|
$person = new Person();
|
||||||
|
$household = new Household();
|
||||||
|
$positionSharing = (new Position())->setShareHousehold(true);
|
||||||
|
$positionNotSharing = (new Position())->setShareHousehold(false);
|
||||||
|
$factory = $this->buildMembersEditorFactory();
|
||||||
|
$editor = $factory->createEditor($household);
|
||||||
|
|
||||||
|
// we add the member to the household
|
||||||
|
$editor->addMovement(new DateTimeImmutable('1 month ago'), $person, $positionSharing);
|
||||||
|
|
||||||
|
// double check that the person is in the household
|
||||||
|
$this->assertContains($person, $household->getCurrentPersons());
|
||||||
|
|
||||||
|
// we do the move to the position not sharing household
|
||||||
|
$editor = $factory->createEditor($household);
|
||||||
|
$editor->addMovement(new DateTimeImmutable('yesterday'), $person, $positionNotSharing);
|
||||||
|
|
||||||
|
$sharings = $household->getCurrentMembers()->filter(static function (HouseholdMember $m) {
|
||||||
|
return $m->getShareHousehold();
|
||||||
|
});
|
||||||
|
$notSharing = $household->getCurrentMembers()->filter(static function (HouseholdMember $m) {
|
||||||
|
return !$m->getShareHousehold();
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assertCount(1, $notSharing);
|
||||||
|
$this->assertCount(0, $sharings);
|
||||||
|
|
||||||
|
$getPerson = static function (HouseholdMember $m) { return $m->getPerson(); };
|
||||||
|
|
||||||
|
$this->assertContains($person, $notSharing->map($getPerson));
|
||||||
|
}
|
||||||
|
|
||||||
public function testMovePersonWithoutSharedHousehold()
|
public function testMovePersonWithoutSharedHousehold()
|
||||||
{
|
{
|
||||||
$person = new Person();
|
$person = new Person();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user