mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add test for WorkflowOnHoldControllerTest
This commit is contained in:
parent
a82b99aecc
commit
9c8a84cdbd
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Controller\WorkflowOnHoldController;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepHold;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepHoldRepository;
|
||||
use Chill\MainBundle\Security\ChillSecurity;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
|
||||
class WorkflowOnHoldControllerTest extends TestCase
|
||||
{
|
||||
public function testPutOnHoldSuccess()
|
||||
{
|
||||
// Mocks
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$security = $this->createMock(ChillSecurity::class);
|
||||
$registry = $this->createMock(Registry::class);
|
||||
$entityWorkflowStepHoldRepository = $this->createMock(EntityWorkflowStepHoldRepository::class);
|
||||
$entityWorkflow = $this->createMock(EntityWorkflow::class);
|
||||
$workflow = $this->createMock(Workflow::class);
|
||||
$request = $this->createMock(Request::class);
|
||||
$currentStep = $this->createMock(EntityWorkflow::class); // Assuming EntityWorkflow is the type, adjust if needed
|
||||
$currentUser = $this->createMock(\Chill\MainBundle\Entity\User::class); // Adjust with actual User entity 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([]);
|
||||
|
||||
$entityManager->expects($this->once())
|
||||
->method('persist')
|
||||
->with($this->isInstanceOf(EntityWorkflowStepHold::class));
|
||||
|
||||
$entityManager->expects($this->once())
|
||||
->method('flush');
|
||||
|
||||
$controller = new WorkflowOnHoldController(
|
||||
$entityManager,
|
||||
$security,
|
||||
$registry,
|
||||
$entityWorkflowStepHoldRepository
|
||||
);
|
||||
|
||||
// Smoke test
|
||||
$response = $controller->putOnHold($entityWorkflow, $request);
|
||||
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
$this->assertEquals(302, $response->getStatusCode());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user