work on userRender test

This commit is contained in:
Julie Lenaerts 2024-01-23 18:13:33 +01:00
parent 853014d8d2
commit d91b1a70bf

View File

@ -0,0 +1,65 @@
<?php
namespace Templating\Entity;
use Chill\ActivityBundle\Entity\Activity;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Clock\MockClock;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class UserRenderTest extends TestCase
{
public function renderUserWithJobAndScopeAtCertainDateTest(): void
{
// Create a user with a certain user job
$user = new User();
$userJob = new UserJob();
$scope = new Scope();
$userJob->setLabel(['fr' => 'assistant social']);
$scope->setName(['fr' => 'service A']);
$user->setLabel('BOB ISLA');
$user->setUserJob($userJob);
$user->setMainScope($scope);
// Change the user job
$userJobTwo = new UserJob();
$userJobTwo->setLabel(['fr' => 'directrice']);
/* this automatically creates a UserJobHistory. How to set the date manually though? **/
// Change the scope
$scopeTwo = new Scope();
$scopeTwo->setName(['fr' => 'service B']);
/* this automatically creates a UserScopeHistory. How to set the date manually though? **/
// Create renderer
$translatableStringHelper = $this->createMock(TranslatableStringHelperInterface::class);
$engine = $this->createMock(Environment::class);
$translator = $this->createMock(TranslatorInterface::class);
$renderer = new UserRender($translatableStringHelper, $engine, $translator);
$options['at_date'] = new \DateTime('2023-11-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
$expectedStringA = 'BOB ISLA (assistant social) (service A)';
$this->assertEquals($expectedStringA, $renderer->renderString($user, $options));
// Check that the user render for the second activity corresponds with the second user job
$expectedStringB = 'BOB ISLA (directrice) (service B)';
$this->assertEquals($expectedStringB, $renderer->renderString($user, $optionsTwo));
}
}