mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
work on userRenderTest
This commit is contained in:
parent
3be8a39a1a
commit
a13ada2937
@ -344,6 +344,11 @@ class User implements UserInterface, \Stringable
|
|||||||
return $this->jobHistories;
|
return $this->jobHistories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUserScopeHistories(): Collection
|
||||||
|
{
|
||||||
|
return $this->scopeHistories;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ArrayCollection|UserJobHistory[]
|
* @return ArrayCollection|UserJobHistory[]
|
||||||
*/
|
*/
|
||||||
|
@ -16,52 +16,62 @@ use Twig\Environment;
|
|||||||
|
|
||||||
class UserRenderTest extends TestCase
|
class UserRenderTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
public function testRenderUserWithJobAndScopeAtCertainDate(): void
|
||||||
* @throws \DateInvalidTimeZoneException
|
|
||||||
* @throws \DateMalformedStringException
|
|
||||||
*/
|
|
||||||
public function renderUserWithJobAndScopeAtCertainDateTest(): void
|
|
||||||
{
|
{
|
||||||
// Create a user with a certain user job
|
// Create a user with a certain user job
|
||||||
|
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$userJob = new UserJob();
|
$userJobA = new UserJob();
|
||||||
$scope = new Scope();
|
$scopeA = new Scope();
|
||||||
|
|
||||||
$userJob->setLabel(['fr' => 'assistant social']);
|
$userJobA->setLabel(['fr' => 'assistant social']);
|
||||||
$scope->setName(['fr' => 'service A']);
|
$scopeA->setName(['fr' => 'service A']);
|
||||||
$user->setLabel('BOB ISLA');
|
$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)
|
->setUser($user)
|
||||||
->setJob($userJob)
|
->setJob($userJobA)
|
||||||
//setStartDate
|
->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)
|
->setUser($user)
|
||||||
->setScope($scope)
|
->setScope($scopeA)
|
||||||
;
|
->setStartDate(new \DateTimeImmutable('2023-11-01 12:00:00'))
|
||||||
$user->getUserJobHistories()->add($userJobHistory);
|
->setEndDate(new \DateTimeImmutable('2023-11-30 00:00:00'));
|
||||||
$user->setMainScope($scope);
|
|
||||||
|
|
||||||
/* // Change the user job
|
$userJobHistoryB = (new User\UserJobHistory())
|
||||||
$userJobTwo = new UserJob();
|
->setUser($user)
|
||||||
$userJobTwo->setLabel(['fr' => 'directrice']);
|
->setJob($userJobB)
|
||||||
|
->setStartDate(new \DateTimeImmutable('2023-12-01 12:00:00'));
|
||||||
|
|
||||||
// Change the scope
|
$userScopeHistoryB = (new User\UserScopeHistory())
|
||||||
$scopeTwo = new Scope();
|
->setUser($user)
|
||||||
$scopeTwo->setName(['fr' => 'service B']);*/
|
->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
|
// Create renderer
|
||||||
$translatableStringHelper = $this->createMock(TranslatableStringHelperInterface::class);
|
$translatableStringHelper = $this->createMock(TranslatableStringHelperInterface::class);
|
||||||
$engine = $this->createMock(Environment::class);
|
$engine = $this->createMock(Environment::class);
|
||||||
$translator = $this->createMock(TranslatorInterface::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);
|
$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');
|
$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
|
// 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)';
|
$expectedStringB = 'BOB ISLA (directrice) (service B)';
|
||||||
$this->assertEquals($expectedStringB, $renderer->renderString($user, $optionsTwo));
|
$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