mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
work on userRenderTest
This commit is contained in:
parent
2121b3ef28
commit
835409cb94
@ -346,6 +346,11 @@ class User implements UserInterface, \Stringable
|
||||
return $this->jobHistories;
|
||||
}
|
||||
|
||||
public function getUserScopeHistories(): Collection
|
||||
{
|
||||
return $this->scopeHistories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection|UserJobHistory[]
|
||||
*/
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user