Merged in feature/PMCORE-3590 (pull request #8321)

PMCORE-3590

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Paula Quispe
2021-12-13 22:29:21 +00:00
committed by Julio Cesar Laura Avendaño
3 changed files with 187 additions and 1 deletions

View File

@@ -0,0 +1,132 @@
<?php
namespace Tests\unit\workflow\engine\classes\PmFunctions;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use RBAC;
use Tests\TestCase;
/**
* Test the PMFCaseInformation() function
*
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFCaseInformation.28.29
*/
class PMFCaseInformation extends TestCase
{
use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/**
* It tests the PMFCaseInformation() function with the default parameters
*
* @test
*/
public function it_should_test_this_pmfunction_default_parameters()
{
$table = factory(Application::class)->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);
}
}

View File

@@ -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);

View File

@@ -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