Merged in bugfix/PMC-138 (pull request #7110)

PMC-138 Assigned user lost in case of Custom Import (Promotion Manager)

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Roly
2019-11-01 17:42:56 +00:00
committed by Julio Cesar Laura Avendaño
21 changed files with 11650 additions and 47 deletions

View File

@@ -428,4 +428,35 @@ class ProcessesTest extends TestCase
$this->assertEquals($expected, $actual);
}
/**
* This gets the data structure of a project.
* @test
* @covers Processes::getWorkflowData()
*/
public function it_should_get_workflow_data()
{
/**
* To perform the test this requires a valid installation and its respective license.
*
* In the file "workflow/engine/classes/WorkspaceTools.php",
* these lines need the db.php file.
*
* public function __construct($workspaceName)
* {
* $this->name = $workspaceName;
* $this->path = PATH_DB . $this->name;
* $this->dbPath = $this->path . '/db.php';
* if ($this->workspaceExists()) {
* $this->getDBInfo();
* }
* $this->setListContentMigrateTable();
* }
*/
$this->markTestIncomplete("To perform the test this requires a valid installation and its respective license.");
$process = factory(\ProcessMaker\Model\Process::class)->create();
$processes = new Processes();
$result = $processes->getWorkflowData($process->PRO_UID);
$this->assertNotNull($result);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel;
use ProcessMaker\BusinessModel\Migrator\GranularImporter;
use Tests\TestCase;
class GranularImporterTest extends TestCase
{
/**
* This returns a set of data that is read from a json file.
*/
public function importDataObject()
{
$filename = PATH_TRUNK . "/tests/resources/GranularImporterTest.json";
$json = file_get_contents($filename);
$data = json_decode($json, true);
return $data;
}
/**
* It should return data from addObjectData() method.
* @test
* @covers \ProcessMaker\BusinessModel\Migrator\GranularImporter::addObjectData()
* @dataProvider importDataObject
*/
public function it_should_return_data_from_add_object_data_method($name, $data)
{
$granularImporter = new GranularImporter();
$result = $granularImporter->addObjectData($name, $data);
$this->assertArrayHasKey($name, $result);
}
}

View File

@@ -0,0 +1,312 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Importer;
use G;
use Exception;
use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\User;
use ProcessMaker\Importer\XmlImporter;
use Tests\TestCase;
class XmlImporterTest extends TestCase
{
private $user;
public function setUp()
{
/**
* To perform the test this requires a valid installation and its respective license.
*
* In the file "workflow/engine/classes/WorkspaceTools.php",
* these lines need the db.php file.
*
* public function __construct($workspaceName)
* {
* $this->name = $workspaceName;
* $this->path = PATH_DB . $this->name;
* $this->dbPath = $this->path . '/db.php';
* if ($this->workspaceExists()) {
* $this->getDBInfo();
* }
* $this->setListContentMigrateTable();
* }
*
*
* In the file "workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularImporter.php",
* these lines need a valid license.
*
* public function import($objectList)
* {
* try {
* if (\PMLicensedFeatures::getSingleton()->verifyfeature
* ("jXsSi94bkRUcVZyRStNVExlTXhEclVadGRRcG9xbjNvTWVFQUF3cklKQVBiVT0=")
* ) {
* $objectList = $this->reorderImportOrder($objectList);
* foreach ($objectList as $data) {
* $objClass = $this->factory->create($data['name']);
* if (is_object($objClass)) {
* $dataImport = $data['data'][$data['name']];
* $replace = ($data['value'] == 'replace') ? true : false;
* $objClass->beforeImport($dataImport);
* $migratorData = $objClass->import($dataImport, $replace);
* $objClass->afterImport($dataImport);
* }
* }
* } else {
* $exception = new ImportException();
* $exception->setNameException(\G::LoadTranslation('ID_NO_LICENSE_SELECTIVEIMPORTEXPORT_ENABLED'));
* throw($exception);
* }
*
* } catch (\Exception $e) {
* if (get_class($e) === 'ProcessMaker\BusinessModel\Migrator\ImportException') {
* throw $e;
* } else {
* $exception = new ImportException('Please review your current process definition
* for missing elements, it\'s recommended that a new process should be exported
* with all the elements.');
* throw $exception;
* }
* }
* }
*/
$this->markTestIncomplete("To perform the test this requires a valid installation and its respective license.");
parent::setUp();
$this->user = factory(User::class)->create();
Groupwf::truncate();
}
/**
* Test the import new option and the import new group option.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
* @covers \ProcessMaker\Importer\XmlImporter::importBpmnTables()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new()
{
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
/**
* Test the import new without changing and the import merge group option.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_keep_without_changing_and_create_new_and_group_import_option_merge_preexistent()
{
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group1'
]);
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group2'
]);
$regenerateUids = false;
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT, true);
$this->assertNotNull($result);
}
/**
* Test the import overwrite option and the import rename group option.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_overwrite_and_group_import_option_rename()
{
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group1'
]);
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group2'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_RENAME, false);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with objects imports.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
* @covers \ProcessMaker\BusinessModel\Migrator\GranularImporter::structureBpmnData()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_and_objects_import()
{
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import without changing option and the import new group option with objects import.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_keep_without_changing_and_create_new_and_group_import_option_create_new()
{
$regenerateUids = false;
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, true, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import overwrite option and the import new group option with objects import.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_overwrite_and_group_import_option_create_new()
{
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import disable option and the import new group option with objects import.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_disable_and_create_new_and_group_import_option_create_new()
{
$regenerateUids = false;
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_DISABLE_AND_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, true, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with exception.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_with_exception()
{
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$this->expectException(Exception::class);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
/**
* Test the import overwrite option and the import new group option with exist groups.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_overwrite_and_group_import_option_create_new_with_groups()
{
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group1'
]);
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group2'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$this->expectException(Exception::class);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with generated uid from js such as null.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_try_exception()
{
$filename = PATH_TRUNK . "/tests/resources/p1normalWithException-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$this->expectException(Exception::class);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with repeated title.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
* @covers \ProcessMaker\Importer\XmlImporter::updateTheProcessOwner()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_try_rename_title()
{
factory(\ProcessMaker\Model\Process::class)->create([
'PRO_TITLE' => 'p1normalWithoutTitle'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normalWithoutTitle-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
factory(\ProcessMaker\Model\Process::class)->create([
'PRO_TITLE' => 'p1normalWithoutTitle2'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normalWithoutTitle2-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
}

View File

@@ -0,0 +1,236 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Project\Adapter;
use Exception;
use Faker\Factory;
use G;
use ProcessMaker\Model\BpmnProject;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ProcessMaker\Project\Adapter\BpmnWorkflow;
use ProcessMaker\Importer\XmlImporter;
use Tests\TestCase;
class BpmnWorkflowTest extends TestCase
{
private $user;
public function setUp()
{
parent::setUp();
$this->user = factory(User::class)->create();
}
/**
* Creation of a bpmn project.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::create()
*/
public function it_should_create_bpmn_project()
{
$faker = Factory::create();
$data = [
'PRJ_UID' => G::generateUniqueID(),
'PRJ_AUTHOR' => G::generateUniqueID(),
'PRJ_NAME' => $faker->title,
'PRJ_DESCRIPTION' => $faker->text,
'PRJ_TYPE' => $faker->name,
'PRJ_CATEGORY' => $faker->word,
'PRO_ID' => $faker->randomDigit,
'PRO_STATUS' => 'ACTIVE'
];
$bpmnWorkflow = new BpmnWorkflow();
$bpmnWorkflow->create($data);
$bpmnProject = BpmnProject::where('PRJ_UID', '=', $data['PRJ_UID'])
->get();
$this->assertNotNull($bpmnProject);
}
/**
* We get an exception when the data is incorrect.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::create()
*/
public function it_should_create_bpmn_project_with_incorrect_data()
{
$faker = Factory::create();
$data = [
'PRJ_UID' => []
];
$bpmnWorkflow = new BpmnWorkflow();
$this->expectException(Exception::class);
$bpmnWorkflow->create($data);
}
/**
* An exception is obtained if we try to enter an existing title.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::create()
*/
public function it_should_create_bpmn_project_with_duplicate_title()
{
$faker = Factory::create();
$title = $faker->title;
factory(\ProcessMaker\Model\Process::class)->create([
'PRO_TITLE' => $title
]);
$data = [
'PRJ_UID' => G::generateUniqueID(),
'PRJ_AUTHOR' => G::generateUniqueID(),
'PRJ_NAME' => $title,
'PRJ_DESCRIPTION' => $faker->text,
'PRJ_TYPE' => $faker->name,
'PRJ_CATEGORY' => $faker->word,
'PRO_ID' => $faker->randomDigit,
'PRO_STATUS' => 'ACTIVE'
];
$bpmnWorkflow = new BpmnWorkflow();
$this->expectException(Exception::class);
$bpmnWorkflow->create($data);
}
/**
* Create a project from a data structure.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* Get an exception if there is an invalid name in the data structure.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_name()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = '';
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* Get an exception if there is a duplicate name.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_with_duplicate_name()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
factory(\ProcessMaker\Model\BpmnProject::class)->create([
'PRJ_NAME' => $projectData['prj_name']
]);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* We get an exception if the type field does not exist in the activity.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_activity_type()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = $faker->name;
unset($projectData['diagrams']['0']['activities']['0']['act_type']);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* We get an exception if the type field does not exist in the event.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_event_type()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = $faker->name;
unset($projectData['diagrams']['0']['events']['0']['evn_type']);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* We get an exception if the marker field does not exist in the event.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_event_marker()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = $faker->name;
unset($projectData['diagrams']['0']['events']['0']['evn_marker']);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Services\Api;
use Faker\Factory;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ProcessMaker\Importer\XmlImporter;
use ProcessMaker\Services\Api\Project;
use Tests\TestCase;
class ProjectTest extends TestCase
{
private $user;
public function setUp()
{
/**
* To perform the test this requires a valid installation and its respective license.
*
* In the file "workflow/engine/classes/WorkspaceTools.php",
* these lines need the db.php file.
*
* public function __construct($workspaceName)
* {
* $this->name = $workspaceName;
* $this->path = PATH_DB . $this->name;
* $this->dbPath = $this->path . '/db.php';
* if ($this->workspaceExists()) {
* $this->getDBInfo();
* }
* $this->setListContentMigrateTable();
* }
*/
$this->markTestIncomplete("To perform the test this requires a valid installation and its respective license.");
parent::setUp();
$this->user = factory(User::class)->create();
}
/**
* Set the process owner with invalid value, the import test covers most of the code.
* @test
* @covers \ProcessMaker\Services\Api\Project::doSaveAs()
* @covers \ProcessMaker\Importer\XmlImporter::saveAs()
*/
public function it_should_set_the_process_owner_with_invalid_value()
{
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$proUid = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$faker = $faker = Factory::create();
$project = new Project();
$project->setUserId($this->user->USR_ID);
$result = $project->doSaveAs($proUid, $faker->title);
$this->assertNotEmpty($result);
}
}