mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Adjust test to check creation of onHold if user is allowed to apply a transition
This commit is contained in:
parent
46b31ae1ea
commit
41ffc470a0
@ -17,52 +17,89 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
|
use Symfony\Component\Workflow\Transition;
|
||||||
use Symfony\Component\Workflow\Workflow;
|
use Symfony\Component\Workflow\Workflow;
|
||||||
|
|
||||||
class WorkflowOnHoldControllerTest extends KernelTestCase
|
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();
|
self::bootKernel();
|
||||||
|
|
||||||
// Mocks
|
// Mocks
|
||||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
$this->entityManager = $this->createMock(EntityManagerInterface::class);
|
||||||
$security = $this->createMock(Security::class);
|
$this->security = $this->createMock(Security::class);
|
||||||
$registry = $this->createMock(Registry::class);
|
$this->registry = $this->createMock(Registry::class);
|
||||||
$entityWorkflowStepHoldRepository = $this->createMock(EntityWorkflowStepHoldRepository::class);
|
$this->entityWorkflowStepHoldRepository = $this->createMock(EntityWorkflowStepHoldRepository::class);
|
||||||
|
|
||||||
$entityWorkflow = $this->createMock(EntityWorkflow::class);
|
$this->entityWorkflow = $this->createMock(EntityWorkflow::class);
|
||||||
$workflow = $this->createMock(Workflow::class);
|
$this->workflow = $this->createMock(Workflow::class);
|
||||||
$request = new Request();
|
$this->currentStep = $this->createMock(EntityWorkflowStep::class);
|
||||||
$currentStep = $this->createMock(EntityWorkflowStep::class);
|
$this->currentUser = $this->createMock(\Chill\MainBundle\Entity\User::class);
|
||||||
$currentUser = $this->createMock(\Chill\MainBundle\Entity\User::class);
|
|
||||||
|
|
||||||
// Define expected behaviors for the mocks
|
// Define expected behaviors for the mocks
|
||||||
$entityWorkflow->method('getCurrentStep')->willReturn($currentStep);
|
$this->entityWorkflow->method('getCurrentStep')->willReturn($this->currentStep);
|
||||||
$security->method('getUser')->willReturn($currentUser);
|
$this->security->method('getUser')->willReturn($this->currentUser);
|
||||||
$entityWorkflow->method('getWorkflowName')->willReturn('workflow_name');
|
$this->entityWorkflow->method('getWorkflowName')->willReturn('workflow_name');
|
||||||
$registry->method('get')->with($entityWorkflow, 'workflow_name')->willReturn($workflow);
|
$this->registry->method('get')->with($this->entityWorkflow, 'workflow_name')->willReturn($this->workflow);
|
||||||
$workflow->method('getEnabledTransitions')->with($entityWorkflow)->willReturn([]);
|
$this->workflow->method('getEnabledTransitions')->with($this->entityWorkflow)->willReturn([]);
|
||||||
$entityWorkflow->method('getUsersInvolved')->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')
|
->method('persist')
|
||||||
->with($this->isInstanceOf(EntityWorkflowStepHold::class));
|
->with($this->isInstanceOf(EntityWorkflowStepHold::class));
|
||||||
|
|
||||||
$entityManager->expects($this->once())
|
$this->entityManager->expects($this->once())
|
||||||
->method('flush');
|
->method('flush');
|
||||||
|
|
||||||
$controller = new WorkflowOnHoldController(
|
$controller = new WorkflowOnHoldController(
|
||||||
$entityManager,
|
$this->entityManager,
|
||||||
$security,
|
$this->security,
|
||||||
$registry,
|
$this->registry,
|
||||||
$entityWorkflowStepHoldRepository
|
$this->entityWorkflowStepHoldRepository
|
||||||
);
|
);
|
||||||
|
|
||||||
/* // Smoke test
|
$request = new Request();
|
||||||
$response = $controller->putOnHold($entityWorkflow, $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->assertInstanceOf(Response::class, $response);
|
||||||
$this->assertEquals(302, $response->getStatusCode());*/
|
$this->assertEquals(302, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user