Merge branch 'master' of bitbucket.org:colosa/processmaker
This commit is contained in:
@@ -1521,4 +1521,232 @@ class Cases
|
||||
$appNote = new \AppNotes();
|
||||
$appNote->addCaseNote($app_uid, $usr_uid, $note_content, intval($send_mail));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data Task Case
|
||||
*
|
||||
* @param string $sApplicationUID Unique id of Case
|
||||
*
|
||||
* return array Return an array with Task Case
|
||||
*/
|
||||
public function getTasks($sApplicationUID)
|
||||
{
|
||||
try {
|
||||
$iDelegation = \AppDelegation::getCurrentIndex($sApplicationUID);
|
||||
$case = new \Cases();
|
||||
$caseLoad = $case->loadCase($sApplicationUID);
|
||||
$sProcessUID = $caseLoad['PRO_UID'];
|
||||
$sTask = '';
|
||||
$bCT = true;
|
||||
$oProcess = new \Process();
|
||||
$oPM = array();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(\TaskPeer::PRO_UID);
|
||||
$oCriteria->addSelectColumn(\TaskPeer::TAS_UID);
|
||||
$oCriteria->addSelectColumn(\ContentPeer::CON_VALUE);
|
||||
$oCriteria->addSelectColumn(\TaskPeer::TAS_START);
|
||||
$oCriteria->addSelectColumn(\TaskPeer::TAS_TYPE);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(0 => \TaskPeer::TAS_UID, 1 => \ContentPeer::CON_ID);
|
||||
$aConditions[] = array(0 => \ContentPeer::CON_CATEGORY, 1 => \DBAdapter::getStringDelimiter() . 'TAS_TITLE' . \DBAdapter::getStringDelimiter() );
|
||||
$aConditions[] = array(0 => \ContentPeer::CON_LANG, 1 => \DBAdapter::getStringDelimiter() . SYS_LANG . \DBAdapter::getStringDelimiter() );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->add(\TaskPeer::PRO_UID, $sProcessUID);
|
||||
$oDataset = \TaskPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
while ($aRow1 = $oDataset->getRow()) {
|
||||
$oTask = new \StdClass();
|
||||
$oTask->tas_uid = $aRow1['TAS_UID'];
|
||||
$oTask->tas_type = $aRow1['TAS_TYPE'];
|
||||
if ($aRow1['TAS_TYPE'] == 'NORMAL') {
|
||||
if (($aRow1['CON_VALUE'] == "")) {
|
||||
//There is no Label in Current SYS_LANG language so try to find in English - by default
|
||||
$oTask1 = new \Task();
|
||||
$aRow1['CON_VALUE'] = $oTask1->getTasTitle();
|
||||
}
|
||||
$oTask->tas_title = htmlentities($aRow1['CON_VALUE'], ENT_QUOTES, 'UTF-8');
|
||||
} else {
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$del = \DBAdapter::getStringDelimiter();
|
||||
$oCriteria->add(\SubProcessPeer::PRO_PARENT, $aRow1['PRO_UID']);
|
||||
$oCriteria->add(\SubProcessPeer::TAS_PARENT, $aRow1['TAS_UID']);
|
||||
|
||||
$oCriteria->addAsColumn('TAS_TITLE', 'C1.CON_VALUE');
|
||||
$oCriteria->addAlias("C1", 'CONTENT');
|
||||
$tasTitleConds = array();
|
||||
$tasTitleConds[] = array(\SubProcessPeer::TAS_PARENT, 'C1.CON_ID');
|
||||
$tasTitleConds[] = array('C1.CON_CATEGORY', $del . 'TAS_TITLE' . $del);
|
||||
$tasTitleConds[] = array('C1.CON_LANG', $del . SYS_LANG . $del);
|
||||
$oCriteria->addJoinMC($tasTitleConds, \Criteria::LEFT_JOIN);
|
||||
|
||||
$oDatasetX = \SubProcessPeer::doSelectRS($oCriteria);
|
||||
$oDatasetX->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDatasetX->next();
|
||||
$aRowx = $oDatasetX->getRow();
|
||||
if ($oProcess->exists($aRowx['PRO_UID'])) {
|
||||
$oTask->tas_title = htmlentities($aRowx['TAS_TITLE'], ENT_QUOTES, 'UTF-8');
|
||||
} else {
|
||||
$oTask->tas_title = htmlentities($aRow1['CON_VALUE'], ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
$oTask->routing = new \StdClass();
|
||||
$oTask->routing->rou_type = '';
|
||||
$oTask->routing->to = array();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(\RoutePeer::ROU_TYPE);
|
||||
$oCriteria->addSelectColumn(\RoutePeer::ROU_NEXT_TASK);
|
||||
$oCriteria->addSelectColumn(\RoutePeer::ROU_CONDITION);
|
||||
$oCriteria->addSelectColumn(\RoutePeer::ROU_TO_LAST_USER);
|
||||
$oCriteria->addSelectColumn(\RoutePeer::ROU_OPTIONAL);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_UID);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_LASTNAME);
|
||||
$oCriteria->addSelectColumn(\AppDelegationPeer::DEL_INIT_DATE);
|
||||
$oCriteria->addSelectColumn(\AppDelegationPeer::DEL_TASK_DUE_DATE);
|
||||
$oCriteria->addSelectColumn(\AppDelegationPeer::DEL_FINISH_DATE);
|
||||
$oCriteria->addJoin(\AppDelegationPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->addJoin(\AppDelegationPeer::PRO_UID, \RoutePeer::PRO_UID, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->add(\RoutePeer::PRO_UID, $sProcessUID);
|
||||
$oCriteria->add(\RoutePeer::TAS_UID, $aRow1['TAS_UID']);
|
||||
$oCriteria->add(\AppDelegationPeer::APP_UID, $sApplicationUID);
|
||||
$oCriteria->add(\AppDelegationPeer::TAS_UID, $aRow1['TAS_UID']);
|
||||
$oCriteria->addDescendingOrderByColumn(\AppDelegationPeer::DEL_INDEX);
|
||||
$oDataset2 = \AppDelegationPeer::doSelectRS($oCriteria);
|
||||
$oDataset2->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset2->next();
|
||||
while ($aRow2 = $oDataset2->getRow()) {
|
||||
switch ($aRow2['ROU_TYPE']) {
|
||||
case 'SEQUENTIAL':
|
||||
$aRow2['ROU_TYPE'] = 0;
|
||||
break;
|
||||
case 'SELECT':
|
||||
$aRow2['ROU_TYPE'] = 1;
|
||||
break;
|
||||
case 'EVALUATE':
|
||||
$aRow2['ROU_TYPE'] = 2;
|
||||
break;
|
||||
case 'PARALLEL':
|
||||
$aRow2['ROU_TYPE'] = 3;
|
||||
break;
|
||||
case 'PARALLEL-BY-EVALUATION':
|
||||
$aRow2['ROU_TYPE'] = 4;
|
||||
break;
|
||||
case 'SEC-JOIN':
|
||||
$aRow2['ROU_TYPE'] = 5;
|
||||
break;
|
||||
case 'DISCRIMINATOR':
|
||||
$aRow2['ROU_TYPE'] = 8;
|
||||
break;
|
||||
}
|
||||
$iDiff = strtotime($aRow2['DEL_FINISH_DATE']) - strtotime($aRow2['DEL_INIT_DATE']);
|
||||
$oTo = new \StdClass();
|
||||
$oTo->rou_next_task = $aRow2['ROU_NEXT_TASK'];
|
||||
$oTo->rou_condition = $aRow2['ROU_CONDITION'];
|
||||
$oTo->rou_to_last_user = $aRow2['ROU_TO_LAST_USER'];
|
||||
$oTo->rou_optional = $aRow2['ROU_OPTIONAL'];
|
||||
$oTo->usr_uid = ($aRow2['USR_UID'] != null ? $aRow2['USR_FIRSTNAME'] . ' ' . $aRow2['USR_LASTNAME'] : \G::LoadTranslation('ID_NONE'));
|
||||
$oTo->usr_firstname = $aRow2['USR_FIRSTNAME'];
|
||||
$oTo->usr_lastname = $aRow2['USR_LASTNAME'];
|
||||
$oTo->del_init_date = ($aRow2['DEL_INIT_DATE'] != null ? $aRow2['DEL_INIT_DATE'] : \G::LoadTranslation('ID_CASE_NOT_YET_STARTED'));
|
||||
$oTo->del_task_due_date = ($aRow2['DEL_TASK_DUE_DATE'] != null ? $aRow2['DEL_TASK_DUE_DATE'] : \G::LoadTranslation('ID_CASE_NOT_YET_STARTED'));
|
||||
$oTo->del_finish_date = ($aRow2['DEL_FINISH_DATE'] != null ? $aRow2['DEL_FINISH_DATE'] : \G::LoadTranslation('ID_NOT_FINISHED'));
|
||||
$oTo->duration = ($aRow2['DEL_FINISH_DATE'] != null ? (int) ($iDiff / 3600) . ' ' . ((int) ($iDiff / 3600) == 1 ? \G::LoadTranslation('ID_HOUR') : \G::LoadTranslation('ID_HOURS')) . ' ' . (int) (($iDiff % 3600) / 60) . ' ' . ((int) (($iDiff % 3600) / 60) == 1 ? \G::LoadTranslation('ID_MINUTE') : \G::LoadTranslation('ID_MINUTES')) . ' ' . (int) (($iDiff % 3600) % 60) . ' ' . ((int) (($iDiff % 3600) % 60) == 1 ? \G::LoadTranslation('ID_SECOND') : \G::LoadTranslation('ID_SECONDS')) : \G::LoadTranslation('ID_NOT_FINISHED'));
|
||||
$oTask->routing->rou_type = $aRow2['ROU_TYPE'];
|
||||
$oTask->routing->to[] = $oTo;
|
||||
$oDataset2->next();
|
||||
}
|
||||
if ($bCT) {
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn('COUNT(*) AS CANT');
|
||||
$oCriteria->addSelectColumn('MIN(DEL_FINISH_DATE) AS FINISH');
|
||||
$oCriteria->add(\AppDelegationPeer::APP_UID, $sApplicationUID);
|
||||
$oCriteria->add(\AppDelegationPeer::TAS_UID, $aRow1['TAS_UID']);
|
||||
$oDataset2 = \AppDelegationPeer::doSelectRS($oCriteria);
|
||||
$oDataset2->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset2->next();
|
||||
$aRow2 = $oDataset2->getRow();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn('DEL_FINISH_DATE');
|
||||
$oCriteria->add(\AppDelegationPeer::APP_UID, $sApplicationUID);
|
||||
$oCriteria->add(\AppDelegationPeer::TAS_UID, $aRow1['TAS_UID']);
|
||||
$oCriteria->add(\AppDelegationPeer::DEL_FINISH_DATE, null);
|
||||
$oDataset2 = \AppDelegationPeer::doSelectRS($oCriteria);
|
||||
$oDataset2->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset2->next();
|
||||
$aRow3 = $oDataset2->getRow();
|
||||
if ($aRow3) {
|
||||
$aRow2['FINISH'] = '';
|
||||
}
|
||||
if (empty($aRow2["FINISH"]) && $aRow1["TAS_UID"] == $sTask) {
|
||||
$oTask->color = "#FF0000"; //Red
|
||||
} else {
|
||||
if (!empty($aRow2["FINISH"])) {
|
||||
$oTask->color = "#006633"; //Green
|
||||
} else {
|
||||
if ($oTask->routing->rou_type != 5) {
|
||||
if ($aRow2["CANT"] != 0) {
|
||||
$oTask->color = "#FF0000"; //Red
|
||||
} else {
|
||||
$oTask->color = "#939598"; //Gray
|
||||
}
|
||||
} else {
|
||||
if ($aRow3) {
|
||||
$oTask->color = "#FF0000"; //Red
|
||||
} else {
|
||||
$oTask->color = "#939598"; //Gray
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (($sApplicationUID != '') && ($iDelegation > 0) && ($sTask != '')) {
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn('COUNT(*) AS CANT');
|
||||
$oCriteria->addSelectColumn('MIN(DEL_FINISH_DATE) AS FINISH');
|
||||
$oCriteria->add(\AppDelegationPeer::APP_UID, $sApplicationUID);
|
||||
$oCriteria->add(\AppDelegationPeer::TAS_UID, $aRow1['TAS_UID']);
|
||||
$oDataset2 = \AppDelegationPeer::doSelectRS($oCriteria);
|
||||
$oDataset2->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset2->next();
|
||||
$aRow2 = $oDataset2->getRow();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn('DEL_FINISH_DATE');
|
||||
$oCriteria->add(\AppDelegationPeer::APP_UID, $sApplicationUID);
|
||||
$oCriteria->add(\AppDelegationPeer::TAS_UID, $aRow1['TAS_UID']);
|
||||
$oCriteria->add(\AppDelegationPeer::DEL_FINISH_DATE, null);
|
||||
$oDataset2 = \AppDelegationPeer::doSelectRS($oCriteria);
|
||||
$oDataset2->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset2->next();
|
||||
$aRow3 = $oDataset2->getRow();
|
||||
if ($aRow3) {
|
||||
$aRow2['FINISH'] = '';
|
||||
}
|
||||
if (empty($aRow2["FINISH"]) && $aRow1["TAS_UID"] == $sTask) {
|
||||
$oTask->color = "#FF0000"; //Red
|
||||
} else {
|
||||
if (!empty($aRow2["FINISH"])) {
|
||||
$oTask->color = "#006633"; //Green
|
||||
} else {
|
||||
if ($oTask->routing->rou_type != 5) {
|
||||
if ($aRow2["CANT"] != 0) {
|
||||
$oTask->color = "#FF0000"; //Red
|
||||
} else {
|
||||
$oTask->color = "#939598"; //Gray
|
||||
}
|
||||
} else {
|
||||
$oTask->color = "#FF9900"; //Yellow
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$oPM[] = $oTask;
|
||||
$oDataset->next();
|
||||
}
|
||||
return $oPM;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,7 +352,9 @@ class WebEntry
|
||||
|
||||
switch ($webEntryMethod) {
|
||||
case "WS":
|
||||
$user = new \Users();
|
||||
require_once(PATH_RBAC . "model" . PATH_SEP . "RbacUsers.php");
|
||||
|
||||
$user = new \RbacUsers();
|
||||
|
||||
$arrayUserData = $user->load($arrayWebEntryData["USR_UID"]);
|
||||
|
||||
@@ -398,7 +400,7 @@ class WebEntry
|
||||
$template->assign("dynaformUid", $dynaFormUid);
|
||||
$template->assign("taskUid", $taskUid);
|
||||
$template->assign("wsUser", $usrUsername);
|
||||
$template->assign("wsPass", "md5:" . md5($usrPassword));
|
||||
$template->assign("wsPass", "md5:" . $usrPassword);
|
||||
$template->assign("wsRoundRobin", $wsRoundRobin);
|
||||
|
||||
if ($webEntryInputDocumentAccess == 0) {
|
||||
|
||||
@@ -116,7 +116,7 @@ abstract class Exporter
|
||||
? "" : serialize($workflowData["process"]['PRO_DYNAFORMS']);
|
||||
|
||||
$workflowData["process"] = array($workflowData["process"]);
|
||||
$workflowData["processCategory"] = empty($workflowData["processCategory"]) ? array() : $workflowData["processCategory"];
|
||||
$workflowData["processCategory"] = empty($workflowData["processCategory"]) ? array() : array($workflowData["processCategory"]);
|
||||
|
||||
|
||||
$data["bpmn-definition"] = $bpmnStruct;
|
||||
|
||||
@@ -210,6 +210,10 @@ abstract class Importer
|
||||
throw new \Exception("Error while uploading file. Error code: {$data["error"]}");
|
||||
}
|
||||
|
||||
if (! is_dir($this->getSaveDir())) {
|
||||
Util\Common::mk_dir($this->getSaveDir());
|
||||
}
|
||||
|
||||
$this->filename = $this->getSaveDir() . $data["name"];
|
||||
|
||||
$oldUmask = umask(0);
|
||||
@@ -401,7 +405,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 +422,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 +436,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 +459,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.")));
|
||||
}
|
||||
|
||||
@@ -989,5 +989,22 @@ class Cases extends Api
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /:app_uid/tasks
|
||||
*
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doGetTasks($app_uid)
|
||||
{
|
||||
try {
|
||||
$cases = new \ProcessMaker\BusinessModel\Cases();
|
||||
$oData = $cases->getTasks($app_uid);
|
||||
return $oData;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class Project extends Api
|
||||
$fileExtension = pathinfo($outputFilename, PATHINFO_EXTENSION);
|
||||
|
||||
$httpStream->loadFromFile($outputFilename);
|
||||
$httpStream->setHeader("Content-Type", "application/$fileExtension");
|
||||
$httpStream->setHeader("Content-Type", "application/xml; charset=UTF-8");
|
||||
$httpStream->send();
|
||||
}
|
||||
|
||||
@@ -136,6 +136,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"));
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
<?php
|
||||
namespace Tests\ProcessMaker\Exporter;
|
||||
|
||||
use \ProcessMaker\Project;
|
||||
use \ProcessMaker\Exporter;
|
||||
|
||||
if (! class_exists("Propel")) {
|
||||
include_once __DIR__ . "/../../bootstrap.php";
|
||||
if (!class_exists("Propel")) {
|
||||
include_once(__DIR__ . "/../../bootstrap.php");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -16,10 +13,154 @@ if (! class_exists("Propel")) {
|
||||
*/
|
||||
class XmlExporterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testExport()
|
||||
protected static $exporter;
|
||||
protected static $projectUid = "";
|
||||
protected static $filePmx = "";
|
||||
|
||||
/**
|
||||
* Set class for test
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$exporter = new Exporter\XmlExporter("4857540205310b25f3d51a5020772457");
|
||||
$exporter->build();
|
||||
$exporter->saveExport("/home/erik/out.xml");
|
||||
$json = "
|
||||
{
|
||||
\"prj_name\": \"" . \ProcessMaker\Util\Common::generateUID() . "\",
|
||||
\"prj_author\": \"00000000000000000000000000000001\",
|
||||
\"diagrams\": [
|
||||
{
|
||||
\"dia_uid\": \"\",
|
||||
\"activities\": [],
|
||||
\"events\": [],
|
||||
\"gateways\": [],
|
||||
\"flows\": [],
|
||||
\"artifacts\": [],
|
||||
\"laneset\": [],
|
||||
\"lanes\": []
|
||||
}
|
||||
]
|
||||
}
|
||||
";
|
||||
|
||||
$arrayResult = \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct(json_decode($json, true));
|
||||
|
||||
self::$projectUid = $arrayResult[0]["new_uid"];
|
||||
self::$filePmx = PATH_DOCUMENT . "output" . PATH_SEP . self::$projectUid . ".pmx";
|
||||
|
||||
self::$exporter = new \ProcessMaker\Exporter\XmlExporter(self::$projectUid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete project
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
$bpmnWf = \ProcessMaker\Project\Adapter\BpmnWorkflow::load(self::$projectUid);
|
||||
$bpmnWf->remove();
|
||||
|
||||
unlink(self::$filePmx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test export
|
||||
*
|
||||
* @covers \ProcessMaker\Exporter\XmlExporter::export
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function testExport()
|
||||
{
|
||||
$strXml = self::$exporter->export();
|
||||
|
||||
$this->assertTrue(is_string($strXml));
|
||||
$this->assertNotEmpty($strXml);
|
||||
|
||||
return $strXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build
|
||||
*
|
||||
* @covers \ProcessMaker\Exporter\XmlExporter::build
|
||||
*
|
||||
* @depends testExport
|
||||
* @param string $strXml Data xml
|
||||
*/
|
||||
public function testBuild($strXml)
|
||||
{
|
||||
//DOMDocument
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadXML($strXml);
|
||||
|
||||
$nodeRoot = $doc->getElementsByTagName("ProcessMaker-Project")->item(0);
|
||||
$uid = "";
|
||||
|
||||
//Node meta
|
||||
$nodeMeta = $nodeRoot->getElementsByTagName("metadata")->item(0)->getElementsByTagName("meta");
|
||||
|
||||
$this->assertNotEmpty($nodeMeta);
|
||||
|
||||
foreach ($nodeMeta as $value) {
|
||||
$node = $value;
|
||||
|
||||
if ($node->hasAttribute("key") && $node->getAttribute("key") == "uid") {
|
||||
$uid = $node->nodeValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals(self::$projectUid, $uid);
|
||||
|
||||
//Node definition
|
||||
$nodeDefinition = $nodeRoot->getElementsByTagName("definition");
|
||||
|
||||
$this->assertNotEmpty($nodeDefinition);
|
||||
|
||||
foreach ($nodeDefinition as $value) {
|
||||
$node = $value;
|
||||
|
||||
if ($node->hasAttribute("class")) {
|
||||
$this->assertContains($node->getAttribute("class"), array("BPMN", "workflow"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test saveExport
|
||||
*
|
||||
* @covers \ProcessMaker\Exporter\XmlExporter::saveExport
|
||||
*/
|
||||
public function testSaveExport()
|
||||
{
|
||||
self::$exporter->saveExport(self::$filePmx);
|
||||
|
||||
$this->assertTrue(file_exists(self::$filePmx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getTextNode
|
||||
*
|
||||
* @covers \ProcessMaker\Exporter\XmlExporter::getTextNode
|
||||
*/
|
||||
public function testGetTextNode()
|
||||
{
|
||||
//Is not implemented. Method getTextNode() is private
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid project uid
|
||||
*
|
||||
* @covers \ProcessMaker\Exporter\XmlExporter::__construct
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Project "ProcessMaker\Project\Bpmn" with UID: 0, does not exist.
|
||||
*/
|
||||
public function test__constructExceptionInvalidProjectUid()
|
||||
{
|
||||
$exporter = new \ProcessMaker\Exporter\XmlExporter("0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
namespace Tests\ProcessMaker\Importer;
|
||||
|
||||
if (!class_exists("Propel")) {
|
||||
include_once(__DIR__ . "/../../bootstrap.php");
|
||||
}
|
||||
|
||||
/**
|
||||
* Class XmlImporterTest
|
||||
*
|
||||
* @package Tests\ProcessMaker\Project
|
||||
*/
|
||||
class XmlImporterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $importer;
|
||||
protected static $projectUid = "";
|
||||
protected static $filePmx = "";
|
||||
|
||||
protected static $arrayPrjUid = array();
|
||||
|
||||
/**
|
||||
* Set class for test
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$json = "
|
||||
{
|
||||
\"prj_name\": \"" . \ProcessMaker\Util\Common::generateUID() . "\",
|
||||
\"prj_author\": \"00000000000000000000000000000001\",
|
||||
\"diagrams\": [
|
||||
{
|
||||
\"dia_uid\": \"\",
|
||||
\"activities\": [],
|
||||
\"events\": [],
|
||||
\"gateways\": [],
|
||||
\"flows\": [],
|
||||
\"artifacts\": [],
|
||||
\"laneset\": [],
|
||||
\"lanes\": []
|
||||
}
|
||||
]
|
||||
}
|
||||
";
|
||||
|
||||
$arrayResult = \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct(json_decode($json, true));
|
||||
|
||||
self::$projectUid = $arrayResult[0]["new_uid"];
|
||||
self::$filePmx = PATH_DOCUMENT . "input" . PATH_SEP . self::$projectUid . ".pmx";
|
||||
|
||||
$exporter = new \ProcessMaker\Exporter\XmlExporter(self::$projectUid);
|
||||
$exporter->saveExport(self::$filePmx);
|
||||
|
||||
$bpmnWf = \ProcessMaker\Project\Adapter\BpmnWorkflow::load(self::$projectUid);
|
||||
$bpmnWf->remove();
|
||||
|
||||
self::$importer = new \ProcessMaker\Importer\XmlImporter();
|
||||
self::$importer->setSourceFile(self::$filePmx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete projects
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
foreach (self::$arrayPrjUid as $value) {
|
||||
$prjUid = $value;
|
||||
|
||||
$bpmnWf = \ProcessMaker\Project\Adapter\BpmnWorkflow::load($prjUid);
|
||||
$bpmnWf->remove();
|
||||
}
|
||||
|
||||
unlink(self::$filePmx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test load
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::load
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
$arrayData = self::$importer->load();
|
||||
|
||||
$this->assertTrue(is_array($arrayData));
|
||||
$this->assertNotEmpty($arrayData);
|
||||
|
||||
$this->assertArrayHasKey("tables", $arrayData);
|
||||
$this->assertArrayHasKey("files", $arrayData);
|
||||
|
||||
$this->assertEquals($arrayData["tables"]["bpmn"]["project"][0]["prj_uid"], self::$projectUid);
|
||||
$this->assertEquals($arrayData["tables"]["workflow"]["process"][0]["PRO_UID"], self::$projectUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getTextNode
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::getTextNode
|
||||
*/
|
||||
public function testGetTextNode()
|
||||
{
|
||||
//Is not implemented. Method getTextNode() is private
|
||||
}
|
||||
|
||||
/**
|
||||
* Test import
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::import
|
||||
*/
|
||||
public function testImport()
|
||||
{
|
||||
$prjUid = self::$importer->import();
|
||||
self::$arrayPrjUid[] = $prjUid;
|
||||
|
||||
$this->assertNotNull(\BpmnProjectPeer::retrieveByPK($prjUid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test importPostFile
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::importPostFile
|
||||
*/
|
||||
public function testImportPostFile()
|
||||
{
|
||||
self::$importer->setSaveDir(PATH_DOCUMENT . "input");
|
||||
|
||||
$arrayData = self::$importer->importPostFile(array("PROJECT_FILE" => self::$projectUid . ".pmx"), "KEEP");
|
||||
self::$arrayPrjUid[] = $arrayData["PRJ_UID"];
|
||||
|
||||
$this->assertNotNull(\BpmnProjectPeer::retrieveByPK($arrayData["PRJ_UID"]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception when the project exists
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::import
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Project already exists, you need set an action to continue. Available actions: [project.import.create_new|project.import.override|project.import.disable_and_create_new|project.import.keep_without_changing_and_create_new].
|
||||
*/
|
||||
public function testImportExceptionProjectExists()
|
||||
{
|
||||
$prjUid = self::$importer->import();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for empty data
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::importPostFile
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for "$arrayData", it can not be empty.
|
||||
*/
|
||||
public function testImportPostFileExceptionEmptyData()
|
||||
{
|
||||
$arrayData = self::$importer->importPostFile(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid extension
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::importPostFile
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The file extension not is "pmx"
|
||||
*/
|
||||
public function testImportPostFileExceptionInvalidExtension()
|
||||
{
|
||||
$arrayData = self::$importer->importPostFile(array("PROJECT_FILE" => "file.pm"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for file does not exist
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::importPostFile
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The file with PROJECT_FILE: "file.pmx" does not exist.
|
||||
*/
|
||||
public function testImportPostFileExceptionFileNotExists()
|
||||
{
|
||||
$arrayData = self::$importer->importPostFile(array("PROJECT_FILE" => "file.pmx"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid option
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::importPostFile
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for "OPTION", it only accepts values: "CREATE|OVERWRITE|DISABLE|KEEP".
|
||||
*/
|
||||
public function testImportPostFileExceptionInvalidOption()
|
||||
{
|
||||
$arrayData = self::$importer->importPostFile(array("PROJECT_FILE" => "file.pmx"), "CREATED");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception when the project exists
|
||||
*
|
||||
* @covers \ProcessMaker\Importer\XmlImporter::importPostFile
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Project already exists, you need set an action to continue. Available actions: [CREATE|OVERWRITE|DISABLE|KEEP].
|
||||
*/
|
||||
public function testImportPostFileExceptionProjectExists()
|
||||
{
|
||||
self::$importer->setSaveDir(PATH_DOCUMENT . "input");
|
||||
|
||||
$arrayData = self::$importer->importPostFile(array("PROJECT_FILE" => self::$projectUid . ".pmx"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user