Merged in feature/PMC-799 (pull request #6914)

PMC-799

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Paula Quispe
2019-07-17 12:13:23 +00:00
committed by Julio Cesar Laura Avendaño
2 changed files with 295 additions and 0 deletions

View File

@@ -532,4 +532,271 @@ class PmDynaformTest extends TestCase
]
];
}
/**
* It tests that the json file is getting the defined values when the grid has one undefined control
*
* @test
*/
public function it_should_add_the_correct_fields_with_a_single_undefined_control()
{
//Creates the PmDynaform object
$pmDynaform = new PmDynaform();
//A json that contains the text control data and columns
$jsonData = (object)(
[
"data" => (object)([
"1" => [
["value" => "textControl1", "label" => "textControl1"],
["value" => "textControl2", "label" => "textControl2"],
["value" => "", "label" => ""]
]
]),
"columns" => (object)([
0 => (object)([
"id" => "text0000000001",
"name" => "text0000000001",
]),
1 => (object)([
"id" => "textarea0000000001",
"name" => "textarea0000000001",
]),
2 => (object)([
"id" => "text0000000002",
"name" => "text0000000002",
])
])
]
);
// An array that contains the variables stored on the App Data
$appData = [
"1" => [
"text0000000001" => "",
"text0000000001_label" => "",
"textarea0000000001" => "",
"textarea0000000001_label" => ""
]
];
//Calls the setDataSchema method
$resultText = $pmDynaform->setDataSchema($jsonData, $appData);
//This assert the result is null
$this->assertNull($resultText);
//Assert the 'dataSchema' field was added
$this->assertObjectHasAttribute('dataSchema', $jsonData);
//It asserts the first control is defined
$this->assertTrue($jsonData->dataSchema['1'][0]['defined']);
//It asserts the second control is defined
$this->assertTrue($jsonData->dataSchema['1'][1]['defined']);
//It asserts the second control is undefined
$this->assertFalse($jsonData->dataSchema['1'][2]['defined']);
}
/**
* It tests that the json file is getting the defined values when the grid has more than one undefined control
*
* @test
*/
public function it_should_add_the_correct_fields_with_more_than_one_undefined_control()
{
//Creates the PmDynaform object
$pmDynaform = new PmDynaform();
//A json that contains the text control data and columns
$jsonData = (object)(
[
"data" => (object)([
"1" => [
["value" => "textControl1", "label" => "textControl1"],
["value" => "textAreaControl2", "label" => "textAreaControl2"],
["value" => "dropdowncontrol1", "label" => "dropdowncontrol1"],
["value" => "", "label" => ""],
["value" => "", "label" => ""]
]
]),
"columns" => (object)([
0 => (object)([
"id" => "text0000000001",
"name" => "text0000000001",
]),
1 => (object)([
"id" => "textarea0000000001",
"name" => "textarea0000000001",
]),
2 => (object)([
"id" => "dropdown0000000001",
"name" => "dropdown0000000001",
]),
3 => (object)([
"id" => "text0000000002",
"name" => "text0000000002",
]),
4 => (object)([
"id" => "text0000000003",
"name" => "text0000000003",
])
])
]
);
// An array that contains the variables stored on the App Data
$appData = [
"1" => [
"text0000000001" => "",
"text0000000001_label" => "",
"textarea0000000001" => "",
"textarea0000000001_label" => "",
"dropdown0000000001" => "",
"dropdown0000000001_label" => ""
]
];
//Calls the setDataSchema method
$resultText = $pmDynaform->setDataSchema($jsonData, $appData);
//This assert the result is null
$this->assertNull($resultText);
//Assert the 'dataSchema' field was added
$this->assertObjectHasAttribute('dataSchema', $jsonData);
//It asserts the first control is defined
$this->assertTrue($jsonData->dataSchema['1'][0]['defined']);
//It asserts the second control is defined
$this->assertTrue($jsonData->dataSchema['1'][1]['defined']);
//It asserts the third control is defined
$this->assertTrue($jsonData->dataSchema['1'][2]['defined']);
//It asserts the fourth control is undefined
$this->assertFalse($jsonData->dataSchema['1'][3]['defined']);
//It asserts the fifth control is undefined
$this->assertFalse($jsonData->dataSchema['1'][4]['defined']);
}
/**
* It tests that the json file is getting the defined and undefined values when the grid has more than one row
*
* @test
*/
public function it_should_add_the_correct_fields_with_more_than_one_rows()
{
//Creates the PmDynaform object
$pmDynaform = new PmDynaform();
//A json that contains the text control data and columns
$jsonData = (object)(
[
"data" => (object)([
"1" => [
["value" => "textControl1", "label" => "textControl1"],
["value" => "textAreaControl2", "label" => "textAreaControl2"],
["value" => "dropdowncontrol1", "label" => "dropdowncontrol1"],
["value" => "", "label" => ""],
["value" => "", "label" => ""]
],
"2" => [
["value" => "textControl1", "label" => "textControl1"],
["value" => "textAreaControl2", "label" => "textAreaControl2"],
["value" => "dropdowncontrol1", "label" => "dropdowncontrol1"],
["value" => "", "label" => ""],
["value" => "", "label" => ""]
],
"3" => [
["value" => "textControl1", "label" => "textControl1"],
["value" => "textAreaControl2", "label" => "textAreaControl2"],
["value" => "dropdowncontrol1", "label" => "dropdowncontrol1"],
["value" => "", "label" => ""],
["value" => "", "label" => ""]
]
]),
"columns" => (object)([
0 => (object)([
"id" => "text0000000001",
"name" => "text0000000001",
]),
1 => (object)([
"id" => "textarea0000000001",
"name" => "textarea0000000001",
]),
2 => (object)([
"id" => "dropdown0000000001",
"name" => "dropdown0000000001",
]),
3 => (object)([
"id" => "text0000000002",
"name" => "text0000000002",
]),
4 => (object)([
"id" => "text0000000003",
"name" => "text0000000003",
])
])
]
);
// An array that contains the variables stored on the App Data
$appData = [
"1" => [
"text0000000001" => "",
"text0000000001_label" => "",
"textarea0000000001" => "",
"textarea0000000001_label" => "",
"dropdown0000000001" => "",
"dropdown0000000001_label" => ""
],
"2" => [
"text0000000001" => "",
"text0000000001_label" => "",
"textarea0000000001" => "",
"textarea0000000001_label" => "",
"dropdown0000000001" => "",
"dropdown0000000001_label" => ""
],
"3" => [
"text0000000001" => "",
"text0000000001_label" => "",
"textarea0000000001" => "",
"textarea0000000001_label" => "",
"dropdown0000000001" => "",
"dropdown0000000001_label" => ""
]
];
//Calls the setDataSchema method
$resultText = $pmDynaform->setDataSchema($jsonData, $appData);
//This assert the result is null
$this->assertNull($resultText);
//Assert the 'dataSchema' field was added
$this->assertObjectHasAttribute('dataSchema', $jsonData);
foreach ($jsonData->dataSchema as $key => $value) {
//It asserts the first control is defined
$this->assertTrue($jsonData->dataSchema[$key][0]['defined']);
//It asserts the second control is defined
$this->assertTrue($jsonData->dataSchema[$key][1]['defined']);
//It asserts the third control is defined
$this->assertTrue($jsonData->dataSchema[$key][2]['defined']);
//It asserts the fourth control is undefined
$this->assertFalse($jsonData->dataSchema[$key][3]['defined']);
//It asserts the fifth control is undefined
$this->assertFalse($jsonData->dataSchema[$key][4]['defined']);
}
}
}

View File

@@ -2410,4 +2410,32 @@ class PmDynaform
}
return $message;
}
/**
* This adds a new definition on the json dynaform
* @param json $json
*
* @link https://wiki.processmaker.com/3.0/Grid_Control
* @see workflow/engine/classes/PmDynaform->jsonr
*/
public function setDataSchema($json, $appDataVariables)
{
foreach ($json->data as $key => $value) {
$columnsData = [];
foreach ($json->columns as $keyData => $valueData) {
foreach ($appDataVariables as $keyAppData => $valueAppData) {
if (array_key_exists($valueData->id, $valueAppData) || array_key_exists($valueData->id . "_label",
$valueAppData) || array_key_exists($valueData->name,
$valueAppData) || array_key_exists($valueData->name . "_label", $valueAppData)) {
array_push($columnsData, ["defined" => true]);
break;
} else {
array_push($columnsData, ["defined" => false]);
break;
}
}
}
$json->dataSchema[$key] = $columnsData;
}
}
}