From 835409cb94fd1aed9c4a176b961f29705f5b314a Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 7 Feb 2024 07:19:26 +0100 Subject: [PATCH] work on userRenderTest --- src/Bundle/ChillMainBundle/Entity/User.php | 5 ++ .../Templating/Entity/UserRenderTest.php | 66 +++++++++++-------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 8b0412a38..2d155b54a 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -346,6 +346,11 @@ class User implements UserInterface, \Stringable return $this->jobHistories; } + public function getUserScopeHistories(): Collection + { + return $this->scopeHistories; + } + /** * @return ArrayCollection|UserJobHistory[] */ diff --git a/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php b/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php index 21f73d466..999421c40 100644 --- a/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php @@ -16,52 +16,62 @@ use Twig\Environment; class UserRenderTest extends TestCase { - /** - * @throws \DateInvalidTimeZoneException - * @throws \DateMalformedStringException - */ - public function renderUserWithJobAndScopeAtCertainDateTest(): void + public function testRenderUserWithJobAndScopeAtCertainDate(): void { // Create a user with a certain user job $user = new User(); - $userJob = new UserJob(); - $scope = new Scope(); + $userJobA = new UserJob(); + $scopeA = new Scope(); - $userJob->setLabel(['fr' => 'assistant social']); - $scope->setName(['fr' => 'service A']); + $userJobA->setLabel(['fr' => 'assistant social']); + $scopeA->setName(['fr' => 'service A']); $user->setLabel('BOB ISLA'); - $userJobHistory = (new User\UserJobHistory()) + $userJobB = new UserJob(); + $scopeB = new Scope(); + + $userJobB->setLabel(['fr' => 'directrice']); + $scopeB->setName(['fr' => 'service B']); + + $userJobHistoryA = (new User\UserJobHistory()) ->setUser($user) - ->setJob($userJob) - //setStartDate - ; + ->setJob($userJobA) + ->setStartDate(new \DateTimeImmutable('2023-11-01 12:00:00')) + ->setEndDate(new \DateTimeImmutable('2023-11-30 00:00:00')); - $userScopeHistory = (new User\UserScopeHistory()) + $userScopeHistoryA = (new User\UserScopeHistory()) ->setUser($user) - ->setScope($scope) - ; - $user->getUserJobHistories()->add($userJobHistory); - $user->setMainScope($scope); + ->setScope($scopeA) + ->setStartDate(new \DateTimeImmutable('2023-11-01 12:00:00')) + ->setEndDate(new \DateTimeImmutable('2023-11-30 00:00:00')); -/* // Change the user job - $userJobTwo = new UserJob(); - $userJobTwo->setLabel(['fr' => 'directrice']); + $userJobHistoryB = (new User\UserJobHistory()) + ->setUser($user) + ->setJob($userJobB) + ->setStartDate(new \DateTimeImmutable('2023-12-01 12:00:00')); - // Change the scope - $scopeTwo = new Scope(); - $scopeTwo->setName(['fr' => 'service B']);*/ + $userScopeHistoryB = (new User\UserScopeHistory()) + ->setUser($user) + ->setScope($scopeB) + ->setStartDate(new \DateTimeImmutable('2023-12-01 12:00:00')); + $user->getUserJobHistories()->add($userJobHistoryA); + $user->getUserScopeHistories()->add($userScopeHistoryA); + + $user->getUserJobHistories()->add($userJobHistoryB); + $user->getUserScopeHistories()->add($userScopeHistoryB); // Create renderer $translatableStringHelper = $this->createMock(TranslatableStringHelperInterface::class); $engine = $this->createMock(Environment::class); $translator = $this->createMock(TranslatorInterface::class); - $clock = new MockClock(new \DateTimeImmutable('2023-12-15')); + $clock = new MockClock(new \DateTimeImmutable('2023-12-15 12:00:00')); + $renderer = new UserRender($translatableStringHelper, $engine, $translator, $clock); - $options['at_date'] = new \DateTime('2023-11-30 12:00:00'); + $optionsNoDate['at_date'] = null; + $options['at_date'] = new \DateTime('2023-11-25 12:00:00'); $optionsTwo['at_date'] = new \DateTime('2024-01-30 12:00:00'); // Check that the user render for the first activity corresponds with the first user job @@ -72,7 +82,9 @@ class UserRenderTest extends TestCase $expectedStringB = 'BOB ISLA (directrice) (service B)'; $this->assertEquals($expectedStringB, $renderer->renderString($user, $optionsTwo)); - + // Check that the user renders the job and scope that is active now, when no date is given + $expectedStringC = 'BOB ISLA (directrice) (service B)'; + $this->assertEquals($expectedStringC, $renderer->renderString($user, $optionsNoDate)); } }