More Bpmn/Workflow handling layer refactoring and improve unit tests

This commit is contained in:
Erik Amaru Ortiz
2014-02-05 11:39:15 -04:00
parent ee480a93e3
commit 47f991034f
12 changed files with 662 additions and 404 deletions

View File

@@ -382,6 +382,7 @@ class Bootstrap
self::registerClass("IsoLocation", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "IsoLocation.php");
self::registerClass("Users", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
self::registerClass("UsersPeer", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "UsersPeer.php");
self::registerClass("ReportTables", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.reportTables.php");
self::registerClass("Xml_Node", PATH_GULLIVER . "class.xmlDocument.php");

View File

@@ -303,7 +303,7 @@ class G
/**
* ************* path functions ****************
*/
public function mk_dir ($strPath, $rights = 0770)
public static function mk_dir ($strPath, $rights = 0770)
{
$folder_path = array ($strPath);
$oldumask = umask( 0 );
@@ -444,7 +444,7 @@ class G
* @param string $strPath
* @return string
*/
public function expandPath ($strPath = '')
public static function expandPath ($strPath = '')
{
$res = "";
$res = PATH_CORE;
@@ -462,7 +462,7 @@ class G
* @param string $strClass
* @return void
*/
public function LoadSystem ($strClass)
public static function LoadSystem ($strClass)
{
require_once (PATH_GULLIVER . 'class.' . $strClass . '.php');
}
@@ -689,7 +689,7 @@ class G
* @param string $strClass
* @return void
*/
public function LoadClass ($strClass)
public static function LoadClass ($strClass)
{
$classfile = G::ExpandPath( "classes" ) . 'class.' . $strClass . '.php';
if (! file_exists( $classfile )) {

View File

@@ -25,9 +25,9 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/* SOAP NTLM
* This class is used to extend SoapClient native PHP
* to allow NTLM authentication throw soap connection
/* SOAP NTLM
* This class is used to extend SoapClient native PHP
* to allow NTLM authentication throw soap connection
*/
/**
@@ -64,8 +64,8 @@ class soapNtlm
*/
public function stream_open ($path, $mode, $options, $opened_path)
{
//echo "[NTLMStream::stream_open] $path , mode=$mode <br>";
//G::pr($options);
//echo "[NTLMStream::stream_open] $path , mode=$mode <br>";
//G::pr($options);
$this->path = $path;
$this->mode = $mode;
$this->options = $options;
@@ -79,7 +79,7 @@ class soapNtlm
*/
public function stream_close ()
{
//echo "[NTLMStream::stream_close] <br>";
//echo "[NTLMStream::stream_close] <br>";
curl_close( $this->ch );
}
@@ -91,7 +91,7 @@ class soapNtlm
*/
public function stream_read ($count)
{
//echo "[NTLMStream::stream_read] $count <br>";
//echo "[NTLMStream::stream_read] $count <br>";
if (strlen( $this->buffer ) == 0) {
return false;
}
@@ -108,7 +108,7 @@ class soapNtlm
*/
public function stream_write ($data)
{
//echo "[NTLMStream::stream_write] <br>";
//echo "[NTLMStream::stream_write] <br>";
if (strlen( $this->buffer ) == 0) {
return false;
}
@@ -121,12 +121,12 @@ class soapNtlm
*/
public function stream_eof ()
{
//echo "[NTLMStream::stream_eof] ";
//echo "[NTLMStream::stream_eof] ";
if ($this->pos > strlen( $this->buffer )) {
//echo "true <br>";
//echo "true <br>";
return true;
}
//echo "false <br>";
//echo "false <br>";
return false;
}
@@ -136,7 +136,7 @@ class soapNtlm
*/
public function stream_tell ()
{
//echo "[NTLMStream::stream_tell] <br>";
//echo "[NTLMStream::stream_tell] <br>";
return $this->pos;
}
@@ -145,7 +145,7 @@ class soapNtlm
*/
public function stream_flush ()
{
//echo "[NTLMStream::stream_flush] <br>";
//echo "[NTLMStream::stream_flush] <br>";
$this->buffer = null;
$this->pos = null;
}
@@ -157,7 +157,7 @@ class soapNtlm
*/
public function stream_stat ()
{
//echo "[NTLMStream::stream_stat] <br>";
//echo "[NTLMStream::stream_stat] <br>";
$this->createBuffer( $this->path );
$stat = array ('size' => strlen( $this->buffer ));
return $stat;
@@ -170,8 +170,8 @@ class soapNtlm
*/
public function url_stat ($path, $flags)
{
//G::pr($this->options);
//echo "[NTLMStream::url_stat] -> $path <br>";
//G::pr($this->options);
//echo "[NTLMStream::url_stat] -> $path <br>";
$this->createBuffer( $path );
$stat = array ('size' => strlen( $this->buffer ));
return $stat;
@@ -188,14 +188,14 @@ class soapNtlm
return;
}
//echo "[NTLMStream::createBuffer] create buffer from : $path <br>";
//echo "[NTLMStream::createBuffer] create buffer from : $path <br>";
$this->ch = curl_init( $path );
curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
curl_setopt( $this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
//curl_setopt($this->ch, CURLOPT_USERPWD, $this->options['auth']); // Hugo's code
curl_setopt( $this->ch, CURLOPT_USERPWD, $this->getuser() . ':' . $this->getpassword() ); // Ankit's code
//Apply proxy settings
//curl_setopt($this->ch, CURLOPT_USERPWD, $this->options['auth']); // Hugo's code
curl_setopt( $this->ch, CURLOPT_USERPWD, $this->getuser() . ':' . $this->getpassword() ); // Ankit's code
//Apply proxy settings
if (class_exists( 'System' )) {
$sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') {
@@ -210,7 +210,7 @@ class soapNtlm
}
}
echo $this->buffer = curl_exec( $this->ch );
//echo "[NTLMStream::createBuffer] buffer size : " . strlen($this->buffer) . "bytes<br>";
//echo "[NTLMStream::createBuffer] buffer size : " . strlen($this->buffer) . "bytes<br>";
$this->pos = 0;
}
@@ -218,7 +218,7 @@ class soapNtlm
class NTLMSoapClient extends SoapClient
{
function __doRequest ($request, $location, $action, $version)
function __doRequest ($request, $location, $action, $version, $one_way = 0)
{
$headers = array ('Method: POST','Connection: Keep-Alive','User-Agent: PHP-SOAP-CURL','Content-Type: text/xml; charset=utf-8','SOAPAction: "' . $action . '"');
@@ -232,10 +232,10 @@ class NTLMSoapClient extends SoapClient
curl_setopt( $ch, CURLOPT_POSTFIELDS, $request );
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
//curl_setopt($ch, CURLOPT_USERPWD, $this->options['auth']); //Hugo's Code
curl_setopt( $ch, CURLOPT_USERPWD, $this->user . ':' . $this->password ); //Ankit's Code
//curl_setopt($ch, CURLOPT_USERPWD, $this->options['auth']); //Hugo's Code
curl_setopt( $ch, CURLOPT_USERPWD, $this->user . ':' . $this->password ); //Ankit's Code
//Apply proxy settings
//Apply proxy settings
if (class_exists( 'System' )) {
$sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') {

View File

@@ -1141,7 +1141,7 @@ class System
return $result;
}
public function solrEnv ($sysName = '')
public static function solrEnv ($sysName = '')
{
if (empty( $sysName )) {
$conf = System::getSystemConfiguration();

View File

@@ -0,0 +1,20 @@
<?php
namespace ProcessMaker\Exception;
use ProcessMaker\Project;
class ProjectNotFound extends \RuntimeException
{
const EXCEPTION_CODE = 20;
public function __construct(Project\Handler $obj, $uid, $message = "", \Exception $previous = null) {
$message = empty($message) ? sprintf("Project \"%s\" with UID: %s, does not exist.", get_class($obj), $uid) : $message;
parent::__construct($message, self::EXCEPTION_CODE, $previous);
}
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
}

View File

@@ -27,20 +27,11 @@ use \BpmnArtifactPeer as ArtifactPeer;
use \BasePeer;
use ProcessMaker\Project\ProjectHandler;
use ProcessMaker\Util\Hash;
use ProcessMaker\Exception;
class BpmnProject //extends ProjectHandler
class Bpmn extends Handler
{
protected static $diagramElements = array(
'activities' => 'act_uid',
'events' => 'evn_uid',
'flows' => 'flo_uid',
'artifacts' => 'art_uid',
'laneset' => 'lns_uid',
'lanes' => 'lan_uid'
);
/**
* @var \BpmnProject
*/
@@ -68,13 +59,13 @@ class BpmnProject //extends ProjectHandler
public static function load($prjUid)
{
$me = new self();
$project = ProjectPeer::retrieveByPK($prjUid);
if (! is_object($project)) {
return null;
throw new Exception\ProjectNotFound($me, $prjUid);
}
$me = new BpmnProject();
$me->project = $project;
$me->prjUid = $me->project->getPrjUid();
@@ -82,7 +73,7 @@ class BpmnProject //extends ProjectHandler
}
/**
* @param array|null $data optional array attributes to create and initialize a BpmnProject
* @param array| $data array attributes to create and initialize a BpmnProject
*/
public function create($data)
{

View File

@@ -3,11 +3,17 @@ namespace ProcessMaker\Project;
use ProcessMaker\Util\Logger;
abstract class ProjectHandler //implements ProjectHandlerInterface
abstract class Handler
{
public abstract function save();
public abstract function update();
public abstract function delete();
public static function load($uid)
{ // This method must be implemented on children classes, this is not declared abstract since PHP 5.3.x
// don't allow any more static abstract methods.
return null;
}
public abstract function create($data);
//public abstract function update();
public abstract function remove();
/**
* Log in ProcessMaker Standard Output if debug mode is enabled.

View File

@@ -1,10 +0,0 @@
<?php
namespace ProcessMaker\Project;
interface ProjectHandlerInterface
{
public function save();
public function update();
public function delete();
public static function load();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +1,25 @@
<?php
namespace Tests\ProcessMaker\Project;
use \ProcessMaker\Project;
if (! class_exists("Propel")) {
include_once __DIR__ . "/../bootstrap.php";
}
use ProcessMaker\Project\BpmnProject;
class BpmnProjectTest extends PHPUnit_Framework_TestCase
class BpmnTest extends \PHPUnit_Framework_TestCase
{
protected static $prjUid;
protected static $prjUids = array();
public static function tearDownAfterClass()
{
$bp = BpmnProject::load(self::$prjUid);
$bp->remove();
//cleaning DB
foreach (self::$prjUids as $prjUid) {
$bp = Project\Bpmn::load($prjUid);
$bp->remove();
}
}
public function testCreate()
@@ -24,10 +30,10 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
"PRJ_AUTHOR" => "00000000000000000000000000000001"
);
// Create a new BpmnProject and save to DB
$bp = new BpmnProject($data);
// Create a new Project\Bpmn and save to DB
$bp = new Project\Bpmn($data);
$projectData = $bp->getProject();
self::$prjUid = $bp->getUid();
self::$prjUids[] = $bp->getUid();
foreach ($data as $key => $value) {
$this->assertEquals($value, $projectData[$key]);
@@ -38,7 +44,7 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testCreate
* @var $bp \ProcessMaker\Project\BpmnProject
* @var $bp \ProcessMaker\Project\Bpmn
*/
public function testAddDiagram($bp)
{
@@ -58,7 +64,7 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testCreate
* @var $bp \ProcessMaker\Project\BpmnProject
* @var $bp \ProcessMaker\Project\Bpmn
*/
public function testAddProcess($bp)
{
@@ -81,7 +87,7 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testCreate
* @var $bp \ProcessMaker\Project\BpmnProject
* @var $bp \ProcessMaker\Project\Bpmn
*/
public function testAddActivity($bp)
{
@@ -112,7 +118,7 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testCreate
* @param $bp \ProcessMaker\Project\BpmnProject
* @param $bp \ProcessMaker\Project\Bpmn
* @return array
*/
public function testAddActivityWithUid($bp)
@@ -146,7 +152,7 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testCreate
* @depends testAddActivityWithUid
* @param $bp \ProcessMaker\Project\BpmnProject
* @param $bp \ProcessMaker\Project\Bpmn
* @param $data
*/
public function testGetActivity($bp, $data)
@@ -166,7 +172,7 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testCreate
* @depends testAddActivityWithUid
* @param $bp \ProcessMaker\Project\BpmnProject
* @param $bp \ProcessMaker\Project\Bpmn
* @param $data
*/
public function testRemoveActivity($bp, $data)
@@ -180,8 +186,8 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
public function testGetActivities()
{
// Create a new BpmnProject and save to DB
$bp = new BpmnProject(array(
// Create a new Project\Bpmn and save to DB
$bp = new Project\Bpmn(array(
"PRJ_NAME" => "Test BPMN Project #2",
"PRJ_DESCRIPTION" => "Description for - Test BPMN Project #1",
"PRJ_AUTHOR" => "00000000000000000000000000000001"
@@ -211,13 +217,13 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testGetActivities
* @param $bp \ProcessMaker\Project\BpmnProject
* @return null|\ProcessMaker\Project\BpmnProject
* @param $bp \ProcessMaker\Project\Bpmn
* @return null|\ProcessMaker\Project\Bpmn
*/
public function testLoad($bp)
{
$prjUid = $bp->getUid();
$bp2 = BpmnProject::load($prjUid);
$bp2 = Project\Bpmn::load($prjUid);
$this->assertNotNull($bp2);
$this->assertEquals($bp->getActivities(), $bp2->getActivities());
@@ -229,14 +235,16 @@ class BpmnProjectTest extends PHPUnit_Framework_TestCase
/**
* @depends testLoad
* @param $bp \ProcessMaker\Project\BpmnProject
* @param $bp \ProcessMaker\Project\Bpmn
* @expectedException \ProcessMaker\Exception\ProjectNotFound
* @expectedExceptionCode 20
*/
public function testRemove($bp)
{
$prjUid = $bp->getUid();
$bp->remove();
$this->assertNull(BpmnProject::load($prjUid));
Project\Bpmn::load($prjUid);
}
}

View File

@@ -1,19 +1,23 @@
<?php
namespace Tests\ProcessMaker\Project;
use \ProcessMaker\Project;
if (! class_exists("Propel")) {
include_once __DIR__ . "/../bootstrap.php";
}
use \ProcessMaker\Project\WorkflowProject;
class WorkflowProjectTest extends PHPUnit_Framework_TestCase
class ProcessMakerProjectWorkflowTest extends \PHPUnit_Framework_TestCase
{
protected $workflowProject;
protected static $proUids = array();
protected function setUp()
public static function tearDownAfterClass()
{
$this->workflowProject = new WorkflowProject();
//cleaning DB
foreach (self::$proUids as $proUid) {
$wp = Project\Workflow::load($proUid);
$wp->remove();
}
}
public function testCreate()
@@ -25,9 +29,10 @@ class WorkflowProjectTest extends PHPUnit_Framework_TestCase
"PRO_CREATE_USER" => "00000000000000000000000000000001"
);
$wp = new WorkflowProject($data);
$wp = new Project\Workflow($data);
self::$proUids[] = $wp->getUid();
$processData = $wp->getProperties();
$processData = $wp->getProcess();
foreach ($data as $key => $value) {
$this->assertEquals($data[$key], $processData[$key]);
@@ -149,11 +154,13 @@ class WorkflowProjectTest extends PHPUnit_Framework_TestCase
*/
public function testAddRoute()
{
$wp = new WorkflowProject(array(
$wp = new Project\Workflow(array(
"PRO_TITLE" => "Test Project #2 (Sequential)",
"PRO_CREATE_USER" => "00000000000000000000000000000001"
));
self::$proUids[] = $wp->getUid();
$tasUid1 = $wp->addTask(array(
"TAS_TITLE" => "task #1",
"TAS_POSX" => "410",
@@ -176,10 +183,11 @@ class WorkflowProjectTest extends PHPUnit_Framework_TestCase
public function testAddSelectRoute()
{
$wp = new WorkflowProject(array(
$wp = new Project\Workflow(array(
"PRO_TITLE" => "Test Project #3 (Select)",
"PRO_CREATE_USER" => "00000000000000000000000000000001"
));
self::$proUids[] = $wp->getUid();
$tasUid1 = $wp->addTask(array(
"TAS_TITLE" => "task #1",
@@ -202,7 +210,7 @@ class WorkflowProjectTest extends PHPUnit_Framework_TestCase
public function testCompleteWorkflowProject()
{
$wp = new WorkflowProject(array(
$wp = new Project\Workflow(array(
"PRO_TITLE" => "Test Complete Project #4",
"PRO_CREATE_USER" => "00000000000000000000000000000001"
));
@@ -253,5 +261,21 @@ class WorkflowProjectTest extends PHPUnit_Framework_TestCase
$wp->setEndTask($tasUid4);
$wp->setEndTask($tasUid6);
return $wp;
}
/**
* @depends testCompleteWorkflowProject
* @param $wp \ProcessMaker\Project\WorkflowProject
* @expectedException \ProcessMaker\Exception\ProjectNotFound
* @expectedExceptionCode 20
*/
public function testRemove($wp)
{
$proUid = $wp->getUid();
$wp->remove();
Project\Workflow::load($proUid);
}
}