Conflicts
This commit is contained in:
@@ -984,6 +984,64 @@ class PmDynaformTest extends TestCase
|
||||
// Compare the values
|
||||
$this->assertEquals($dynaformTitle, $dynaform->DYN_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test should verify the setDependentOptionsForDatetime() method, to
|
||||
* add the dependentOptions property to the datetime control.
|
||||
* @test
|
||||
* @covers PmDynaform::jsonr()
|
||||
* @covers PmDynaform::setDependentOptionsForDatetime()
|
||||
*/
|
||||
public function it_should_test_dependent_options_for_datetime_control()
|
||||
{
|
||||
$pathData = PATH_TRUNK . "/tests/resources/dynaform1.json";
|
||||
$data = file_get_contents($pathData);
|
||||
$json = json_decode($data);
|
||||
|
||||
//assert for not contain property: dependentOptions
|
||||
$result = json_decode(json_encode($json), JSON_OBJECT_AS_ARRAY);
|
||||
$fn = function($item) use(&$fn) {
|
||||
if (is_array($item)) {
|
||||
if (isset($item['type']) && $item['type'] === 'datetime') {
|
||||
$this->assertArrayNotHasKey('dependentOptions', $item);
|
||||
}
|
||||
array_map($fn, $item);
|
||||
}
|
||||
};
|
||||
array_map($fn, $result);
|
||||
|
||||
//assert new property: dependentOptions
|
||||
$dynaform = new PmDynaform();
|
||||
$dynaform->jsonr($json);
|
||||
$result = json_decode(json_encode($json), JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
$fn = function($item) use(&$fn) {
|
||||
if (is_array($item)) {
|
||||
if (isset($item['type']) && $item['type'] === 'datetime') {
|
||||
$this->assertArrayHasKey('dependentOptions', $item);
|
||||
$this->assertArrayHasKey('minDate', $item['dependentOptions']);
|
||||
$this->assertArrayHasKey('maxDate', $item['dependentOptions']);
|
||||
$this->assertArrayHasKey('defaultDate', $item['dependentOptions']);
|
||||
}
|
||||
array_map($fn, $item);
|
||||
}
|
||||
};
|
||||
array_map($fn, $result);
|
||||
|
||||
$dynaform = new PmDynaform();
|
||||
$reflection = new ReflectionClass($dynaform);
|
||||
$reflectionMethod = $reflection->getMethod('setDependentOptionsForDatetime');
|
||||
$reflectionMethod->setAccessible(true);
|
||||
|
||||
$a = new stdClass();
|
||||
$reflectionMethod->invokeArgs($dynaform, [&$a]);
|
||||
$this->assertInstanceOf('ReflectionMethod', $reflectionMethod);
|
||||
|
||||
$a = new stdClass();
|
||||
$a->type = 'suggest';
|
||||
$reflectionMethod->invokeArgs($dynaform, [&$a]);
|
||||
$this->assertInstanceOf('ReflectionMethod', $reflectionMethod);
|
||||
}
|
||||
}
|
||||
|
||||
// Dummy function used for the coverture
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\classes\PmFunctions;
|
||||
|
||||
use Faker\Factory;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Test the PMFTotalCalculation() function
|
||||
*
|
||||
* @link https://wiki.processmaker.com/3.1/ProcessMaker_Functions#executeQuery.28.29
|
||||
*/
|
||||
class PMFTotalCalculationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the sum
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_sum_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 2
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 5
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 3
|
||||
]
|
||||
];
|
||||
$field = "field2";
|
||||
$this->assertEquals(10, PMFTotalCalculation($grid, $field, 'sum'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the average
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_average_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 2
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 5
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 3
|
||||
]
|
||||
];
|
||||
$this->assertEquals(3.3333333333, PMFTotalCalculation($grid, 'field2', 'average'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the median
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_median_of_the_method()
|
||||
{
|
||||
$grid1 = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 2
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 5
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 3
|
||||
]
|
||||
];
|
||||
$grid2 = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 2
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 5
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 3
|
||||
],
|
||||
'4' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 8
|
||||
]
|
||||
];
|
||||
$this->assertEquals(3, PMFTotalCalculation($grid1, 'field2', 'median'));
|
||||
$this->assertEquals(4, PMFTotalCalculation($grid2, 'field2', 'median'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the minimum
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_minimum_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 5
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 2
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 3
|
||||
]
|
||||
];
|
||||
$this->assertEquals(2, PMFTotalCalculation($grid, 'field2', 'minimum'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the maximum
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_maximum_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 2
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 5
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 3
|
||||
]
|
||||
];
|
||||
$this->assertEquals(5, PMFTotalCalculation($grid, 'field2', 'maximum'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the standardDeviation
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_standardDeviation_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 25
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 40
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 10
|
||||
]
|
||||
];
|
||||
$this->assertEquals(12.2474487139, PMFTotalCalculation($grid, 'field2', 'standardDeviation'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the variance
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_variance_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 25
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 40
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 10
|
||||
]
|
||||
];
|
||||
$this->assertEquals(150, PMFTotalCalculation($grid, 'field2', 'variance'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the percentile
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_percentile_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 10
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 35
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 5
|
||||
]
|
||||
];
|
||||
$expectedArray = [
|
||||
"1" => 20,
|
||||
"2" => 70,
|
||||
"3" => 10,
|
||||
];
|
||||
$this->assertEquals($expectedArray, PMFTotalCalculation($grid, 'field2', 'percentile'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the count
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_count_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 25
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 40
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 10
|
||||
]
|
||||
];
|
||||
$this->assertEquals(3, PMFTotalCalculation($grid, 'field2', 'count'));
|
||||
}
|
||||
/**
|
||||
* This tests if the "PMFTotalCalculation" execute correctly the count distinct
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_count_distinct_of_the_method()
|
||||
{
|
||||
$grid = [
|
||||
'1' => [
|
||||
"field1" => "Value 1",
|
||||
"field2" => 20
|
||||
],
|
||||
'2' => [
|
||||
"field1" => "Value 2",
|
||||
"field2" => 20
|
||||
],
|
||||
'3' => [
|
||||
"field1" => "Value 3",
|
||||
"field2" => 10
|
||||
]
|
||||
];
|
||||
$this->assertEquals(2, PMFTotalCalculation($grid, 'field2', 'countDistinct'));
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use Tests\TestCase;
|
||||
|
||||
class ReportTablesTest extends TestCase
|
||||
{
|
||||
|
||||
use CreateTestSite;
|
||||
use DatabaseTransactions;
|
||||
|
||||
@@ -21,14 +22,12 @@ class ReportTablesTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->markTestIncomplete(""
|
||||
. "This test has started using the ./processmaker command, this "
|
||||
. "command requires the file 'paths_installed.php', that is, a "
|
||||
. "valid installation of processmaker.");
|
||||
$_SERVER["REQUEST_URI"] = "";
|
||||
config(['queue.default' => 'sync']);
|
||||
config(["system.workspace" => "test"]);
|
||||
$workspace = config("system.workspace");
|
||||
$this->createDBFile($workspace);
|
||||
$this->createConstantsOfConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,6 +38,33 @@ class ReportTablesTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create constants of connection to databases.
|
||||
*/
|
||||
private function createConstantsOfConnection()
|
||||
{
|
||||
$constants = [
|
||||
'DB_ADAPTER' => env('mysql'),
|
||||
'DB_HOST' => env('DB_HOST'),
|
||||
'DB_NAME' => env('DB_DATABASE'),
|
||||
'DB_USER' => env('DB_USERNAME'),
|
||||
'DB_PASS' => env('DB_PASSWORD'),
|
||||
'DB_RBAC_HOST' => env('DB_HOST'),
|
||||
'DB_RBAC_NAME' => env('DB_DATABASE'),
|
||||
'DB_RBAC_USER' => env('DB_USERNAME'),
|
||||
'DB_RBAC_PASS' => env('DB_PASSWORD'),
|
||||
'DB_REPORT_HOST' => env('DB_HOST'),
|
||||
'DB_REPORT_NAME' => env('DB_DATABASE'),
|
||||
'DB_REPORT_USER' => env('DB_USERNAME'),
|
||||
'DB_REPORT_PASS' => env('DB_PASSWORD'),
|
||||
];
|
||||
foreach ($constants as $key => $value) {
|
||||
if (!defined($key)) {
|
||||
define($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the "populateTable" function returns an array value if entered all parameters.
|
||||
* @test
|
||||
@@ -565,97 +591,6 @@ class ReportTablesTest extends TestCase
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mapping fields supported by report table.
|
||||
* @return array
|
||||
*/
|
||||
private function getMapFields()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'sFieldName' => 'var_Text1',
|
||||
'sType' => 'char'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_Textarea1',
|
||||
'sType' => 'text'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_Dropdown1',
|
||||
'sType' => 'char'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_Suggest1',
|
||||
'sType' => 'char'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_DateTime1',
|
||||
'sType' => 'date'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_String1',
|
||||
'sType' => 'char'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_Integer1',
|
||||
'sType' => 'number'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_Boolean1',
|
||||
'sType' => 'boolean'
|
||||
],
|
||||
[
|
||||
'sFieldName' => 'var_Array1',
|
||||
'sType' => 'array'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fields data by type supported.
|
||||
* @param array $types
|
||||
* @return array
|
||||
*/
|
||||
private function createFieldsByType($types = [])
|
||||
{
|
||||
$fields = [];
|
||||
$mapping = [];
|
||||
$faker = Faker\Factory::create();
|
||||
$date = $faker->dateTime();
|
||||
$mapFields = $this->getMapFields();
|
||||
foreach ($mapFields as $key => $value) {
|
||||
if (!in_array($value['sType'], $types)) {
|
||||
continue;
|
||||
}
|
||||
switch ($value['sType']) {
|
||||
case 'number':
|
||||
$mapping[] = $value;
|
||||
$fields[$value['sFieldName']] = (string) random_int(0, 100);
|
||||
break;
|
||||
case 'char':
|
||||
$mapping[] = $value;
|
||||
$fields[$value['sFieldName']] = G::generateUniqueID();
|
||||
break;
|
||||
case 'text':
|
||||
$mapping[] = $value;
|
||||
$fields[$value['sFieldName']] = G::generateUniqueID();
|
||||
break;
|
||||
case 'date':
|
||||
$mapping[] = $value;
|
||||
$fields[$value['sFieldName']] = $date->format('Y-m-d H:i:s');
|
||||
break;
|
||||
case 'boolean':
|
||||
$mapping[] = $value;
|
||||
$fields[$value['sFieldName']] = ['0' => 0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [
|
||||
'data' => $fields,
|
||||
'mapping' => $mapping
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data initial for test, the grid parameter is optional if you want
|
||||
* to create a grid type field.
|
||||
@@ -665,7 +600,7 @@ class ReportTablesTest extends TestCase
|
||||
* @param boolean $grid
|
||||
* @return object
|
||||
*/
|
||||
private function prepareData($tableName, $grid = null)
|
||||
private function prepareData($tableName, $grid = null, $structure = [])
|
||||
{
|
||||
$applicationNumber = Application::max('APP_NUMBER');
|
||||
if (is_null($applicationNumber)) {
|
||||
@@ -681,7 +616,10 @@ class ReportTablesTest extends TestCase
|
||||
$taskUid = G::generateUniqueID();
|
||||
$applicationUid = G::generateUniqueID();
|
||||
|
||||
$structure = $this->createFieldsByType(['number', 'char', 'text', 'date']);
|
||||
if (empty($structure)) {
|
||||
$structure = $this->getDataFromFile('structureReportTable.json');
|
||||
}
|
||||
|
||||
$fields = $structure['mapping'];
|
||||
$dataFields = $structure['data'];
|
||||
$appData = [
|
||||
@@ -753,4 +691,157 @@ class ReportTablesTest extends TestCase
|
||||
$result->application = $application;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the "populateTable" method is it filling with missing values into app_data.
|
||||
* @test
|
||||
* @covers ReportTables::populateTable
|
||||
*/
|
||||
public function it_should_populating_data_with_fields_missing_in_to_app_data()
|
||||
{
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'NORMAL';
|
||||
$fields = $result->fields;
|
||||
$proUid = $result->processUid;
|
||||
$grid = '';
|
||||
|
||||
$app = Application::where('APP_UID', '=', $result->applicationUid)->get()->first();
|
||||
$appData = unserialize($app->APP_DATA);
|
||||
unset($appData['var_Textarea1']);
|
||||
$appData = serialize($appData);
|
||||
Application::where('APP_UID', '=', $result->applicationUid)->update(['APP_DATA' => $appData]);
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
|
||||
|
||||
$expected = $result->dataFields;
|
||||
$expected['APP_UID'] = $result->applicationUid;
|
||||
$expected['APP_NUMBER'] = $result->applicationNumber;
|
||||
$expected['var_Textarea1'] = '';
|
||||
|
||||
$actual = (array) DB::table($tableName)
|
||||
->select()
|
||||
->first();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the "populateTable" method is it filling with arrays values.
|
||||
* @test
|
||||
* @covers ReportTables::populateTable
|
||||
*/
|
||||
public function it_should_populating_data_with_arrays_values()
|
||||
{
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'NORMAL';
|
||||
$fields = $result->fields;
|
||||
$proUid = $result->processUid;
|
||||
$grid = '';
|
||||
|
||||
$app = Application::where('APP_UID', '=', $result->applicationUid)->get()->first();
|
||||
$appData = unserialize($app->APP_DATA);
|
||||
$appData['var_Textarea1'] = [];
|
||||
$appData = serialize($appData);
|
||||
Application::where('APP_UID', '=', $result->applicationUid)->update(['APP_DATA' => $appData]);
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
|
||||
|
||||
$expected = $result->dataFields;
|
||||
$expected['APP_UID'] = $result->applicationUid;
|
||||
$expected['APP_NUMBER'] = $result->applicationNumber;
|
||||
$expected['var_Textarea1'] = '';
|
||||
|
||||
$actual = (array) DB::table($tableName)
|
||||
->select()
|
||||
->first();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the "populateTable" method is it filling with missing values into app_data for grids control.
|
||||
* parameters and type and grid are correct values.
|
||||
* @test
|
||||
* @covers ReportTables::populateTable
|
||||
*/
|
||||
public function it_should_populating_data_with_all_parameters_with_type_is_grid_fields_missing_in_to_app_data()
|
||||
{
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName, true);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'GRID';
|
||||
$fields = $result->fields;
|
||||
$proUid = $result->processUid;
|
||||
$grid = 'var_Grid1';
|
||||
|
||||
$app = Application::where('APP_UID', '=', $result->applicationUid)->get()->first();
|
||||
$appData = unserialize($app->APP_DATA);
|
||||
unset($appData['var_Grid1'][1]['var_Textarea1']);
|
||||
$appData = serialize($appData);
|
||||
Application::where('APP_UID', '=', $result->applicationUid)->update(['APP_DATA' => $appData]);
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
|
||||
|
||||
$indexRow = 1;
|
||||
$expected = $result->appData[$grid];
|
||||
foreach ($expected as &$row) {
|
||||
$row['APP_UID'] = $result->applicationUid;
|
||||
$row['APP_NUMBER'] = $result->applicationNumber;
|
||||
$row['ROW'] = (string) ($indexRow++);
|
||||
}
|
||||
$expected = array_values($expected);
|
||||
$expected[0]['var_Textarea1'] = '';
|
||||
|
||||
$actual = DB::table($tableName)
|
||||
->select()
|
||||
->get();
|
||||
$actual->transform(function ($item, $key) {
|
||||
return (array) $item;
|
||||
});
|
||||
$actual = $actual->toArray();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check an exception if the input parameters are wrong.
|
||||
* @test
|
||||
* @covers ReportTables::populateTable
|
||||
*/
|
||||
public function it_should_catch_an_exception()
|
||||
{
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName, true);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'GRID';
|
||||
$fields = $result->fields;
|
||||
$proUid = $result->processUid;
|
||||
$grid = 'var_Grid1';
|
||||
|
||||
//assert exception
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, null, $proUid, $grid);
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets data from a json file.
|
||||
* @param string $pathData
|
||||
* @return array
|
||||
*/
|
||||
private function getDataFromFile(string $pathData): array
|
||||
{
|
||||
$pathData = PATH_TRUNK . "tests/resources/{$pathData}";
|
||||
$data = file_get_contents($pathData);
|
||||
$result = json_decode($data, JSON_OBJECT_AS_ARRAY);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,32 @@
|
||||
namespace Tests\unit\workflow\engine\classes\model;
|
||||
|
||||
use AdditionalTables;
|
||||
use App\Jobs\GenerateReportTable;
|
||||
use Exception;
|
||||
use G;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use ProcessMaker\BusinessModel\ReportTable;
|
||||
use ProcessMaker\Model\AdditionalTables as AdditionalTablesModel;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\DbSource;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\Task;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdditionalTablesTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Set up method.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the creation of a PMTable.
|
||||
* @test
|
||||
@@ -198,6 +213,74 @@ class AdditionalTablesTest extends TestCase
|
||||
$this->assertContains($actual[0], $expected, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if populate report table is added to job queue.
|
||||
* @test
|
||||
* @covers \AdditionalTables::populateReportTable
|
||||
*/
|
||||
public function it_should_test_populate_report_table()
|
||||
{
|
||||
$proUid = factory(Process::class)->create()->PRO_UID;
|
||||
|
||||
$task = factory(Task::class)->create([
|
||||
'PRO_UID' => $proUid
|
||||
]);
|
||||
|
||||
//local connections
|
||||
$dbSource = factory(DbSource::class)->create([
|
||||
'PRO_UID' => $proUid,
|
||||
'DBS_SERVER' => env('DB_HOST'),
|
||||
'DBS_DATABASE_NAME' => env('DB_DATABASE'),
|
||||
'DBS_USERNAME' => env('DB_USERNAME'),
|
||||
'DBS_PASSWORD' => G::encrypt(env('DB_PASSWORD'), env('DB_DATABASE')) . "_2NnV3ujj3w",
|
||||
'DBS_PORT' => '3306',
|
||||
'DBS_CONNECTION_TYPE' => 'NORMAL'
|
||||
]);
|
||||
$additionalTable = factory(AdditionalTablesModel::class)->create([
|
||||
'PRO_UID' => $proUid,
|
||||
'DBS_UID' => $dbSource->DBS_UID,
|
||||
]);
|
||||
$tableName = $additionalTable->ADD_TAB_NAME;
|
||||
$name = $additionalTable->ADD_TAB_CLASS_NAME;
|
||||
$this->createSchema($dbSource->DBS_DATABASE_NAME, $tableName, $name, $dbSource->DBS_UID);
|
||||
|
||||
//external connection
|
||||
$dbSource = factory(DbSource::class)->create([
|
||||
'PRO_UID' => $proUid,
|
||||
'DBS_SERVER' => config('database.connections.testexternal.host'),
|
||||
'DBS_DATABASE_NAME' => config('database.connections.testexternal.database'),
|
||||
'DBS_USERNAME' => config('database.connections.testexternal.username'),
|
||||
'DBS_PASSWORD' => G::encrypt(config('database.connections.testexternal.password'), config('database.connections.testexternal.database')) . "_2NnV3ujj3w",
|
||||
'DBS_PORT' => '3306',
|
||||
'DBS_CONNECTION_TYPE' => 'NORMAL'
|
||||
]);
|
||||
$additionalTable = factory(AdditionalTablesModel::class)->create([
|
||||
'PRO_UID' => $proUid,
|
||||
'DBS_UID' => $dbSource->DBS_UID,
|
||||
]);
|
||||
$tableNameExternal = $additionalTable->ADD_TAB_NAME;
|
||||
$nameExternal = $additionalTable->ADD_TAB_CLASS_NAME;
|
||||
$this->createSchema($dbSource->DBS_DATABASE_NAME, $tableNameExternal, $nameExternal, $dbSource->DBS_UID);
|
||||
|
||||
$application = factory(Application::class)->create([
|
||||
'PRO_UID' => $proUid
|
||||
]);
|
||||
factory(Delegation::class)->create([
|
||||
'DEL_THREAD_STATUS' => 'CLOSED',
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
]);
|
||||
|
||||
//assertions
|
||||
Queue::fake();
|
||||
Queue::assertNothingPushed();
|
||||
|
||||
$additionalTables = new AdditionalTables();
|
||||
$additionalTables->populateReportTable($tableName, 'workflow', 'NORMAL', $proUid, '', $additionalTable->ADD_TAB_UID);
|
||||
|
||||
Queue::assertPushed(GenerateReportTable::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the content from template file.
|
||||
* @param string $pathData
|
||||
|
||||
@@ -188,4 +188,43 @@ class VariableTest extends TestCase
|
||||
$this->assertArrayHasKey('var_accepted_values', $res, "The result does not contains 'var_accepted_values' as key");
|
||||
$this->assertArrayHasKey('inp_doc_uid', $res, "The result does not contains 'inp_doc_uid' as key");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it return the variables by type related to the PRO_UID
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Variable::getVariablesByType()
|
||||
* @test
|
||||
*/
|
||||
public function it_list_variables_by_type_related_a_process()
|
||||
{
|
||||
$process = factory(Process::class)->create();
|
||||
$varType = 'integer';
|
||||
$varTypeId = 2;
|
||||
for ($x = 1; $x <= 5; $x++) {
|
||||
$processVar = factory(ProcessVariables::class)->states('foreign_keys')->create([
|
||||
'PRO_ID' => $process->PRO_ID,
|
||||
'PRJ_UID' => $process->PRO_UID,
|
||||
'VAR_FIELD_TYPE' => $varType,
|
||||
'VAR_FIELD_TYPE_ID' => $varTypeId,
|
||||
'VAR_NAME' => 'varTestName' . $x,
|
||||
]);
|
||||
}
|
||||
$variable = new Variable();
|
||||
// Get all results
|
||||
$res = $variable->getVariablesByType($process->PRO_UID, 2);
|
||||
$this->assertEquals(5, count($res));
|
||||
$res = head($res);
|
||||
$this->assertArrayHasKey('value', $res, "The result does not contains 'value' as key");
|
||||
// Get a specific start and limit
|
||||
$res = $variable->getVariablesByType($process->PRO_UID, 2, 0, 2);
|
||||
$this->assertNotEmpty($res);
|
||||
$this->assertEquals(2, count($res));
|
||||
// Get a specific search
|
||||
$res = $variable->getVariablesByType($process->PRO_UID, 2, 0, 4, 'varTest');
|
||||
$this->assertNotEmpty($res);
|
||||
$this->assertEquals(4, count($res));
|
||||
// When the search does not match
|
||||
$res = $variable->getVariablesByType($process->PRO_UID, 2, null, null, 'other');
|
||||
$this->assertEmpty($res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace ProcessMaker\Core;
|
||||
|
||||
use App\Jobs\Email;
|
||||
use Tests\TestCase;
|
||||
|
||||
class JobsManagerTest extends TestCase
|
||||
|
||||
@@ -70,4 +70,41 @@ class ProcessVariablesTest extends TestCase
|
||||
$result = ProcessVariables::getVariables($process->PRO_ID);
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it return the variables by type related to the PRO_ID
|
||||
*
|
||||
* @covers \ProcessMaker\Model\ProcessVariables::getVariablesByType()
|
||||
* @test
|
||||
*/
|
||||
public function it_list_variables_type_by_process()
|
||||
{
|
||||
$process = factory(Process::class)->create();
|
||||
$varType = 'integer';
|
||||
$varTypeId = 2;
|
||||
for ($x = 1; $x <= 5; $x++) {
|
||||
$processVar = factory(ProcessVariables::class)->states('foreign_keys')->create([
|
||||
'PRO_ID' => $process->PRO_ID,
|
||||
'PRJ_UID' => $process->PRO_UID,
|
||||
'VAR_FIELD_TYPE' => $varType,
|
||||
'VAR_FIELD_TYPE_ID' => $varTypeId,
|
||||
'VAR_NAME' => 'varTestName' . $x,
|
||||
]);
|
||||
}
|
||||
|
||||
$res = ProcessVariables::getVariablesByType($processVar->PRO_ID, 2, null, null, null);
|
||||
$this->assertNotEmpty($res);
|
||||
$this->assertEquals(5, count($res));
|
||||
// Get a specific start and limit
|
||||
$res = ProcessVariables::getVariablesByType($process->PRO_ID, 2, 0, 2);
|
||||
$this->assertNotEmpty($res);
|
||||
$this->assertEquals(2, count($res));
|
||||
// Get a specific search
|
||||
$res = ProcessVariables::getVariablesByType($process->PRO_ID, 2, 0, 4, 'varTest');
|
||||
$this->assertNotEmpty($res);
|
||||
$this->assertEquals(4, count($res));
|
||||
// When the search does not match
|
||||
$res = ProcessVariables::getVariablesByType($process->PRO_ID, 2, null, null, 'other');
|
||||
$this->assertEmpty($res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user