PMCORE-1677 Dependent variable needs to search the data outside the grid if the prefix is @?

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-06-19 11:49:18 -04:00
committed by Paula Quispe
parent e5d42aa682
commit d9cc26ca37
6 changed files with 801 additions and 50 deletions

View File

@@ -0,0 +1,444 @@
{
"name": "f1",
"description": "",
"items": [
{
"type": "form",
"variable": "",
"var_uid": "",
"dataType": "",
"id": "8463235965ee964cd21d5d5065152425",
"name": "f1",
"description": "",
"mode": "edit",
"script": "",
"language": "en",
"externalLibs": "",
"printable": false,
"items": [
[
{
"type": "title",
"id": "title0000000001",
"label": "Variables reference on grids",
"ariaLabel": "",
"colSpan": 12
}
],
[
{
"type": "dropdown",
"variable": "stateDropdown",
"var_uid": "6433597845eea6b2ad10097077910842",
"dataType": "string",
"protectedValue": false,
"id": "stateDropdown",
"name": "stateDropdown",
"label": "State Dropdown",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IC_UID, IC_NAME FROM ISO_COUNTRY",
"memoryCache": false,
"dataVariable": "",
"options": [],
"var_name": "stateDropdown",
"colSpan": 12
}
],
[
{
"type": "dropdown",
"variable": "countryDropdown",
"var_uid": "8461594435ee964da8652b7084948416",
"dataType": "string",
"protectedValue": false,
"id": "countryDropdown",
"name": "countryDropdown",
"label": "Country Dropdown",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IC_UID, IC_NAME FROM ISO_COUNTRY",
"memoryCache": false,
"dataVariable": "",
"options": [],
"var_name": "countryDropdown",
"colSpan": 4
},
{
"type": "grid",
"variable": "gridVar003",
"var_uid": "6174086855ee964da934c06026331273",
"dataType": "grid",
"protectedValue": false,
"id": "gridVar003",
"name": "gridVar003",
"label": "GRID1",
"hint": "",
"required": false,
"requiredFieldErrorMessage": "",
"columns": [
{
"type": "dropdown",
"variable": "",
"var_uid": "",
"dataType": "",
"protectedValue": false,
"id": "stateDropdown",
"name": "stateDropdown",
"label": "State use form",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IS_UID, IS_NAME FROM ISO_SUBDIVISION \nWHERE IC_UID = @?countryDropdown ORDER BY IS_NAME",
"memoryCache": false,
"dataVariable": "",
"options": [],
"columnWidth": "25",
"width": 100,
"title": "State use form",
"var_name": "gridVar003",
"gridName": "gridVar003"
},
{
"type": "dropdown",
"variable": "",
"var_uid": "",
"dataType": "",
"protectedValue": false,
"id": "countryGrid",
"name": "countryGrid",
"label": "country",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IC_UID, IC_NAME FROM ISO_COUNTRY",
"memoryCache": false,
"dataVariable": "",
"options": [],
"columnWidth": "25",
"width": 100,
"title": "country"
},
{
"type": "dropdown",
"variable": "",
"var_uid": "",
"dataType": "",
"protectedValue": false,
"id": "dropdown0000000003",
"name": "dropdown0000000003",
"label": "Country Grid",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IS_UID, IS_NAME FROM ISO_SUBDIVISION \nWHERE IC_UID = @@countryGrid ORDER BY IS_NAME",
"memoryCache": false,
"dataVariable": "",
"options": [],
"columnWidth": "25",
"width": 100,
"title": "Country Grid"
}
],
"data": [],
"mode": "parent",
"layout": "responsive",
"pageSize": "0",
"addRow": true,
"deleteRow": true,
"title": "GRID1",
"colSpan": 8
}
],
[
{
"type": "label",
"id": "label0000000002",
"label": "En este segundo dropdown la variable \"stateDropdown\" tiene el mismo ID que en el primer grid. Cuando tienen el mismo ID el segundo dropdown no carga sus opciones\n",
"ariaLabel": "",
"colSpan": 12
}
],
[
{
"type": "dropdown",
"variable": "countryDropdown1",
"var_uid": "3870420235ee964da9d9205006775679",
"dataType": "string",
"protectedValue": false,
"id": "countryDropdown1",
"name": "countryDropdown1",
"label": "Country Dropdown 1",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IC_UID, IC_NAME FROM ISO_COUNTRY",
"memoryCache": false,
"dataVariable": "",
"options": [],
"var_name": "countryDropdown1",
"colSpan": 4
},
{
"type": "grid",
"variable": "gridVar004",
"var_uid": "5972116805ee964daa950e7067922526",
"dataType": "grid",
"protectedValue": false,
"id": "gridVar004",
"name": "gridVar004",
"label": "GRID2",
"hint": "",
"required": false,
"requiredFieldErrorMessage": "",
"columns": [
{
"type": "dropdown",
"variable": "",
"var_uid": "",
"dataType": "",
"protectedValue": false,
"id": "stateDropdown",
"name": "stateDropdown",
"label": "State use form",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IS_UID, IS_NAME FROM ISO_SUBDIVISION \nWHERE IC_UID = @@countryDropdown1 ORDER BY IS_NAME",
"memoryCache": false,
"dataVariable": "",
"options": [],
"columnWidth": "25",
"width": 100,
"title": "State use form",
"var_name": "gridVar004"
},
{
"type": "dropdown",
"variable": "",
"var_uid": "",
"dataType": "",
"protectedValue": false,
"id": "countryGrid",
"name": "countryGrid",
"label": "country",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IC_UID, IC_NAME FROM ISO_COUNTRY",
"memoryCache": false,
"dataVariable": "",
"options": [],
"columnWidth": "25",
"width": 100,
"title": "country"
},
{
"type": "dropdown",
"variable": "",
"var_uid": "",
"dataType": "",
"protectedValue": false,
"id": "dropdown0000000004",
"name": "dropdown0000000004",
"label": "Country Grid",
"tabIndex": "",
"defaultValue": "",
"placeholder": "",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IS_UID, IS_NAME FROM ISO_SUBDIVISION \nWHERE IC_UID = @@countryGrid ORDER BY IS_NAME",
"memoryCache": false,
"dataVariable": "",
"options": [],
"columnWidth": "25",
"width": 100,
"title": "Country Grid"
}
],
"data": [],
"mode": "parent",
"layout": "responsive",
"pageSize": "0",
"addRow": true,
"deleteRow": true,
"title": "GRID2",
"colSpan": 8
}
],
[
{
"type": "submit",
"id": "submit0000000001",
"name": "submit0000000001",
"label": "submit_1",
"tabIndex": "",
"ariaLabel": "",
"colSpan": 12
}
]
],
"variables": [
{
"var_uid": "6433597845eea6b2ad10097077910842",
"prj_uid": "3973270015ee964bd20e167047282910",
"var_name": "stateDropdown",
"var_field_type": "string",
"var_field_size": 10,
"var_label": "string",
"var_dbconnection": "workflow",
"var_dbconnection_label": "PM Database",
"var_sql": "",
"var_null": 0,
"var_default": "",
"var_accepted_values": "[]",
"inp_doc_uid": ""
},
{
"var_uid": "8461594435ee964da8652b7084948416",
"prj_uid": "3973270015ee964bd20e167047282910",
"var_name": "countryDropdown",
"var_field_type": "string",
"var_field_size": 10,
"var_label": "string",
"var_dbconnection": "workflow",
"var_dbconnection_label": "PM Database",
"var_sql": "",
"var_null": 0,
"var_default": "",
"var_accepted_values": [],
"inp_doc_uid": "",
"var_uid_old": "4356061615edff028cae968013552938",
"var_name_old": "countryDropdown",
"prj_uid_old": "4922885715edfecb76f0024086363079"
},
{
"var_uid": "6174086855ee964da934c06026331273",
"prj_uid": "3973270015ee964bd20e167047282910",
"var_name": "gridVar003",
"var_field_type": "grid",
"var_field_size": 10,
"var_label": "grid",
"var_dbconnection": "workflow",
"var_dbconnection_label": "PM Database",
"var_sql": "",
"var_null": 0,
"var_default": "",
"var_accepted_values": [],
"inp_doc_uid": "",
"var_uid_old": "4763913505ee04a4acfac28032288647",
"var_name_old": "gridVar003",
"prj_uid_old": "4922885715edfecb76f0024086363079"
},
{
"var_uid": "3870420235ee964da9d9205006775679",
"prj_uid": "3973270015ee964bd20e167047282910",
"var_name": "countryDropdown1",
"var_field_type": "string",
"var_field_size": 10,
"var_label": "string",
"var_dbconnection": "workflow",
"var_dbconnection_label": "PM Database",
"var_sql": "",
"var_null": 0,
"var_default": "",
"var_accepted_values": [],
"inp_doc_uid": "",
"var_uid_old": "5743244195ee04b6c466484086183124",
"var_name_old": "countryDropdown1",
"prj_uid_old": "4922885715edfecb76f0024086363079"
},
{
"var_uid": "5972116805ee964daa950e7067922526",
"prj_uid": "3973270015ee964bd20e167047282910",
"var_name": "gridVar004",
"var_field_type": "grid",
"var_field_size": 10,
"var_label": "grid",
"var_dbconnection": "workflow",
"var_dbconnection_label": "PM Database",
"var_sql": "",
"var_null": 0,
"var_default": "",
"var_accepted_values": [],
"inp_doc_uid": "",
"var_uid_old": "8181709185ee04b0c2f8502096315574",
"var_name_old": "gridVar004",
"prj_uid_old": "4922885715edfecb76f0024086363079"
}
]
}
]
}

View File

@@ -0,0 +1,34 @@
{
"type": "dropdown",
"variable": "",
"var_uid": "",
"dataType": "",
"protectedValue": false,
"id": "stateDropdown",
"name": "stateDropdown",
"label": "State use form",
"tabIndex": "",
"defaultValue": "BO",
"placeholder": "BO",
"hint": "",
"ariaLabel": "",
"required": false,
"requiredFieldErrorMessage": "",
"mode": "parent",
"datasource": "database",
"dbConnection": "workflow",
"dbConnectionLabel": "PM Database",
"sql": "SELECT IS_UID, IS_NAME FROM ISO_SUBDIVISION \nWHERE IC_UID = @?countryDropdown ORDER BY IS_NAME",
"memoryCache": false,
"dataVariable": "",
"options": [
{
"value": "val1",
"label": "val1"
}
],
"columnWidth": "25",
"width": 100,
"title": "State use form",
"var_name": "gridVar003"
}

View File

@@ -13,15 +13,13 @@ use Tests\TestCase;
*/
class PmDynaformTest extends TestCase
{
use DatabaseTransactions;
/**
* Constructor of the class.
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function __construct($name = null, array $data = [], $dataName = '')
protected function setUp()
{
parent::__construct($name, $data, $dataName);
parent::setUp();
$_SERVER["REQUEST_URI"] = "";
if (!defined("DB_ADAPTER")) {
define("DB_ADAPTER", "mysql");
@@ -38,15 +36,7 @@ class PmDynaformTest extends TestCase
if (!defined("DB_PASS")) {
define("DB_PASS", env('DB_PASSWORD'));
}
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
parent::setUp();
Dynaform::truncate();
}
/**
@@ -1042,6 +1032,156 @@ class PmDynaformTest extends TestCase
$reflectionMethod->invokeArgs($dynaform, [&$a]);
$this->assertInstanceOf('ReflectionMethod', $reflectionMethod);
}
/**
* This verify method getValuesDependentFields.
* @test
* @covers PmDynaform::jsonr()
* @covers PmDynaform::getValuesDependentFields()
*/
public function it_should_test_get_values_dependent_fields()
{
$pathData = PATH_TRUNK . "/tests/resources/dynaform2.json";
$data = file_get_contents($pathData);
$json = json_decode($data);
$pathData2 = PATH_TRUNK . "/tests/resources/fieldDynaform.json";
$data2 = file_get_contents($pathData2);
$json2 = json_decode($data2);
$dynaform = new PmDynaform();
$dynaform->record = [
'DYN_CONTENT' => $data
];
$dynaform->fields = [
'APP_DATA' => [
'stateDropdown' => 'stateDropdown'
]
];
$reflection = new ReflectionClass($dynaform);
$reflectionMethod = $reflection->getMethod('getValuesDependentFields');
$reflectionMethod->setAccessible(true);
$result = $reflectionMethod->invokeArgs($dynaform, [&$json2]);
$this->assertArrayHasKey('countryDropdown', $result);
}
/**
* This verify method searchField.
* @test
* @covers PmDynaform::jsonr()
* @covers PmDynaform::searchField()
*/
public function it_should_test_search_field()
{
$pathData = PATH_TRUNK . "/tests/resources/dynaform2.json";
$data = file_get_contents($pathData);
$json = json_decode($data);
$pathData2 = PATH_TRUNK . "/tests/resources/fieldDynaform.json";
$data2 = file_get_contents($pathData2);
$json2 = json_decode($data2);
$dynaform = factory(Dynaform::class)->create([
'DYN_CONTENT' => $data
]);
factory(Dynaform::class)->create([
'DYN_CONTENT' => $data,
'PRO_UID' => $dynaform->PRO_UID
]);
$dynUid = $dynaform->DYN_UID;
$fieldId = 'stateDropdown';
$proUid = '';
$and = [];
$dynaform = new PmDynaform();
$result = $dynaform->searchField($dynUid, $fieldId, $proUid, $and);
$this->assertObjectHasAttribute('id', $result);
$this->assertEquals($result->id, 'stateDropdown');
}
/**
* This verify method replaceDataField.
* @test
* @covers PmDynaform::jsonr()
* @covers PmDynaform::replaceDataField()
*/
public function it_should_test_replace_data_field()
{
$sql = "SELECT IS_UID, IS_NAME FROM ISO_SUBDIVISION WHERE IC_UID = '@?countryDropdown' ORDER BY IS_NAME";
$data = [
'countryDropdown' => 'BO'
];
$dynaform = new PmDynaform();
$reflection = new ReflectionClass($dynaform);
$reflectionMethod = $reflection->getMethod('replaceDataField');
$reflectionMethod->setAccessible(true);
$result = $reflectionMethod->invokeArgs($dynaform, [&$sql, $data]);
$expected = "SELECT IS_UID, IS_NAME FROM ISO_SUBDIVISION WHERE IC_UID = 'BO' ORDER BY IS_NAME";
$this->assertEquals($expected, $result);
}
/**
* This verify method completeAdditionalHelpInformationOnControls.
* @test
* @covers PmDynaform::jsonr()
* @covers PmDynaform::completeAdditionalHelpInformationOnControls()
*/
public function it_should_test_complete_additional_help_information_on_controls()
{
$pathData = PATH_TRUNK . "/tests/resources/dynaform2.json";
$data = file_get_contents($pathData);
$json = json_decode($data);
$dynaform = new PmDynaform();
$reflection = new ReflectionClass($dynaform);
$reflectionMethod = $reflection->getMethod('completeAdditionalHelpInformationOnControls');
$reflectionMethod->setAccessible(true);
$reflectionMethod->invokeArgs($dynaform, [&$json]);
$this->assertInstanceOf('ReflectionMethod', $reflectionMethod);
}
/**
* This verify method jsonsf.
* @test
* @covers PmDynaform::jsonr()
* @covers PmDynaform::jsonsf()
*/
public function it_should_test_jsonsf()
{
$pathData = PATH_TRUNK . "/tests/resources/dynaform2.json";
$data = file_get_contents($pathData);
$json = json_decode($data);
$pathData2 = PATH_TRUNK . "/tests/resources/fieldDynaform.json";
$data2 = file_get_contents($pathData2);
$json2 = json_decode($data2);
$dynaform = factory(Dynaform::class)->create([
'DYN_CONTENT' => $data
]);
factory(Dynaform::class)->create([
'DYN_CONTENT' => $data,
'PRO_UID' => $dynaform->PRO_UID
]);
$id = 'stateDropdown';
$for = 'id';
$and = ['gridName' => 'gridVar003'];
$dynaform = new PmDynaform();
$reflection = new ReflectionClass($dynaform);
$reflectionMethod = $reflection->getMethod('jsonsf');
$reflectionMethod->setAccessible(true);
$result = $reflectionMethod->invokeArgs($dynaform, [&$json, $id, $for, $and]);
$this->assertObjectHasAttribute('id', $result);
$this->assertEquals($result->id, 'stateDropdown');
}
}
// Dummy function used for the coverture

View File

@@ -1,8 +1,12 @@
<?php
namespace ProcessMaker\BusinessModel;
use Exception;
use G;
use ProcessMaker\BusinessModel\Variable;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Dynaform;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\ProcessVariables;
use Tests\TestCase;
@@ -12,6 +16,7 @@ use Tests\TestCase;
*/
class VariableTest extends TestCase
{
/**
* Test it create variables related to the process
*
@@ -23,10 +28,9 @@ class VariableTest extends TestCase
$process = factory(Process::class)->create();
factory(ProcessVariables::class)->create([
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]
);
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]);
$properties = [
'VAR_UID' => G::generateUniqueID(),
'VAR_NAME' => 'var_test',
@@ -69,10 +73,9 @@ class VariableTest extends TestCase
{
$process = factory(Process::class)->create();
factory(ProcessVariables::class)->create([
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]
);
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]);
$properties = [
'VAR_UID' => G::generateUniqueID(),
'VAR_NAME' => '',
@@ -101,10 +104,9 @@ class VariableTest extends TestCase
{
$process = factory(Process::class)->create();
factory(ProcessVariables::class)->create([
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]
);
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]);
$properties = [
'VAR_UID' => G::generateUniqueID(),
'VAR_NAME' => 'var_test',
@@ -133,10 +135,9 @@ class VariableTest extends TestCase
{
$process = factory(Process::class)->create();
factory(ProcessVariables::class)->create([
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]
);
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]);
$properties = [
'VAR_UID' => G::generateUniqueID(),
'VAR_NAME' => 'var_test',
@@ -166,10 +167,9 @@ class VariableTest extends TestCase
$process = factory(Process::class)->create();
factory(ProcessVariables::class)->create([
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]
);
'PRJ_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
]);
$variable = new Variable();
$res = $variable->getVariables($process->PRO_UID);
$this->assertNotEmpty($res);
@@ -227,4 +227,49 @@ class VariableTest extends TestCase
$res = $variable->getVariablesByType($process->PRO_UID, 2, null, null, 'other');
$this->assertEmpty($res);
}
/**
* This verify method executeSqlControl.
* @test
* @covers \ProcessMaker\BusinessModel\Variable::executeSqlControl()
*/
public function it_should_test_execute_sql_control()
{
$pathData = PATH_TRUNK . "/tests/resources/dynaform2.json";
$data = file_get_contents($pathData);
$json = json_decode($data);
$dynaform = factory(Dynaform::class)->create([
'DYN_CONTENT' => $data
]);
$application = factory(Application::class)->create();
$proUid = '';
$params = [
'app_uid' => $application->APP_UID,
'countryDropdown1' => 'BO',
'dyn_uid' => $dynaform->DYN_UID,
'field_id' => 'stateDropdown',
'grid_name' => 'gridVar004',
];
$_SERVER["REQUEST_URI"] = '';
$variable = new Variable();
$result = $variable->executeSqlControl($proUid, $params);
$this->assertNotEmpty($result);
}
/**
* This verify method executeSqlControl try exception.
* @test
* @covers \ProcessMaker\BusinessModel\Variable::executeSqlControl()
*/
public function it_should_test_execute_sql_control_with_exception()
{
//assert
$this->expectException(Exception::class);
$variable = new Variable();
$result = $variable->executeSqlControl(null, []);
}
}