diff --git a/tests/unit/workflow/engine/classes/DerivationTest.php b/tests/unit/workflow/engine/classes/DerivationTest.php index ca42ee585..da821037e 100644 --- a/tests/unit/workflow/engine/classes/DerivationTest.php +++ b/tests/unit/workflow/engine/classes/DerivationTest.php @@ -2,7 +2,17 @@ namespace Tests\unit\workflow\engine\classes; -use \Derivation; +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; +use ProcessMaker\Model\Task; +use ProcessMaker\Model\TaskUser; +use ProcessMaker\Model\User; use Tests\TestCase; class DerivationTest extends TestCase @@ -15,6 +25,41 @@ class DerivationTest extends TestCase { parent::setUp(); // TODO: Change the autogenerated stub + // Truncate the APP_SEQUENCE table + DB::table('APP_SEQUENCE')->truncate(); + + config(["system.workspace" => "test"]); + $workspace = config("system.workspace"); + + if (!file_exists(PATH_DB . $workspace)) { + G::mk_dir(PATH_DB . $workspace); + } + + if (!file_exists(PATH_DB . $workspace . PATH_SEP . "db.php")) { + $myfile = fopen(PATH_DB . $workspace . PATH_SEP . "db.php", "w"); + fwrite($myfile, "assertObjectHasAttribute('name', $res['var3_label']); $this->assertEquals($res['var3_label'], (object)['Street' => 'test', 'name' => 'Something']); } + + /** + * It tests the doDerivation method sending variables synchronously + * + * @covers Derivation::doDerivation() + * @test + */ + public function it_should_test_the_do_derivation_method_sending_variables_synchronously() + { + // Create the models + $user = factory(User::class)->create(); + $process = factory(Process::class)->create([ + 'PRO_CREATE_USER' => $user->USR_UID + ]); + $task = factory(Task::class)->create([ + 'PRO_UID' => $process->PRO_UID, + ]); + $application = factory(Application::class)->create(); + $appDelegation = factory(Delegation::class)->create(); + + // 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, + '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";}', + 'SP_SYNCHRONOUS' => '1', + '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->assertEquals(1, $res); + } + + /** + * It tests the doDerivation method sending variables asynchronously + * + * @covers Derivation::doDerivation() + * @test + */ + public function it_should_test_the_do_derivation_method_sending_variables_asynchronously() + { + // Create the models + $user = factory(User::class)->create(); + $process = factory(Process::class)->create([ + 'PRO_CREATE_USER' => $user->USR_UID + ]); + $task = factory(Task::class)->create([ + 'PRO_UID' => $process->PRO_UID, + 'TAS_USER' => $user->USR_UID + ]); + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + ]); + $application = factory(Application::class)->create(); + $appDelegation = factory(Delegation::class)->create([ + 'TAS_UID' => $task->TAS_UID + ]); + factory(Route::class)->create([ + '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";}', + 'SP_SYNCHRONOUS' => '0', + '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->assertEquals(1, $res); + } } \ No newline at end of file