diff --git a/tests/unit/workflow/engine/classes/PmFunctions/PMFCaseInformationTest.php b/tests/unit/workflow/engine/classes/PmFunctions/PMFCaseInformationTest.php new file mode 100644 index 000000000..ed7752f3d --- /dev/null +++ b/tests/unit/workflow/engine/classes/PmFunctions/PMFCaseInformationTest.php @@ -0,0 +1,132 @@ +states('foreign_keys')->create(); + // Force commit for propel + DB::commit(); + // Call the funtion + $result = PMFCaseInformation($table->APP_UID, 0, 0); + $this->assertNotEmpty($result); + // Colums to return with the default parameters + $this->assertArrayHasKey('APP_UID', $result); + $this->assertArrayHasKey('APP_NUMBER', $result); + $this->assertArrayHasKey('APP_STATUS', $result); + $this->assertArrayHasKey('APP_STATUS_ID', $result); + $this->assertArrayHasKey('PRO_UID', $result); + $this->assertArrayHasKey('APP_INIT_USER', $result); + $this->assertArrayHasKey('APP_CUR_USER', $result); + $this->assertArrayHasKey('APP_CREATE_DATE', $result); + $this->assertArrayHasKey('APP_INIT_DATE', $result); + $this->assertArrayHasKey('APP_FINISH_DATE', $result); + $this->assertArrayHasKey('APP_UPDATE_DATE', $result); + $this->assertArrayHasKey('PRO_ID', $result); + $this->assertArrayHasKey('APP_INIT_USER_ID', $result); + // When the index = 0 those values will not return + $this->assertArrayNotHasKey('DEL_INDEX', $result); + $this->assertArrayNotHasKey('DEL_PREVIOUS', $result); + $this->assertArrayNotHasKey('DEL_TYPE', $result); + $this->assertArrayNotHasKey('DEL_PRIORITY', $result); + $this->assertArrayNotHasKey('DEL_THREAD_STATUS', $result); + $this->assertArrayNotHasKey('DEL_THREAD', $result); + $this->assertArrayNotHasKey('DEL_DELEGATE_DATE', $result); + $this->assertArrayNotHasKey('DEL_INIT_DATE', $result); + $this->assertArrayNotHasKey('DEL_TASK_DUE_DATE', $result); + $this->assertArrayNotHasKey('DEL_FINISH_DATE', $result); + // When the returnAppData = 0, false this value will not return + $this->assertArrayNotHasKey('APP_DATA', $result); + } + + /** + * It tests the PMFCaseInformation() function with index parameter + * + * @test + */ + public function it_should_test_this_pmfunction_index_parameter() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + // Force commit for propel + DB::commit(); + // Call the funtion + $result = PMFCaseInformation($table->APP_UID, $table->DEL_INDEX, 0); + $this->assertNotEmpty($result); + // When the index != 0 those values will return + $this->assertArrayHasKey('DEL_INDEX', $result); + $this->assertArrayHasKey('DEL_PREVIOUS', $result); + $this->assertArrayHasKey('DEL_TYPE', $result); + $this->assertArrayHasKey('DEL_PRIORITY', $result); + $this->assertArrayHasKey('DEL_THREAD_STATUS', $result); + $this->assertArrayHasKey('DEL_THREAD', $result); + $this->assertArrayHasKey('DEL_DELEGATE_DATE', $result); + $this->assertArrayHasKey('DEL_INIT_DATE', $result); + $this->assertArrayHasKey('DEL_TASK_DUE_DATE', $result); + $this->assertArrayHasKey('DEL_FINISH_DATE', $result); + } + + /** + * It tests the PMFCaseInformation() function with returnAppData parameter + * + * @test + */ + public function it_should_test_this_pmfunction_app_data_parameter() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + // Force commit for propel + DB::commit(); + // Call the funtion + $result = PMFCaseInformation($table->APP_UID, 0, true); + $this->assertNotEmpty($result); + // When the returnAppData = true, the case data will return + $this->assertArrayHasKey('APP_DATA', $result); + } + + /** + * It tests the exception caseUid is required in the PMFCaseInformation() function + * + * @test + */ + public function it_should_test_exception_user_required() + { + $this->expectExceptionMessage('**ID_REQUIRED_FIELD**'); + $result = PMFCaseInformation('', 0, 0); + } +} \ No newline at end of file diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index b5d773a1f..51f141a44 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -7226,7 +7226,14 @@ class Cases } } - public function unserializeData($data) + /** + * Unserialize the case data + * + * @param string $data + * + * @return array + */ + public static function unserializeData($data) { $unserializedData = @unserialize($data); diff --git a/workflow/engine/classes/class.pmFunctions.php b/workflow/engine/classes/class.pmFunctions.php index cc5b47913..a1ec3b07b 100644 --- a/workflow/engine/classes/class.pmFunctions.php +++ b/workflow/engine/classes/class.pmFunctions.php @@ -4210,6 +4210,53 @@ function PMFNewUser( return $response; } +/** + * + * @method + * + * Load the case information + * + * @name PMFCaseInformation + * @label PMF Case Information + * @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFCaseInformation.28.29 + * + * @param string(32) | $caseUid | Case ID | The case unique identifier, that is string of 32 hexadecimal characters. + * @param int | $delIndex = 0 | Delegation index of the case | The delegation index of the case thread task to get information (optional). + * @param int | $returnAppData = 0 | Include Application Data | Set as TRUE to get all the case data (optional). + * + * @return array | $response | Response + * @throws Exception + */ +function PMFCaseInformation($caseUid, $delIndex = 0, $returnAppData = false) +{ + if (empty($caseUid)) { + throw new Exception(G::LoadTranslation("ID_REQUIRED_FIELD") . " caseUid"); + } + $case = new Cases(); + $result = $case->loadCase($caseUid, $delIndex); + // Clean the APPLICATION's columns deprecated or without functionallity + unset($result['APP_TITLE']); + unset($result['APP_PARENT']); + unset($result['APP_PROC_STATUS']); + unset($result['APP_PROC_CODE']); + unset($result['APP_PARALLEL']); + unset($result['APP_PIN']); + unset($result['APP_DURATION']); + unset($result['APP_DELAY_DURATION']); + unset($result['APP_DRIVE_FOLDER_UID']); + unset($result['APP_ROUTING_DATA']); + // Only if this parameter is true we will to return this value + if (!$returnAppData) { + unset($result['APP_DATA']); + } + // Clean the additional columns deprecated or without functionallity + unset($result['TITLE']); + unset($result['DESCRIPTION']); + unset($result['DESCRIPTION']); + + return $result; +} + //Start - Private functions