Files
luos/tests/unit/workflow/engine/classes/DerivationTest.php

290 lines
10 KiB
PHP
Raw Normal View History

2019-11-05 11:32:47 -04:00
<?php
namespace Tests\unit\workflow\engine\classes;
2019-11-14 14:08:04 -04:00
use Cases;
use Derivation;
use G;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Route;
2020-04-30 16:08:24 -04:00
use ProcessMaker\Model\SubApplication;
2019-11-14 14:08:04 -04:00
use ProcessMaker\Model\Task;
use ProcessMaker\Model\TaskUser;
use ProcessMaker\Model\User;
use Tests\CreateTestSite;
2019-11-05 11:32:47 -04:00
use Tests\TestCase;
class DerivationTest extends TestCase
{
use CreateTestSite;
2019-11-05 11:32:47 -04:00
/**
* Call the setUp parent method
*/
2022-06-09 11:43:56 -04:00
public function setUp(): void
2019-11-05 11:32:47 -04:00
{
parent::setUp(); // TODO: Change the autogenerated stub
2019-11-14 14:08:04 -04:00
// Truncate the APP_SEQUENCE table
DB::table('APP_SEQUENCE')->truncate();
2019-12-19 09:41:52 -04:00
config(["system.workspace" => "new_site"]);
2019-11-14 14:08:04 -04:00
$workspace = config("system.workspace");
$this->createDBFile($workspace);
2019-11-14 14:08:04 -04:00
}
/**
* Call the tearDown method
*/
2022-06-09 11:43:56 -04:00
public function tearDown(): void
2019-11-14 14:08:04 -04:00
{
parent::tearDown(); // TODO: Change the autogenerated stub
2019-11-05 11:32:47 -04:00
}
/**
* It tests the getSubProcessVariables method with object variables
*
* @covers Derivation::getSubProcessVariables()
* @test
*/
public function it_should_test_the_get_sub_process_variables_method_with_object_variables()
{
$fields = ['@&var2' => '@&var3'];
$childCaseData = ['var2' => (object)['Street' => 'test', 'name' => 'Something']];
$parentCaseData = ['var1' => (object)['Street' => 'test']];
$der = new Derivation();
$res = $der->getSubProcessVariables($fields, $childCaseData, $parentCaseData);
$this->assertArrayHasKey('var3', $res);
$this->assertObjectHasAttribute('Street', $res['var3']);
$this->assertObjectHasAttribute('name', $res['var3']);
$this->assertEquals($res['var3'], (object)['Street' => 'test', 'name' => 'Something']);
}
/**
* It tests the getSubProcessVariables method with origin labels
*
* @covers Derivation::getSubProcessVariables()
* @test
*/
public function it_should_test_the_get_sub_process_variables_method_with_origin_labels()
{
$fields = ['@&var2' => '@&var3', '@&var2_label' => '@&var3'];
$childCaseData = [
'var2' => (object)['Street' => 'test', 'name' => 'Something'],
'var2_label' => ['Street' => 'test', 'name' => 'Something']
];
$parentCaseData = ['var1' => (object)['Street' => 'test']];
$der = new Derivation();
$res = $der->getSubProcessVariables($fields, $childCaseData, $parentCaseData);
$this->assertArrayHasKey('var3_label', $res);
$this->assertEquals($res['var3_label'], ['Street' => 'test', 'name' => 'Something']);
}
/**
* It tests the getSubProcessVariables method with target labels
*
* @covers Derivation::getSubProcessVariables()
* @test
*/
public function it_should_test_the_get_sub_process_variables_method_with_target_labels()
{
$fields = ['@&var2' => '@&var3', '@&var2' => '@&var3_label'];
$childCaseData = ['var2' => (object)['Street' => 'test', 'name' => 'Something']];
$parentCaseData = ['var1' => (object)['Street' => 'test']];
$der = new Derivation();
$res = $der->getSubProcessVariables($fields, $childCaseData, $parentCaseData);
$this->assertArrayHasKey('var3_label', $res);
$this->assertObjectHasAttribute('Street', $res['var3_label']);
$this->assertObjectHasAttribute('name', $res['var3_label']);
$this->assertEquals($res['var3_label'], (object)['Street' => 'test', 'name' => 'Something']);
}
2019-11-14 14:08:04 -04:00
/**
* It tests the doDerivation method sending variables synchronously
*
* @covers Derivation::doDerivation()
2020-04-30 16:08:24 -04:00
* @covers Derivation::<protected>
*
2019-11-14 14:08:04 -04:00
* @test
*/
public function it_should_test_the_do_derivation_method_sending_variables_synchronously()
{
// Create the models
$user = User::factory()->create();
$process = Process::factory()->create([
2019-11-14 14:08:04 -04:00
'PRO_CREATE_USER' => $user->USR_UID
]);
$task = Task::factory()->create([
2019-11-14 14:08:04 -04:00
'PRO_UID' => $process->PRO_UID,
]);
$application = Application::factory()->create([
'PRO_UID' => $process->PRO_UID,
'APP_INIT_USER' => $user->USR_UID,
'APP_CUR_USER' => $user->USR_UID
]);
$appDelegation = Delegation::factory()->create([
'APP_UID' => $application->APP_UID,
'APP_NUMBER' => $application->APP_NUMBER
]);
SubApplication::factory()->create([
'APP_UID' => $application->APP_UID,
'APP_PARENT' => $application->APP_UID,
'DEL_INDEX_PARENT' => $appDelegation->DEL_INDEX
]);
2019-11-14 14:08:04 -04:00
// Create the parameters
$currentDelegation = [
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $appDelegation->DEL_INDEX,
'ROU_TYPE' => ''
];
$nextDel = [
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID,
'DEL_PRIORITY' => $appDelegation->DEL_PRIORITY,
'TAS_ASSIGN_TYPE' => $task->TAS_ASSIGN_TYPE,
'TAS_ID' => $task->TAS_ID
];
$appFields = [
'APP_NUMBER' => $application->APP_NUMBER,
2020-11-19 17:21:05 -04:00
'DEL_INDEX' => $appDelegation->DEL_INDEX,
2019-11-14 14:08:04 -04:00
'DEL_THREAD' => $appDelegation->DEL_THREAD,
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
'APP_DATA' => [],
'APP_TITLE' => $application->APP_TITLE,
'APP_UID' => $application->APP_UID
];
$sp = [
'SP_VARIABLES_OUT' => 'a:1:{s:6:"@&var1";s:6:"@&var2";}',
'SP_VARIABLES_IN' => 'a:1:{s:6:"@&var2";s:6:"@&var3";}',
2020-04-30 16:08:24 -04:00
'SP_SYNCHRONOUS' => 1,
2019-11-14 14:08:04 -04:00
'SP_TYPE' => '',
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID,
];
// Create the Derivation object
$der = new Derivation();
$der->case = new Cases;
// Call the doDerivation method
$res = $der->doDerivation($currentDelegation, $nextDel, $appFields, $sp);
// Assert the new delegation index is 1
$this->assertTrue($res >= 1);
2020-04-30 16:08:24 -04:00
// Review the subprocess synchronously
$query = SubApplication::query()->select();
$query->where('APP_PARENT', $application->APP_UID);
$query->where('DEL_INDEX_PARENT', $appDelegation->DEL_INDEX);
$results = $query->get()->toArray();
$this->assertNotEmpty($results);
$this->assertEquals($results[0]['SA_STATUS'], 'ACTIVE');
2019-11-14 14:08:04 -04:00
}
/**
* It tests the doDerivation method sending variables asynchronously
*
* @covers Derivation::doDerivation()
2020-04-30 16:08:24 -04:00
* @covers Derivation::<protected>
*
2019-11-14 14:08:04 -04:00
* @test
*/
public function it_should_test_the_do_derivation_method_sending_variables_asynchronously()
{
// Create the models
$user = User::factory()->create();
$process = Process::factory()->create([
2019-11-14 14:08:04 -04:00
'PRO_CREATE_USER' => $user->USR_UID
]);
$task = Task::factory()->create([
2019-11-14 14:08:04 -04:00
'PRO_UID' => $process->PRO_UID,
'TAS_USER' => $user->USR_UID
]);
TaskUser::factory()->create([
2019-11-14 14:08:04 -04:00
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$application = Application::factory()->create([
'PRO_UID' => $process->PRO_UID,
'APP_INIT_USER' => $user->USR_UID,
'APP_CUR_USER' => $user->USR_UID
2019-11-14 14:08:04 -04:00
]);
$appDelegation = Delegation::factory()->create([
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'APP_NUMBER' => $application->APP_NUMBER
]);
SubApplication::factory()->create([
'APP_UID' => $application->APP_UID,
'APP_PARENT' => $application->APP_UID,
'DEL_INDEX_PARENT' => $appDelegation->DEL_INDEX,
'SA_STATUS' => 'FINISHED'
2019-11-14 14:08:04 -04:00
]);
Route::factory()->create([
2019-11-14 14:08:04 -04:00
'TAS_UID' => $task->TAS_UID,
'ROU_NEXT_TASK' => $task->TAS_UID,
'PRO_UID' => $process->PRO_UID
]);
// Create the parameters
$currentDelegation = [
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $appDelegation->DEL_INDEX,
'ROU_TYPE' => '',
'TAS_UID' => $task->TAS_UID
];
$nextDel = [
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID,
'DEL_PRIORITY' => $appDelegation->DEL_PRIORITY,
'TAS_ASSIGN_TYPE' => $task->TAS_ASSIGN_TYPE,
'TAS_ID' => $task->TAS_ID
];
$appFields = [
'APP_NUMBER' => $application->APP_NUMBER,
'DEL_THREAD' => $appDelegation->DEL_THREAD,
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
'APP_DATA' => [],
'APP_TITLE' => $application->APP_TITLE,
'APP_UID' => $application->APP_UID
];
$sp = [
'SP_VARIABLES_OUT' => 'a:1:{s:6:"@&var1";s:6:"@&var2";}',
'SP_VARIABLES_IN' => 'a:1:{s:6:"@&var2";s:6:"@&var3";}',
2020-04-30 16:08:24 -04:00
'SP_SYNCHRONOUS' => 0,
2019-11-14 14:08:04 -04:00
'SP_TYPE' => '',
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID,
];
// Create the Derivation object
$der = new Derivation();
$der->case = new Cases;
// Call the doDerivation method
$res = $der->doDerivation($currentDelegation, $nextDel, $appFields, $sp);
// Assert the new delegation index is 1
$this->assertTrue($res >= 1);
2020-04-30 16:08:24 -04:00
// Review the subprocess asynchronously
$query = SubApplication::query()->select();
$query->where('APP_PARENT', $application->APP_UID);
$query->where('DEL_INDEX_PARENT', $appDelegation->DEL_INDEX);
$results = $query->get()->toArray();
$this->assertNotEmpty($results);
$this->assertEquals($results[0]['SA_STATUS'], 'FINISHED');
2019-11-14 14:08:04 -04:00
}
2019-11-05 11:32:47 -04:00
}