PMCORE-1677 Dependent variable needs to search the data outside the grid if the prefix is @?
This commit is contained in:
committed by
Paula Quispe
parent
e5d42aa682
commit
d9cc26ca37
@@ -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
|
||||
|
||||
@@ -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, []);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user