Merged in bugfix/PMC-1459 (pull request #7196)
PMC-1459 It is not possible to export processes Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
929
tests/resources/dynaformDataForRenewUids.json
Normal file
929
tests/resources/dynaformDataForRenewUids.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,7 @@ use Tests\TestCase;
|
||||
|
||||
class ProcessesTest extends TestCase
|
||||
{
|
||||
private $processes;
|
||||
|
||||
/**
|
||||
* Constructor of the class.
|
||||
@@ -33,6 +34,7 @@ class ProcessesTest extends TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->processes = new Processes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +156,7 @@ class ProcessesTest extends TestCase
|
||||
* This checks fi the returned output documents are correct with the differect
|
||||
* parameters.
|
||||
* @test
|
||||
* @covers Processes::getOutputRows()
|
||||
* @covers \Processes::getOutputRows()
|
||||
*/
|
||||
public function it_should_return_output_documents()
|
||||
{
|
||||
@@ -205,7 +207,7 @@ class ProcessesTest extends TestCase
|
||||
/**
|
||||
* This checks if the dynaforms structure is saved with the different parameters.
|
||||
* @test
|
||||
* @covers Processes::createDynaformRows()
|
||||
* @covers \Processes::createDynaformRows()
|
||||
*/
|
||||
public function it_sholud_create_dynaform()
|
||||
{
|
||||
@@ -269,7 +271,7 @@ class ProcessesTest extends TestCase
|
||||
* This checks if the input documents structure is saved with the different
|
||||
* parameters.
|
||||
* @test
|
||||
* @covers Processes::createInputRows()
|
||||
* @covers \Processes::createInputRows()
|
||||
*/
|
||||
public function it_should_create_input_document()
|
||||
{
|
||||
@@ -339,7 +341,7 @@ class ProcessesTest extends TestCase
|
||||
* This checks if the output documents structure is saved with the different
|
||||
* parameters.
|
||||
* @test
|
||||
* @covers Processes::createOutputRows()
|
||||
* @covers \Processes::createOutputRows()
|
||||
*/
|
||||
public function it_should_create_output_document()
|
||||
{
|
||||
@@ -432,7 +434,7 @@ class ProcessesTest extends TestCase
|
||||
/**
|
||||
* This gets the data structure of a project.
|
||||
* @test
|
||||
* @covers Processes::getWorkflowData()
|
||||
* @covers \Processes::getWorkflowData()
|
||||
*/
|
||||
public function it_should_get_workflow_data()
|
||||
{
|
||||
@@ -459,4 +461,40 @@ class ProcessesTest extends TestCase
|
||||
$result = $processes->getWorkflowData($process->PRO_UID);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test guarantees the replacement of new identifiers.
|
||||
* @test
|
||||
* @covers \Processes::renewAllDynaformGuid()
|
||||
*/
|
||||
public function it_should_renew_all_dynaform_guid()
|
||||
{
|
||||
$pathData = PATH_TRUNK . "/tests/resources/dynaformDataForRenewUids.json";
|
||||
$data = file_get_contents($pathData);
|
||||
$result = json_decode($data, JSON_OBJECT_AS_ARRAY);
|
||||
$result = (object) $result;
|
||||
$this->processes->renewAllDynaformGuid($result);
|
||||
foreach ($result as $key => $value) {
|
||||
$this->assertObjectHasAttribute($key, $result);
|
||||
}
|
||||
|
||||
//without PRO_DYNAFORMS
|
||||
$result = json_decode($data, JSON_OBJECT_AS_ARRAY);
|
||||
$result = (object) $result;
|
||||
unset($result->process['PRO_DYNAFORMS']);
|
||||
$this->processes->renewAllDynaformGuid($result);
|
||||
foreach ($result as $key => $value) {
|
||||
$this->assertObjectHasAttribute($key, $result);
|
||||
}
|
||||
|
||||
//for process inside PRO_DYNAFORMS
|
||||
$result = json_decode($data, JSON_OBJECT_AS_ARRAY);
|
||||
$result = (object) $result;
|
||||
$result->process['PRO_DYNAFORMS'] = [];
|
||||
$result->process['PRO_DYNAFORMS']['PROCESS'] = $result->dynaforms[0]['DYN_UID'];
|
||||
$this->processes->renewAllDynaformGuid($result);
|
||||
foreach ($result as $key => $value) {
|
||||
$this->assertObjectHasAttribute($key, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Project;
|
||||
|
||||
use Exception;
|
||||
use Faker\Factory;
|
||||
use G;
|
||||
use ProcessMaker\Model\Dynaform;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\WebEntry;
|
||||
use ProcessMaker\Project\Workflow;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WorkflowTest extends TestCase
|
||||
{
|
||||
private $workflow;
|
||||
private $directories;
|
||||
private $files;
|
||||
private $faker;
|
||||
|
||||
/**
|
||||
* This method sets the values before starting any test.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->workflow = new Workflow();
|
||||
$this->directories = [];
|
||||
$this->files = [];
|
||||
$this->faker = Factory::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is executed after each test.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
foreach ($this->files as $value) {
|
||||
unlink($value);
|
||||
}
|
||||
foreach ($this->directories as $value) {
|
||||
rmdir($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that the getData method returns the correct data.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Project\Workflow::getData()
|
||||
*/
|
||||
public function it_should_return_the_data_when_the_project_id_is_valid()
|
||||
{
|
||||
$process = factory(Process::class)->create();
|
||||
$dynaforms = factory(Dynaform::class, 5)->create([
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
factory(WebEntry::class, 5)->create([
|
||||
'PRO_UID' => $process->PRO_UID
|
||||
]);
|
||||
|
||||
$directory = PATH_DYNAFORM . $process->PRO_UID . "/";
|
||||
$this->directories[] = $directory;
|
||||
mkdir($directory);
|
||||
foreach ($dynaforms as $dynaform) {
|
||||
Dynaform::where('PRO_UID', $process->PRO_UID)
|
||||
->where('DYN_UID', $dynaform->DYN_UID)
|
||||
->update(['DYN_FILENAME' => $process->PRO_UID . '/' . $dynaform->DYN_UID]);
|
||||
|
||||
$dynUid = $dynaform->DYN_UID;
|
||||
$data = '';
|
||||
$filename = $directory . $dynUid . ".xml";
|
||||
$this->files[] = $filename;
|
||||
file_put_contents($filename, $data);
|
||||
|
||||
$filename = $directory . $dynUid . ".html";
|
||||
$this->files[] = $filename;
|
||||
file_put_contents($filename, $data);
|
||||
}
|
||||
|
||||
//template
|
||||
$directory = PATH_DATA_MAILTEMPLATES . $process->PRO_UID;
|
||||
$this->directories[] = $directory;
|
||||
mkdir($directory);
|
||||
|
||||
$filename = $directory . "/test.html";
|
||||
$this->files[] = $filename;
|
||||
file_put_contents($filename, '');
|
||||
|
||||
//public files
|
||||
$directory = PATH_DATA_PUBLIC . $process->PRO_UID;
|
||||
$this->directories[] = $directory;
|
||||
mkdir($directory);
|
||||
|
||||
$filename = $directory . "/wsClient.php";
|
||||
$this->files[] = $filename;
|
||||
file_put_contents($filename, '');
|
||||
|
||||
$actual = $this->workflow->getData($process->PRO_UID);
|
||||
|
||||
$this->assertCount(2, $actual);
|
||||
$this->assertArrayHasKey('process', $actual[0]);
|
||||
$this->assertArrayHasKey('DYNAFORMS', $actual[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test should throw an exception when the parameter is not correct.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Project\Workflow::getData()
|
||||
*/
|
||||
public function it_should_throw_exception_when_get_data_is_failed()
|
||||
{
|
||||
$proUid = $this->faker->regexify("/[a-zA-Z]{32}/");
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$actual = $this->workflow->getData($proUid);
|
||||
}
|
||||
}
|
||||
@@ -1017,6 +1017,9 @@ class Processes
|
||||
$map[$val['DYN_UID']] = $newGuid;
|
||||
$oData->dynaforms[$key]['DYN_UID'] = $newGuid;
|
||||
unset($oData->dynaforms[$key]['DYN_ID']);
|
||||
|
||||
//this is important when UID's is updated
|
||||
$oData->dynaforms[$key]['DYN_FILENAME'] = $oData->dynaforms[$key]['PRO_UID'] . "/" . $oData->dynaforms[$key]['DYN_UID'];
|
||||
}
|
||||
|
||||
$oData->uid["DYNAFORM"] = $map;
|
||||
|
||||
@@ -268,44 +268,45 @@ if (isset($_POST["PRO_FILENAME"]) &&
|
||||
try {
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$objectsToImport = '';
|
||||
// only uploadFileNewProcessExist
|
||||
if (version_compare($data['version'], '3.0', '>') && isset($_POST['objectsToImport']) && $_POST['objectsToImport'] === '' && $_POST['IMPORT_OPTION']==="1") {
|
||||
$objectImport = (isset($data['objects'])) ? explode('|', $data['objects']) : "";
|
||||
$ids = new \ProcessMaker\BusinessModel\Migrator\ExportObjects();
|
||||
$objectImport = $ids->getIdObjectList($objectImport);
|
||||
$granularImport = true;
|
||||
$result = array(
|
||||
"success" => true,
|
||||
"catchMessage" => '',
|
||||
"ExistProcessInDatabase" => 0,
|
||||
"ExistGroupsInDatabase" => 0,
|
||||
"notExistProcessInDatabase" => 0,
|
||||
"affectedGroups" => '',
|
||||
"sNewProUid" => '',
|
||||
"project_type" => 'bpmn',
|
||||
"isGranularImport" => $granularImport,
|
||||
"objectGranularImport" => $objectImport,
|
||||
"project_type_aux" => ''
|
||||
);
|
||||
echo G::json_encode($result);
|
||||
exit(0);
|
||||
}
|
||||
if (version_compare($data['version'], '3.0', '>')) {
|
||||
$dataObject = (isset($data['objects'])) ? explode('|', $data['objects']) : "";
|
||||
$exportObjects = new \ProcessMaker\BusinessModel\Migrator\ExportObjects();
|
||||
$idObjectList = $exportObjects->getIdObjectList($dataObject);
|
||||
|
||||
// only uploadFileNewProcessExist
|
||||
if (isset($_POST['objectsToImport']) && $_POST['objectsToImport'] === '' && $_POST['IMPORT_OPTION'] === "1") {
|
||||
$granularImport = true;
|
||||
$result = [
|
||||
"success" => true,
|
||||
"catchMessage" => '',
|
||||
"ExistProcessInDatabase" => 0,
|
||||
"ExistGroupsInDatabase" => 0,
|
||||
"notExistProcessInDatabase" => 0,
|
||||
"affectedGroups" => '',
|
||||
"sNewProUid" => '',
|
||||
"project_type" => 'bpmn',
|
||||
"isGranularImport" => $granularImport,
|
||||
"objectGranularImport" => $idObjectList,
|
||||
"project_type_aux" => ''
|
||||
];
|
||||
echo G::json_encode($result);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$actionImport = "merge";
|
||||
if ($_POST['IMPORT_OPTION'] === "3") {
|
||||
$actionImport = "replace";
|
||||
}
|
||||
|
||||
if ((version_compare($data['version'], '3.0',
|
||||
'>') && $_POST['IMPORT_OPTION'] === "3") || empty($_POST['objectsToImport'])) {
|
||||
$objectsToImport = [];
|
||||
$objects = (isset($data['objects'])) ? explode('|', $data['objects']) : "";
|
||||
$ids = new \ProcessMaker\BusinessModel\Migrator\ExportObjects();
|
||||
$objects = $ids->getIdObjectList($objects);
|
||||
foreach ($objects as $object) {
|
||||
$objectsToImport[] = (object)array('id' => $object, 'action' => 'replace');
|
||||
foreach ($idObjectList as $object) {
|
||||
$objectsToImport[] = (object) ['id' => $object, 'action' => $actionImport];
|
||||
}
|
||||
|
||||
if (isset($_POST['objectsToImport']) && !empty(G::json_decode($_POST['objectsToImport']))) {
|
||||
$objectsToImport = G::json_decode($_POST['objectsToImport']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['objectsToImport']) && !empty(G::json_decode($_POST['objectsToImport']))) {
|
||||
$objectsToImport = G::json_decode($_POST['objectsToImport']);
|
||||
}
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$prjUid = $importer->import($option, $optionGroup, false, $objectsToImport);
|
||||
|
||||
|
||||
@@ -1169,12 +1169,13 @@ class Workflow extends Handler
|
||||
|
||||
//Getting DynaForms
|
||||
foreach ($workflowData["dynaforms"] as $dynaform) {
|
||||
$dynFile = PATH_DYNAFORM . $dynaform["DYN_FILENAME"] . ".xml";
|
||||
$dynFile = PATH_DYNAFORM . $dynaform["PRO_UID"] . "/" . $dynaform["DYN_UID"] . ".xml";
|
||||
$content = file_exists($dynFile) ? file_get_contents($dynFile) : '';
|
||||
|
||||
$workflowFile["DYNAFORMS"][] = array(
|
||||
"filename" => $dynaform["DYN_TITLE"],
|
||||
"filepath" => $dynaform["DYN_FILENAME"] . ".xml",
|
||||
"file_content" => file_get_contents($dynFile)
|
||||
"file_content" => $content
|
||||
);
|
||||
|
||||
$htmlFile = PATH_DYNAFORM . $dynaform["DYN_FILENAME"] . ".html";
|
||||
|
||||
Reference in New Issue
Block a user