Adjust test to check creation of onHold if user is allowed to apply a transition

This commit is contained in:
Julie Lenaerts 2024-08-30 11:30:06 +02:00 committed by Julien Fastré
parent 46b31ae1ea
commit 41ffc470a0
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -17,52 +17,89 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\Workflow;
class WorkflowOnHoldControllerTest extends KernelTestCase
{
public function testPutOnHoldSuccess()
private $entityManager;
private $security;
private $registry;
private $entityWorkflowStepHoldRepository;
private $entityWorkflow;
private $workflow;
private $currentStep;
private $currentUser;
protected function setUp(): void
{
self::bootKernel();
// Mocks
$entityManager = $this->createMock(EntityManagerInterface::class);
$security = $this->createMock(Security::class);
$registry = $this->createMock(Registry::class);
$entityWorkflowStepHoldRepository = $this->createMock(EntityWorkflowStepHoldRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->security = $this->createMock(Security::class);
$this->registry = $this->createMock(Registry::class);
$this->entityWorkflowStepHoldRepository = $this->createMock(EntityWorkflowStepHoldRepository::class);
$entityWorkflow = $this->createMock(EntityWorkflow::class);
$workflow = $this->createMock(Workflow::class);
$request = new Request();
$currentStep = $this->createMock(EntityWorkflowStep::class);
$currentUser = $this->createMock(\Chill\MainBundle\Entity\User::class);
$this->entityWorkflow = $this->createMock(EntityWorkflow::class);
$this->workflow = $this->createMock(Workflow::class);
$this->currentStep = $this->createMock(EntityWorkflowStep::class);
$this->currentUser = $this->createMock(\Chill\MainBundle\Entity\User::class);
// Define expected behaviors for the mocks
$entityWorkflow->method('getCurrentStep')->willReturn($currentStep);
$security->method('getUser')->willReturn($currentUser);
$entityWorkflow->method('getWorkflowName')->willReturn('workflow_name');
$registry->method('get')->with($entityWorkflow, 'workflow_name')->willReturn($workflow);
$workflow->method('getEnabledTransitions')->with($entityWorkflow)->willReturn([]);
$entityWorkflow->method('getUsersInvolved')->willReturn([]);
$this->entityWorkflow->method('getCurrentStep')->willReturn($this->currentStep);
$this->security->method('getUser')->willReturn($this->currentUser);
$this->entityWorkflow->method('getWorkflowName')->willReturn('workflow_name');
$this->registry->method('get')->with($this->entityWorkflow, 'workflow_name')->willReturn($this->workflow);
$this->workflow->method('getEnabledTransitions')->with($this->entityWorkflow)->willReturn([]);
$this->entityWorkflow->method('getUsersInvolved')->willReturn([]);
}
$entityManager->expects($this->once())
public function testPutOnHoldPersistence(): void
{
// Adjust mock for getEnabledTransitions to return a non-empty array
$transition = $this->createMock(Transition::class);
$transition->method('getName')->willReturn('dummy_transition');
$this->workflow->method('getEnabledTransitions')
->with($this->entityWorkflow)
->willReturn([$transition]);
$this->workflow->method('can')
->with($this->entityWorkflow, 'dummy_transition')
->willReturn(true);
$this->entityManager->expects($this->once())
->method('persist')
->with($this->isInstanceOf(EntityWorkflowStepHold::class));
$entityManager->expects($this->once())
$this->entityManager->expects($this->once())
->method('flush');
$controller = new WorkflowOnHoldController(
$entityManager,
$security,
$registry,
$entityWorkflowStepHoldRepository
$this->entityManager,
$this->security,
$this->registry,
$this->entityWorkflowStepHoldRepository
);
/* // Smoke test
$response = $controller->putOnHold($entityWorkflow, $request);
$request = new Request();
$controller->putOnHold($this->entityWorkflow, $request);
}
public function testPutOnHoldSmokeTest(): void
{
$controller = new WorkflowOnHoldController(
$this->entityManager,
$this->security,
$this->registry,
$this->entityWorkflowStepHoldRepository
);
$request = new Request();
$response = $controller->putOnHold($this->entityWorkflow, $request);
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(302, $response->getStatusCode());*/
$this->assertEquals(302, $response->getStatusCode());
}
}