Merged colosa/processmaker into master
This commit is contained in:
@@ -30,7 +30,7 @@ try {
|
||||
$exporter = new ProcessMaker\Exporter\XmlExporter($_GET["pro_uid"]);
|
||||
|
||||
$version = ProcessMaker\Util\Common::getLastVersion($outputDir . $exporter->getProjectName() . "-*.pmx") + 1;
|
||||
$outputFilename = sprintf("%s-%s.%s", $exporter->getProjectName(), $version, "pmx");
|
||||
$outputFilename = sprintf("%s-%s.%s", str_replace(" ", "_", $exporter->getProjectName()), $version, "pmx");
|
||||
$exporter->saveExport($outputDir . $outputFilename);
|
||||
} else {
|
||||
$oProcess = new Processes();
|
||||
@@ -134,3 +134,4 @@ echo json_encode($response);
|
||||
// $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
|
||||
// G::RenderPage( 'publish', 'raw' );
|
||||
//}
|
||||
|
||||
|
||||
@@ -700,16 +700,22 @@ class Cases
|
||||
Validator::appUid($app_uid, '$app_uid');
|
||||
Validator::usrUid($usr_uid, '$usr_uid');
|
||||
|
||||
$case = new \Cases();
|
||||
$fields = $case->loadCase($app_uid);
|
||||
if ($fields['APP_STATUS'] == 'CANCELLED') {
|
||||
throw (new \Exception("The case '$app_uid' is canceled"));
|
||||
}
|
||||
|
||||
if ($del_index === false) {
|
||||
$del_index = \AppDelegation::getCurrentIndex($app_uid);
|
||||
}
|
||||
|
||||
Validator::isInteger($del_index, '$del_index');
|
||||
|
||||
if ($unpaused_date != null) {
|
||||
Validator::isDate($unpaused_date, 'Y-m-d', '$unpaused_date');
|
||||
}
|
||||
|
||||
$case = new \Cases();
|
||||
$case->pauseCase( $app_uid, $del_index, $usr_uid, $unpaused_date );
|
||||
}
|
||||
|
||||
@@ -1515,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ class Table
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$dataValidate['TAB_UID'] = (isset($dataValidate['REP_UID'])) ? $dataValidate['REP_UID'] : '';
|
||||
$dataValidate['PRO_UID'] = $pro_uid;
|
||||
$dataValidate['REP_TAB_NAME'] = $this->validateTabName($dataValidate['REP_TAB_NAME']);
|
||||
$dataValidate['REP_TAB_NAME'] = $this->validateTabName($dataValidate['REP_TAB_NAME'], $reportFlag);
|
||||
$tempRepTabName = $dataValidate['REP_TAB_CONNECTION'];
|
||||
$dataValidate['REP_TAB_CONNECTION'] = $this->validateRepConnection($tempRepTabName, $pro_uid);
|
||||
if ($dataValidate['REP_TAB_TYPE'] == 'GRID') {
|
||||
@@ -969,11 +969,12 @@ class Table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateTabName ($rep_tab_name)
|
||||
public function validateTabName ($rep_tab_name, $reportFlag = false)
|
||||
{
|
||||
$rep_tab_name = trim($rep_tab_name);
|
||||
$nametype = ($reportFlag == false) ? 'pmt_tab_name' : 'rep_tab_name';
|
||||
if ((strpos($rep_tab_name, ' ')) || (strlen($rep_tab_name) < 4)) {
|
||||
throw (new \Exception("The property pmt_tab_name: '$rep_tab_name' is incorrect."));
|
||||
throw (new \Exception("The property $nametype: '$rep_tab_name' is incorrect."));
|
||||
}
|
||||
$rep_tab_name = G::toUpper($rep_tab_name);
|
||||
if (substr($rep_tab_name, 0, 4) != 'PMT_') {
|
||||
|
||||
@@ -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.")));
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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