PMCORE-1404 Use Jobs in the 'script task' and 'service task' execution
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Cases;
|
||||
|
||||
use App\Jobs\CasesDispatch;
|
||||
use Cases;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\Route;
|
||||
use ProcessMaker\Model\Step;
|
||||
use ProcessMaker\Model\StepTrigger;
|
||||
use ProcessMaker\Model\Task;
|
||||
use ProcessMaker\Model\TaskUser;
|
||||
use ProcessMaker\Model\Triggers;
|
||||
use ProcessMaker\Model\User;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CasesTraitTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Set up method.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare initial derivation data.
|
||||
* @return object
|
||||
*/
|
||||
private function prepareDerivationData()
|
||||
{
|
||||
$user = User::where('USR_ID', '=', 1)->get()->first();
|
||||
|
||||
$process = factory(Process::class)->create([
|
||||
'PRO_CREATE_USER' => $user->USR_UID
|
||||
]);
|
||||
$task = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => 'BALANCED',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
factory(TaskUser::class)->create([
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'TU_RELATION' => 1,
|
||||
'TU_TYPE' => 1
|
||||
]);
|
||||
$task2 = factory(Task::class)->create([
|
||||
'TAS_ASSIGN_TYPE' => 'BALANCED',
|
||||
'TAS_GROUP_VARIABLE' => '',
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
factory(TaskUser::class)->create([
|
||||
'TAS_UID' => $task2->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'TU_RELATION' => 1,
|
||||
'TU_TYPE' => 1
|
||||
]);
|
||||
|
||||
|
||||
$application = factory(Application::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
$appDelegation = factory(Delegation::class)->create([
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'DEL_INDEX' => 1,
|
||||
]);
|
||||
factory(Delegation::class)->create([
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'TAS_UID' => $task2->TAS_UID,
|
||||
'DEL_INDEX' => 2,
|
||||
'DEL_PREVIOUS' => $appDelegation->DEL_INDEX
|
||||
]);
|
||||
factory(Route::class)->create([
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'ROU_NEXT_TASK' => $task2->TAS_UID,
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
|
||||
$step = factory(Step::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'TAS_UID' => $appDelegation->TAS_UID,
|
||||
'STEP_POSITION' => 2,
|
||||
'STEP_CONDITION' => '1 == 1'
|
||||
]);
|
||||
|
||||
|
||||
$triggers = factory(Triggers::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'TRI_WEBBOT' => '$a = 0;'
|
||||
]);
|
||||
factory(StepTrigger::class)->create([
|
||||
'STEP_UID' => -2,
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'TRI_UID' => $triggers->TRI_UID,
|
||||
'ST_CONDITION' => '1 == 1',
|
||||
'ST_TYPE' => 'BEFORE'
|
||||
]);
|
||||
|
||||
|
||||
$triggers = factory(Triggers::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'TRI_WEBBOT' => '$b = 0;'
|
||||
]);
|
||||
factory(StepTrigger::class)->create([
|
||||
'STEP_UID' => -2,
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'TRI_UID' => $triggers->TRI_UID,
|
||||
'ST_CONDITION' => '2 == 2',
|
||||
'ST_TYPE' => 'AFTER'
|
||||
]);
|
||||
|
||||
$result = [
|
||||
'application' => $application,
|
||||
'user' => $user,
|
||||
'task' => $task,
|
||||
'task2' => $task2,
|
||||
];
|
||||
return (object) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies that the derivation of the case has closed the delegation
|
||||
* with single task.
|
||||
* @test
|
||||
* @covers \Cases::routeCase
|
||||
*/
|
||||
public function it_should_test_a_derivate_case_with_single_task()
|
||||
{
|
||||
$result = $this->prepareDerivationData();
|
||||
$application = $result->application;
|
||||
$user = $result->user;
|
||||
$task = $result->task;
|
||||
$task2 = $result->task2;
|
||||
|
||||
$processUid = $application->PRO_UID;
|
||||
$application = $application->APP_UID;
|
||||
$postForm = [
|
||||
'ROU_TYPE' => 'SEQUENTIAL',
|
||||
'TASKS' => [
|
||||
1 => [
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'TAS_ASSIGN_TYPE' => "BALANCED",
|
||||
'TAS_DEF_PROC_CODE' => "",
|
||||
'DEL_PRIORITY' => "",
|
||||
'TAS_PARENT' => "",
|
||||
'ROU_CONDITION' => "",
|
||||
'SOURCE_UID' => $task->TAS_UID,
|
||||
]
|
||||
]
|
||||
];
|
||||
$status = 'TO_DO';
|
||||
$flagGmail = true;
|
||||
$tasUid = $task->TAS_UID;
|
||||
$index = '1';
|
||||
$userLogged = $user->USR_UID;
|
||||
|
||||
$cases = new Cases();
|
||||
$cases->routeCase($processUid, $application, $postForm, $status, $flagGmail, $tasUid, $index, $userLogged);
|
||||
|
||||
$result = Delegation::where('APP_UID', '=', $application)->where('DEL_INDEX', '=', $index)->get()->first();
|
||||
|
||||
$this->assertEquals('CLOSED', $result->DEL_THREAD_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies that the derivation of the case has closed the delegation
|
||||
* with multiple task.
|
||||
* @test
|
||||
* @covers \Cases::routeCase
|
||||
*/
|
||||
public function it_should_test_a_derivate_case_with_multiple_task()
|
||||
{
|
||||
$result = $this->prepareDerivationData();
|
||||
$application = $result->application;
|
||||
$user = $result->user;
|
||||
$task = $result->task;
|
||||
$task2 = $result->task2;
|
||||
|
||||
$processUid = $application->PRO_UID;
|
||||
$application = $application->APP_UID;
|
||||
$postForm = [
|
||||
'ROU_TYPE' => 'SEQUENTIAL',
|
||||
'TASKS' => [
|
||||
1 => [
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'TAS_ASSIGN_TYPE' => "BALANCED",
|
||||
'TAS_DEF_PROC_CODE' => "",
|
||||
'DEL_PRIORITY' => "",
|
||||
'TAS_PARENT' => "",
|
||||
'ROU_CONDITION' => "",
|
||||
'SOURCE_UID' => $task->TAS_UID,
|
||||
],
|
||||
2 => [
|
||||
'TAS_UID' => $task2->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'TAS_ASSIGN_TYPE' => "BALANCED",
|
||||
'TAS_DEF_PROC_CODE' => "",
|
||||
'DEL_PRIORITY' => "",
|
||||
'TAS_PARENT' => "",
|
||||
'ROU_CONDITION' => "",
|
||||
'SOURCE_UID' => $task2->TAS_UID,
|
||||
]
|
||||
]
|
||||
];
|
||||
$status = 'TO_DO';
|
||||
$flagGmail = true;
|
||||
$tasUid = $task->TAS_UID;
|
||||
$index = '1';
|
||||
$userLogged = $user->USR_UID;
|
||||
|
||||
$cases = new Cases();
|
||||
$cases->routeCase($processUid, $application, $postForm, $status, $flagGmail, $tasUid, $index, $userLogged);
|
||||
|
||||
$result = Delegation::where('APP_UID', '=', $application)->where('DEL_INDEX', '=', $index)->get()->first();
|
||||
|
||||
$this->assertEquals('CLOSED', $result->DEL_THREAD_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies that the 'CasesDispath' job is in the queue.
|
||||
* @test
|
||||
* @covers \Cases::routeCase
|
||||
*/
|
||||
public function this_should_add_a_cases_dispath_job_to_the_queue()
|
||||
{
|
||||
$result = $this->prepareDerivationData();
|
||||
$application = $result->application;
|
||||
$user = $result->user;
|
||||
$task = $result->task;
|
||||
$task2 = $result->task2;
|
||||
|
||||
$_SESSION['PROCESS'] = $application->PRO_UID;
|
||||
$_SESSION['APPLICATION'] = $application->APP_UID;
|
||||
$_POST['form'] = [
|
||||
'ROU_TYPE' => 'SEQUENTIAL',
|
||||
'TASKS' => [
|
||||
1 => [
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'TAS_ASSIGN_TYPE' => "BALANCED",
|
||||
'TAS_DEF_PROC_CODE' => "",
|
||||
'DEL_PRIORITY' => "",
|
||||
'TAS_PARENT' => "",
|
||||
'ROU_CONDITION' => "",
|
||||
'SOURCE_UID' => $task->TAS_UID,
|
||||
],
|
||||
2 => [
|
||||
'TAS_UID' => $task2->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'TAS_ASSIGN_TYPE' => "BALANCED",
|
||||
'TAS_DEF_PROC_CODE' => "",
|
||||
'DEL_PRIORITY' => "",
|
||||
'TAS_PARENT' => "",
|
||||
'ROU_CONDITION' => "",
|
||||
'SOURCE_UID' => $task2->TAS_UID,
|
||||
]
|
||||
]
|
||||
];
|
||||
$status = 'TO_DO';
|
||||
$flagGmail = true;
|
||||
$_SESSION['TASK'] = $task->TAS_UID;
|
||||
$_SESSION["INDEX"] = '1';
|
||||
$_SESSION['USER_LOGGED'] = $user->USR_UID;
|
||||
|
||||
global $RBAC;
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$RBAC->initRBAC();
|
||||
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
|
||||
|
||||
Queue::fake();
|
||||
Queue::assertNothingPushed();
|
||||
|
||||
require_once PATH_METHODS . 'cases/cases_Derivate.php';
|
||||
|
||||
Queue::assertPushed(CasesDispatch::class);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,15 @@ class DelegationTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* Set up function.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks to make sure pagination is working properly
|
||||
*
|
||||
@@ -255,6 +264,7 @@ class DelegationTest extends TestCase
|
||||
$this->assertCount(1, $results['data']);
|
||||
$this->assertEquals($application->APP_NUMBER, $results['data'][0]['APP_NUMBER']);
|
||||
}
|
||||
|
||||
/**
|
||||
* This ensures searching by case number and review the order
|
||||
*
|
||||
@@ -263,28 +273,23 @@ class DelegationTest extends TestCase
|
||||
*/
|
||||
public function it_should_search_and_filter_by_app_title()
|
||||
{
|
||||
$title = '';
|
||||
for ($x = 1; $x <= 10; $x++) {
|
||||
$application = factory(Application::class)->states('foreign_keys')->create();
|
||||
factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'PRO_UID' => $application->PRO_UID,
|
||||
'PRO_ID' => $application->PRO_ID
|
||||
]);
|
||||
$title = $application->APP_TITLE;
|
||||
}
|
||||
$delegations = factory(Delegation::class, 1)
|
||||
->states('foreign_keys')
|
||||
->create();
|
||||
$title = $delegations->last()
|
||||
->application
|
||||
->APP_TITLE;
|
||||
// We need to commit the records inserted because is needed for the "fulltext" index
|
||||
DB::commit();
|
||||
|
||||
// Searching by a existent case title, result ordered by APP_NUMBER, filter by APP_NUMBER in DESC mode
|
||||
$results = Delegation::search(null, 0, 10, $title, null, null, 'DESC',
|
||||
'APP_NUMBER', null, null, null, 'APP_TITLE');
|
||||
'APP_NUMBER', null, null, null, 'APP_TITLE');
|
||||
$this->assertCount(1, $results['data']);
|
||||
$this->assertEquals($title, $results['data'][0]['APP_TITLE']);
|
||||
// Searching by a existent case title, result ordered by APP_NUMBER, filter by APP_NUMBER in ASC mode
|
||||
$results = Delegation::search(null, 0, 10, $title, null, null, 'ASC',
|
||||
'APP_NUMBER', null, null, null, 'APP_TITLE');
|
||||
'APP_NUMBER', null, null, null, 'APP_TITLE');
|
||||
$this->assertCount(1, $results['data']);
|
||||
$this->assertEquals($title, $results['data'][0]['APP_TITLE']);
|
||||
}
|
||||
@@ -536,7 +541,6 @@ class DelegationTest extends TestCase
|
||||
// Process with the category to search
|
||||
$category = factory(ProcessCategory::class)->create();
|
||||
$processSearch = factory(Process::class)->create([
|
||||
'PRO_ID' => 5,
|
||||
'PRO_CATEGORY' => $category->CATEGORY_UID
|
||||
]);
|
||||
// Delegations to found
|
||||
|
||||
@@ -25,10 +25,10 @@ class ProcessTest extends TestCase
|
||||
*/
|
||||
public function it_has_tasks()
|
||||
{
|
||||
$process = factory(Process::class)->create([
|
||||
'PRO_ID' => function () {
|
||||
return factory(Task::class)->create()->PRO_ID;
|
||||
}
|
||||
$process = factory(Process::class)->create();
|
||||
factory(Task::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'PRO_ID' => $process->PRO_ID
|
||||
]);
|
||||
$this->assertInstanceOf(Task::class, $process->tasks);
|
||||
}
|
||||
|
||||
@@ -192,11 +192,12 @@ class ServerTest extends TestCase
|
||||
if (!is_dir(PATH_DB)) {
|
||||
mkdir(PATH_DB);
|
||||
}
|
||||
if (!is_dir(PATH_WORKSPACE)) {
|
||||
mkdir(PATH_WORKSPACE);
|
||||
$pathWorkspace = PATH_DB . config('system.workspace') . PATH_SEP;
|
||||
if (!is_dir($pathWorkspace)) {
|
||||
mkdir($pathWorkspace);
|
||||
}
|
||||
$info = $this->getLicenseInfo();
|
||||
$filename = PATH_WORKSPACE . $info['name'];
|
||||
$filename = $pathWorkspace . $info['name'];
|
||||
$data = $info['content'];
|
||||
file_put_contents($filename, $data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user