diff --git a/database/factories/BpmnProjectFactory.php b/database/factories/BpmnProjectFactory.php new file mode 100644 index 000000000..16cbf5722 --- /dev/null +++ b/database/factories/BpmnProjectFactory.php @@ -0,0 +1,20 @@ +define(\ProcessMaker\Model\BpmnProject::class, function (Faker $faker) { + return [ + 'PRJ_UID' => G::generateUniqueID(), + 'PRJ_NAME' => '', + 'PRJ_DESCRIPTION' => $faker->text, + 'PRJ_EXPRESION_LANGUAGE' => '', + 'PRJ_TYPE_LANGUAGE' => '', + 'PRJ_EXPORTER' => '', + 'PRJ_EXPORTER_VERSION' => '', + 'PRJ_CREATE_DATE' => new \Carbon\Carbon(2030, 1, 1), + 'PRJ_UPDATE_DATE' => new \Carbon\Carbon(2030, 1, 1), + 'PRJ_AUTHOR' => '', + 'PRJ_AUTHOR_VERSION' => '', + 'PRJ_ORIGINAL_SOURCE' => '', + ]; +}); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 895c470da..f45a6b907 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -35,6 +35,10 @@ define('PMTABLE_KEY', 'pmtable'); define('PATH_WORKFLOW_MYSQL_DATA', PATH_TRUNK . '/workflow/engine/data/mysql/'); define('PATH_RBAC_MYSQL_DATA', PATH_TRUNK . '/rbac/engine/data/mysql/'); define('PATH_LANGUAGECONT', PATH_DATA . '/META-INF/'); +define('PM_NEW_PROCESS_SAVE', 1006); +define('PATH_DATA_SITE', PATH_DATA . 'sites/' . SYS_SYS . '/'); +define("PATH_DATA_MAILTEMPLATES", PATH_DATA_SITE . "mailTemplates/"); +define('PATH_DATA_PUBLIC', PATH_DATA_SITE . 'public/'); //timezone $_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int) (env('MAIN_SYSTEM_UTC_TIME_ZONE', 'workflow')) == 1; diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Importer/ImporterTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Importer/ImporterTest.php new file mode 100644 index 000000000..be9c6f569 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Importer/ImporterTest.php @@ -0,0 +1,538 @@ +getProperty($property); + $reflection_property->setAccessible(true); + $reflection_property->setValue($object, $value); + } + + /** + * Tests the import method when importing a process with a new uid + * + * @test + */ + public function it_should_test_the_import_method_when_importing_a_process_with_a_new_uid() + { + // Create the existing process + $process = factory(Process::class)->create( + ['PRO_CREATE_DATE' => '2019-07-10 10:00:00'] + ); + + // Mock the abstract class + $importer = $this + ->getMockBuilder('ProcessMaker\Importer\Importer') + ->getMockForAbstractClass(); + + // create the array that will be passed to the load method + $array = []; + + $array["files"]["workflow"] = []; + + $array['tables'] = [ + 'bpmn' => + [ + 'activity' => + [], + 'artifact' => + [], + 'bound' => + [], + 'data' => + [], + 'diagram' => + [ + 0 => + [ + 'dia_uid' => '9367735405d247f616ed440021337333', + 'prj_uid' => $process['PRO_UID'], + 'dia_name' => 'Custom', + 'dia_is_closable' => '0', + + ], + ], + 'documentation' => + [], + 'event' => + [], + 'extension' => + [], + 'flow' => + [], + 'gateway' => + [], + 'lane' => + [], + 'laneset' => + [], + 'participant' => + [], + 'process' => + [ + 0 => + [ + 'pro_uid' => '3209565785d247f618b6235074913840', + 'prj_uid' => $process['PRO_UID'], + 'dia_uid' => '9367735405d247f616ed440021337333', + 'pro_name' => 'Custom', + 'pro_type' => 'NONE', + 'pro_is_executable' => '0', + 'pro_is_closed' => '0', + 'pro_is_subprocess' => '0', + ], + ], + 'project' => + [ + 0 => + [ + 'prj_uid' => $process['PRO_UID'], + 'prj_name' => 'Custom', + 'prj_description' => '', + 'prj_target_namespace' => '', + 'prj_expresion_language' => '', + 'prj_type_language' => '', + 'prj_exporter' => '', + 'prj_exporter_version' => '', + 'prj_create_date' => '2019-07-09 11:49:53', + 'prj_update_date' => '', + 'prj_author' => '00000000000000000000000000000001', + 'prj_author_version' => '', + 'prj_original_source' => '', + ], + ], + ], + 'workflow' => + [ + 'stepSupervisor' => + [], + 'processUser' => + [], + 'groupwfs' => + [], + 'objectPermissions' => + [], + 'dbconnections' => + [], + 'filesManager' => + [], + 'reportTablesDefinition' => + [], + 'reportTablesFields' => + [], + 'steptriggers' => + [], + 'triggers' => + [], + 'steps' => + [], + 'outputs' => + [], + 'inputs' => + [], + 'dynaforms' => + [], + 'processVariables' => + [], + 'tasks' => + [], + 'taskusers' => + [], + 'routes' => + [], + 'lanes' => + [], + 'gateways' => + [], + 'subProcess' => + [], + 'caseTracker' => + [], + 'caseTrackerObject' => + [], + 'stage' => + [], + 'fieldCondition' => + [], + 'event' => + [], + 'caseScheduler' => + [], + 'processCategory' => + [], + 'taskExtraProperties' => + [], + 'webEntry' => + [], + 'webEntryEvent' => + [], + 'messageType' => + [], + 'messageTypeVariable' => + [], + 'messageEventDefinition' => + [], + 'scriptTask' => + [], + 'timerEvent' => + [], + 'emailEvent' => + [], + 'abeConfiguration' => + [], + 'process' => + [ + 0 => + [ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_TITLE' => 'Custom', + 'PRO_DESCRIPTION' => '', + 'PRO_PARENT' => $process['PRO_UID'], + 'PRO_TIME' => '1', + 'PRO_TIMEUNIT' => 'DAYS', + 'PRO_STATUS' => 'ACTIVE', + 'PRO_TYPE_DAY' => '', + 'PRO_TYPE' => 'NORMAL', + 'PRO_ASSIGNMENT' => 'FALSE', + 'PRO_SHOW_MAP' => '0', + 'PRO_SHOW_MESSAGE' => '0', + 'PRO_SUBPROCESS' => '0', + 'PRO_TRI_CREATE' => '', + 'PRO_TRI_OPEN' => '', + 'PRO_TRI_DELETED' => '', + 'PRO_TRI_CANCELED' => '', + 'PRO_TRI_PAUSED' => '', + 'PRO_TRI_REASSIGNED' => '', + 'PRO_TRI_UNPAUSED' => '', + 'PRO_TYPE_PROCESS' => 'PUBLIC', + 'PRO_SHOW_DELEGATE' => '0', + 'PRO_SHOW_DYNAFORM' => '0', + 'PRO_CATEGORY' => '', + 'PRO_SUB_CATEGORY' => '', + 'PRO_INDUSTRY' => '0', + 'PRO_UPDATE_DATE' => '', + 'PRO_CREATE_DATE' => '2019-07-09 11:49:53', + 'PRO_CREATE_USER' => '00000000000000000000000000000001', + 'PRO_HEIGHT' => '5000', + 'PRO_WIDTH' => '10000', + 'PRO_TITLE_X' => '0', + 'PRO_TITLE_Y' => '0', + 'PRO_DEBUG' => '0', + 'PRO_DYNAFORMS' => '', + 'PRO_DERIVATION_SCREEN_TPL' => '', + 'PRO_COST' => '0', + 'PRO_UNIT_COST' => '', + 'PRO_ITEE' => '1', + 'PRO_ACTION_DONE' => '', + 'PRO_CATEGORY_LABEL' => 'No Category', + 'PRO_BPMN' => '1', + ], + ], + 'reportTables' => + [], + 'reportTablesVars' => + [], + ], + 'plugins' => + [], + ]; + + // Mock the load method + $importer->method("load") + ->willReturn($array); + + // Call the import method + $res = $importer->import(Importer::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW, + Importer::GROUP_IMPORT_OPTION_CREATE_NEW, true); + + // Query the new process created + $query = Process::query(); + $query->select()->where('PRO_UID', $res); + $result = $query->get()->values()->toArray(); + + // Assert the created date is the same as the updated date + $this->assertEquals($result[0]['PRO_CREATE_DATE'], $result[0]['PRO_UPDATE_DATE']); + } + + /** + * Tests the import method when importing a process with a new uid + * + * @test + */ + public function it_should_test_the_import_method_when_importing_a_process_without_change_the_uid() + { + // Create the existing process + $process = factory(Process::class)->create( + ['PRO_CREATE_DATE' => '2019-07-10 10:00:00'] + ); + factory(BpmnProject::class)->create( + ['PRJ_UID' => $process['PRO_UID']] + ); + + // Mock the abstract class + $importer = $this + ->getMockBuilder('ProcessMaker\Importer\Importer') + ->getMockForAbstractClass(); + + // create the array that will be passed to the load method + $array = []; + + $array["files"]["workflow"] = []; + + $array['tables'] = [ + 'bpmn' => + [ + 'activity' => + [], + 'artifact' => + [], + 'bound' => + [], + 'data' => + [], + 'diagram' => + [ + 0 => + [ + 'dia_uid' => '9367735405d247f616ed440021337333', + 'prj_uid' => $process['PRO_UID'], + 'dia_name' => 'Custom', + 'dia_is_closable' => '0', + + ], + ], + 'documentation' => + [], + 'event' => + [], + 'extension' => + [], + 'flow' => + [], + 'gateway' => + [], + 'lane' => + [], + 'laneset' => + [], + 'participant' => + [], + 'process' => + [ + 0 => + [ + 'pro_uid' => '3209565785d247f618b6235074913840', + 'prj_uid' => $process['PRO_UID'], + 'dia_uid' => '9367735405d247f616ed440021337333', + 'pro_name' => 'Custom', + 'pro_type' => 'NONE', + 'pro_is_executable' => '0', + 'pro_is_closed' => '0', + 'pro_is_subprocess' => '0', + ], + ], + 'project' => + [ + 0 => + [ + 'prj_uid' => $process['PRO_UID'], + 'prj_name' => 'Custom', + 'prj_description' => '', + 'prj_target_namespace' => '', + 'prj_expresion_language' => '', + 'prj_type_language' => '', + 'prj_exporter' => '', + 'prj_exporter_version' => '', + 'prj_create_date' => '2019-07-09 11:49:53', + 'prj_update_date' => '', + 'prj_author' => '00000000000000000000000000000001', + 'prj_author_version' => '', + 'prj_original_source' => '', + ], + ], + ], + 'workflow' => + [ + 'stepSupervisor' => + [], + 'processUser' => + [], + 'groupwfs' => + [], + 'objectPermissions' => + [], + 'dbconnections' => + [], + 'filesManager' => + [], + 'reportTablesDefinition' => + [], + 'reportTablesFields' => + [], + 'steptriggers' => + [], + 'triggers' => + [], + 'steps' => + [], + 'outputs' => + [], + 'inputs' => + [], + 'dynaforms' => + [], + 'processVariables' => + [], + 'tasks' => + [], + 'taskusers' => + [], + 'routes' => + [], + 'lanes' => + [], + 'gateways' => + [], + 'subProcess' => + [], + 'caseTracker' => + [], + 'caseTrackerObject' => + [], + 'stage' => + [], + 'fieldCondition' => + [], + 'event' => + [], + 'caseScheduler' => + [], + 'processCategory' => + [], + 'taskExtraProperties' => + [], + 'webEntry' => + [], + 'webEntryEvent' => + [], + 'messageType' => + [], + 'messageTypeVariable' => + [], + 'messageEventDefinition' => + [], + 'scriptTask' => + [], + 'timerEvent' => + [], + 'emailEvent' => + [], + 'abeConfiguration' => + [], + 'process' => + [ + 0 => + [ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_TITLE' => 'Custom', + 'PRO_DESCRIPTION' => '', + 'PRO_PARENT' => $process['PRO_UID'], + 'PRO_TIME' => '1', + 'PRO_TIMEUNIT' => 'DAYS', + 'PRO_STATUS' => 'ACTIVE', + 'PRO_TYPE_DAY' => '', + 'PRO_TYPE' => 'NORMAL', + 'PRO_ASSIGNMENT' => 'FALSE', + 'PRO_SHOW_MAP' => '0', + 'PRO_SHOW_MESSAGE' => '0', + 'PRO_SUBPROCESS' => '0', + 'PRO_TRI_CREATE' => '', + 'PRO_TRI_OPEN' => '', + 'PRO_TRI_DELETED' => '', + 'PRO_TRI_CANCELED' => '', + 'PRO_TRI_PAUSED' => '', + 'PRO_TRI_REASSIGNED' => '', + 'PRO_TRI_UNPAUSED' => '', + 'PRO_TYPE_PROCESS' => 'PUBLIC', + 'PRO_SHOW_DELEGATE' => '0', + 'PRO_SHOW_DYNAFORM' => '0', + 'PRO_CATEGORY' => '', + 'PRO_SUB_CATEGORY' => '', + 'PRO_INDUSTRY' => '0', + 'PRO_UPDATE_DATE' => '', + 'PRO_CREATE_DATE' => '2019-07-09 11:49:53', + 'PRO_CREATE_USER' => '00000000000000000000000000000001', + 'PRO_HEIGHT' => '5000', + 'PRO_WIDTH' => '10000', + 'PRO_TITLE_X' => '0', + 'PRO_TITLE_Y' => '0', + 'PRO_DEBUG' => '0', + 'PRO_DYNAFORMS' => '', + 'PRO_DERIVATION_SCREEN_TPL' => '', + 'PRO_COST' => '0', + 'PRO_UNIT_COST' => '', + 'PRO_ITEE' => '1', + 'PRO_ACTION_DONE' => '', + 'PRO_CATEGORY_LABEL' => 'No Category', + 'PRO_BPMN' => '1', + ], + ], + 'reportTables' => + [], + 'reportTablesVars' => + [], + ], + 'plugins' => + [], + ]; + + // Mock the load method + $importer->method("load") + ->willReturn($array); + + // Call the setProtectedProperty method + $this->setProtectedProperty($importer, 'metadata', ['uid' => $process['PRO_UID']]); + + // Call the import method + $res = $importer->import(Importer::IMPORT_OPTION_OVERWRITE, + Importer::GROUP_IMPORT_OPTION_CREATE_NEW, false); + + // Query the new process created + $query = Process::query(); + $query->select()->where('PRO_UID', $res); + $result = $query->get()->values()->toArray(); + + // Assert the created date is the same as the updated date + $this->assertNotEquals($result[0]['PRO_CREATE_DATE'], $result[0]['PRO_UPDATE_DATE']); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Importer/Importer.php b/workflow/engine/src/ProcessMaker/Importer/Importer.php index 4d8cb2af2..f8ce9b043 100644 --- a/workflow/engine/src/ProcessMaker/Importer/Importer.php +++ b/workflow/engine/src/ProcessMaker/Importer/Importer.php @@ -91,6 +91,7 @@ abstract class Importer public function import($option = self::IMPORT_OPTION_CREATE_NEW, $optionGroup = self::GROUP_IMPORT_OPTION_CREATE_NEW, $generateUidFromJs = null, $objectsToImport = '') { $this->prepare(); + $keepCreateDate = false; //Verify data switch ($option) { case self::IMPORT_OPTION_CREATE_NEW: @@ -126,6 +127,7 @@ abstract class Importer case self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW: break; case self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW: + $keepCreateDate = true; break; } @@ -258,12 +260,15 @@ abstract class Importer $this->importData["tables"]["workflow"]["process"] = $this->importData["tables"]["workflow"]["process"][0]; //Import - if(!empty($generateUidFromJs)) { + if (!empty($generateUidFromJs)) { $generateUid = $generateUidFromJs; } /*----------------------------------********---------------------------------*/ //Granular Import try { + if ($generateUidFromJs || $keepCreateDate) { + unset($this->importData["tables"]["workflow"]["process"]["PRO_CREATE_DATE"]); + } if ($objectsToImport !== '') { $granularObj = new \ProcessMaker\BusinessModel\Migrator\GranularImporter(); $newObjectArray = $objectsToImport; @@ -651,7 +656,9 @@ abstract class Importer } unset($arrayWorkflowTables["process"]["PRO_CREATE_USER"]); - unset($arrayWorkflowTables["process"]["PRO_CREATE_DATE"]); + if ($generateUid) { + unset($arrayWorkflowTables["process"]["PRO_CREATE_DATE"]); + } unset($arrayWorkflowTables["process"]["PRO_UPDATE_DATE"]); if ($flagDeleteCategory) { diff --git a/workflow/engine/src/ProcessMaker/Model/BpmnProject.php b/workflow/engine/src/ProcessMaker/Model/BpmnProject.php new file mode 100644 index 000000000..5f5b85b79 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/BpmnProject.php @@ -0,0 +1,14 @@ +