ProcessMaker-BE "BPMN Import (PHPUnit)"

- PHPUnit for processmaker/workflow/engine/src/ProcessMaker/Importer/XmlImporter.php
- BPMN Export, el nombre del archivo generado contiene
  el caracter guion bajo en reemplazo del caracter espacio
This commit is contained in:
Victor Saisa Lopez
2014-05-12 15:24:19 -04:00
parent 1843cae639
commit 212938d835
4 changed files with 18 additions and 20 deletions

View File

@@ -401,7 +401,7 @@ abstract class Importer
$arrayFieldNameForException = $arrayFieldName;
if (isset($_FILES[$arrayFieldName["projectFile"]])) {
$_FILES["filepmx"] = $_FILES[$arrayFieldName["projectFile"]];
$_FILES["filePmx"] = $_FILES[$arrayFieldName["projectFile"]];
}
if (isset($arrayData[$arrayFieldName["projectFile"]]) &&
@@ -418,7 +418,6 @@ abstract class Importer
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, true);
@@ -433,7 +432,7 @@ abstract class Importer
}
}
if ((isset($_FILES["filepmx"]) && pathinfo($_FILES["filepmx"]["name"], PATHINFO_EXTENSION) != "pmx") ||
if ((isset($_FILES["filePmx"]) && pathinfo($_FILES["filePmx"]["name"], PATHINFO_EXTENSION) != "pmx") ||
(isset($arrayData[$arrayFieldName["projectFile"]]) && pathinfo($arrayData[$arrayFieldName["projectFile"]], PATHINFO_EXTENSION) != "pmx")
) {
throw (new \Exception("The file extension not is \"pmx\""));
@@ -456,12 +455,13 @@ abstract class Importer
$option = $opt;
if (isset($_FILES["filepmx"])) {
$this->setSaveDir(PATH_DOCUMENT . "input");
$this->setSourceFromGlobals("filepmx");
if (isset($_FILES["filePmx"])) {
$this->setSourceFromGlobals("filePmx");
} else {
if (isset($arrayData[$arrayFieldName["projectFile"]]) && file_exists(PATH_DOCUMENT . "input" . PATH_SEP . $arrayData[$arrayFieldName["projectFile"]])) {
$this->setSourceFile(PATH_DOCUMENT . "input" . PATH_SEP . $arrayData[$arrayFieldName["projectFile"]]);
$filePmx = rtrim($this->getSaveDir(), PATH_SEP) . PATH_SEP . $arrayData[$arrayFieldName["projectFile"]];
if (isset($arrayData[$arrayFieldName["projectFile"]]) && file_exists($filePmx)) {
$this->setSourceFile($filePmx);
} else {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayFieldNameForException["projectFile"], $arrayData[$arrayFieldName["projectFile"]]), "The file with {0}: \"{1}\" does not exist.")));
}

View File

@@ -133,6 +133,7 @@ class Project extends Api
try {
$importer = new \ProcessMaker\Importer\XmlImporter();
$importer->setSaveDir(PATH_DOCUMENT . "input");
$importer->setData("usr_uid", $this->getUserId());
$arrayData = $importer->importPostFile($request_data, $option, array("projectFile" => "project_file", "option" => "option"));

View File

@@ -15,8 +15,7 @@ class XmlExporterTest extends \PHPUnit_Framework_TestCase
{
protected static $exporter;
protected static $projectUid = "";
protected static $projectName = "";
protected static $fileXml = "";
protected static $filePmx = "";
/**
* Set class for test
@@ -25,11 +24,9 @@ class XmlExporterTest extends \PHPUnit_Framework_TestCase
*/
public static function setUpBeforeClass()
{
self::$projectName = \ProcessMaker\Util\Common::generateUID();
$json = "
{
\"prj_name\": \"" . self::$projectName . "\",
\"prj_name\": \"" . \ProcessMaker\Util\Common::generateUID() . "\",
\"prj_author\": \"00000000000000000000000000000001\",
\"diagrams\": [
{
@@ -49,7 +46,7 @@ class XmlExporterTest extends \PHPUnit_Framework_TestCase
$arrayResult = \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct(json_decode($json, true));
self::$projectUid = $arrayResult[0]["new_uid"];
self::$fileXml = PATH_DOCUMENT . "output" . PATH_SEP . self::$projectUid . ".xml";
self::$filePmx = PATH_DOCUMENT . "output" . PATH_SEP . self::$projectUid . ".pmx";
self::$exporter = new \ProcessMaker\Exporter\XmlExporter(self::$projectUid);
}
@@ -62,10 +59,9 @@ class XmlExporterTest extends \PHPUnit_Framework_TestCase
public static function tearDownAfterClass()
{
$bpmnWf = \ProcessMaker\Project\Adapter\BpmnWorkflow::load(self::$projectUid);
$bpmnWf->remove();
unlink(self::$fileXml);
unlink(self::$filePmx);
}
/**
@@ -127,7 +123,7 @@ class XmlExporterTest extends \PHPUnit_Framework_TestCase
$node = $value;
if ($node->hasAttribute("class")) {
$this->assertTrue(in_array($node->getAttribute("class"), array("BPMN", "workflow")));
$this->assertContains($node->getAttribute("class"), array("BPMN", "workflow"));
}
}
}
@@ -139,9 +135,9 @@ class XmlExporterTest extends \PHPUnit_Framework_TestCase
*/
public function testSaveExport()
{
self::$exporter->saveExport(self::$fileXml);
self::$exporter->saveExport(self::$filePmx);
$this->assertTrue(file_exists(self::$fileXml));
$this->assertTrue(file_exists(self::$filePmx));
}
/**