work on userRenderTest

This commit is contained in:
Julie Lenaerts 2024-02-07 07:19:26 +01:00
parent 2121b3ef28
commit 835409cb94
2 changed files with 44 additions and 27 deletions

View File

@ -346,6 +346,11 @@ class User implements UserInterface, \Stringable
return $this->jobHistories;
}
public function getUserScopeHistories(): Collection
{
return $this->scopeHistories;
}
/**
* @return ArrayCollection|UserJobHistory[]
*/

View File

@ -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));
}
}