PMC-1459 It is not possible to export processes

This commit is contained in:
Roly Rudy Gutierrez Pinto
2019-12-23 12:36:40 -04:00
parent 21b2eddc89
commit 2871f02a04
6 changed files with 1131 additions and 41 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}