CODE STYLE

files modified:   class.form.php
                  class.functionTest.php
                  class.rbac.php
                  class.restClient.php
                  class.ymlTestCases.php
This commit is contained in:
Ralph Asendeteufrer
2012-10-18 09:27:23 -04:00
parent 05758ea812
commit 5f5388e7b4
5 changed files with 2230 additions and 2110 deletions

View File

@@ -1,6 +1,8 @@
<?php <?php
/** /**
* class.database_base.php * class.database_base.php
*
* @package gulliver.system * @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -25,53 +27,56 @@
*/ */
/** /**
* Class Form * Class Form
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @package gulliver.system * @package gulliver.system
* @access public * @access public
*/ */
class Form extends XmlForm class Form extends XmlForm
{ {
var $id=''; public $id = '';
var $width = 600; public $width = 600;
var $title = ''; public $title = '';
var $fields = array(); public $fields = array ();
var $values = array(); public $values = array ();
var $action = ''; public $action = '';
var $ajaxServer = ''; public $ajaxServer = '';
var $enableTemplate = false; public $enableTemplate = false;
var $ajaxSubmit = false; public $ajaxSubmit = false;
var $callback='function(){}'; public $callback = 'function(){}';
var $in_progress='function(){}'; public $in_progress = 'function(){}';
var $template; public $template;
var $className="formDefault"; public $className = "formDefault";
var $objectRequiredFields = null; public $objectRequiredFields = null;
var $nextstepsave = ''; public $nextstepsave = '';
var $printdynaform = ''; public $printdynaform = '';
var $adjustgridswidth = '0'; public $adjustgridswidth = '0';
public $visual_frontend; public $visual_frontend;
/** /**
* Function setDefaultValues * Function setDefaultValues
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @return string * @return string
*/ */
function setDefaultValues( ) public function setDefaultValues ()
{ {
foreach ($this->fields as $name => $content) { foreach ($this->fields as $name => $content) {
if (is_object( $content ) && get_class( $content ) != '__PHP_Incomplete_Class') { if (is_object( $content ) && get_class( $content ) != '__PHP_Incomplete_Class') {
if (isset($content->defaultValue)) if (isset( $content->defaultValue )) {
$this->values[$name] = $content->defaultValue; $this->values[$name] = $content->defaultValue;
else } else {
$this->values[$name] = ''; $this->values[$name] = '';
} }
else { } else {
$this->values[$name] = ''; $this->values[$name] = '';
} }
} }
foreach ($this->fields as $k => $v) { foreach ($this->fields as $k => $v) {
if (is_object($v)) {//julichu if (is_object( $v )) {
//julichu
$this->fields[$k]->owner = & $this; $this->fields[$k]->owner = & $this;
} }
} }
@@ -79,6 +84,7 @@ class Form extends XmlForm
/** /**
* Function Form * Function Form
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @param string filename * @param string filename
@@ -88,33 +94,40 @@ class Form extends XmlForm
* @param string $visual_frontend * @param string $visual_frontend
* @return string * @return string
*/ */
function Form($filename, $home='', $language = '', $forceParse = false, $visual_frontend=null) public function Form ($filename, $home = '', $language = '', $forceParse = false, $visual_frontend = null)
{ {
$this->visual_frontend = $visual_frontend; $this->visual_frontend = $visual_frontend;
if ($language=== '') if ($language === '') {
$language = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; $language = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
if ($home=== '') }
$home = defined('PATH_XMLFORM')? PATH_XMLFORM : if ($home === '') {
(defined('PATH_DYNAFORM')? PATH_DYNAFORM: ''); $home = defined( 'PATH_XMLFORM' ) ? PATH_XMLFORM : (defined( 'PATH_DYNAFORM' ) ? PATH_DYNAFORM : '');
}
//to do: obtain the error code in case the xml parsing has errors: DONE //to do: obtain the error code in case the xml parsing has errors: DONE
//Load and parse the xml file //Load and parse the xml file
if ( substr($filename, -4) !== '.xml' ) if (substr( $filename, - 4 ) !== '.xml') {
$filename = $filename . '.xml'; $filename = $filename . '.xml';
}
$this->home = $home; $this->home = $home;
$res = parent::parseFile( $filename, $language, $forceParse ); $res = parent::parseFile( $filename, $language, $forceParse );
if ($res==1) if ($res == 1) {
trigger_error( 'Faild to parse file ' . $filename . '.', E_USER_ERROR ); trigger_error( 'Faild to parse file ' . $filename . '.', E_USER_ERROR );
if ($res==2) }
if ($res == 2) {
trigger_error( 'Faild to create cache file "' . $xmlform->parsedFile . '".', E_USER_ERROR ); trigger_error( 'Faild to create cache file "' . $xmlform->parsedFile . '".', E_USER_ERROR );
}
$this->setDefaultValues(); $this->setDefaultValues();
//to do: review if you can use the same form twice. in order to use once or not. //to do: review if you can use the same form twice. in order to use once or not.
//DONE: Use require to be able to use the same xmlform more than once. //DONE: Use require to be able to use the same xmlform more than once.
foreach ($this->fields as $k => $v) { foreach ($this->fields as $k => $v) {
//too memory? but it fails if it's loaded with baneco.xml with SYS_LANG='es' //too memory? but it fails if it's loaded with baneco.xml with SYS_LANG='es'
//NOTE: This fails apparently when class of ($this->fields[$k]) is PHP_Incomplete_Class (because of cache) //NOTE: This fails apparently when class of ($this->fields[$k]) is PHP_Incomplete_Class (because of cache)
if (is_object($v)) {//julichu if (is_object( $v )) {
//julichu
$this->fields[$k]->owner = & $this; $this->fields[$k]->owner = & $this;
if ($this->fields[$k]->type==='grid') $this->fields[$k]->parseFile($home, $language); if ($this->fields[$k]->type === 'grid') {
$this->fields[$k]->parseFile( $home, $language );
}
} }
} }
$this->template = PATH_CORE . 'templates/' . $this->type . '.html'; $this->template = PATH_CORE . 'templates/' . $this->type . '.html';
@@ -122,23 +135,24 @@ class Form extends XmlForm
/** /**
* Function printTemplate * Function printTemplate
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @param string template * @param string template
* @param string scriptContent * @param string scriptContent
* @return string * @return string
*/ */
function printTemplate( $template, &$scriptContent ) public function printTemplate ($template, &$scriptContent)
{ {
if (! file_exists( $template )) { if (! file_exists( $template )) {
throw (new Exception( 'Template "' . basename( $template ) . '" doesn`t exist.' )); throw (new Exception( 'Template "' . basename( $template ) . '" doesn`t exist.' ));
} }
$o = new xmlformTemplate( $this, $template ); $o = new xmlformTemplate( $this, $template );
if (is_array(reset($this->values))) if (is_array( reset( $this->values ) )) {
$this->rows = count( reset( $this->values ) ); $this->rows = count( reset( $this->values ) );
}
if ($this->enableTemplate) { if ($this->enableTemplate) {
$filename = substr($this->fileName , 0, -3) . $filename = substr( $this->fileName, 0, - 3 ) . ($this->type === 'xmlform' ? '' : '.' . $this->type) . 'html';
( $this->type==='xmlform' ? '' : '.' . $this->type ) . 'html';
if (! file_exists( $filename )) { if (! file_exists( $filename )) {
$o->template = $o->printTemplate( $this ); $o->template = $o->printTemplate( $this );
$f = fopen( $filename, 'w+' ); $f = fopen( $filename, 'w+' );
@@ -154,15 +168,17 @@ class Form extends XmlForm
/** /**
* Function render * Function render
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @param string template * @param string template
* @param string scriptContent * @param string scriptContent
* @return string * @return string
*/ */
function render( $template, &$scriptContent ) public function render ($template, &$scriptContent)
{ {
/*** /**
* *
* This section was added for store the current used template. * This section was added for store the current used template.
*/ */
$tmp_var = explode( '/', $template ); $tmp_var = explode( '/', $template );
@@ -170,13 +186,15 @@ class Form extends XmlForm
$tmp_var = $tmp_var[sizeof( $tmp_var ) - 1]; $tmp_var = $tmp_var[sizeof( $tmp_var ) - 1];
$this->using_template = $tmp_var; $this->using_template = $tmp_var;
} }
/***/ /**
*/
$this->template = $template; $this->template = $template;
$o = new xmlformTemplate( $this, $template ); $o = new xmlformTemplate( $this, $template );
$values = $this->values; $values = $this->values;
$aValuekeys = array_keys( $values ); $aValuekeys = array_keys( $values );
if (isset($aValuekeys[0]) && ((int)$aValuekeys[0]==1)) if (isset( $aValuekeys[0] ) && ((int) $aValuekeys[0] == 1)) {
$values = XmlForm_Field_Grid::flipValues( $values ); $values = XmlForm_Field_Grid::flipValues( $values );
}
//TODO: Review when $values of a grid has only one row it is converted as a $values for a list (when template="grid" at addContent()) //TODO: Review when $values of a grid has only one row it is converted as a $values for a list (when template="grid" at addContent())
if (is_array( reset( $values ) )) { if (is_array( reset( $values ) )) {
$this->rows = count( reset( $values ) ); $this->rows = count( reset( $values ) );
@@ -200,12 +218,13 @@ class Form extends XmlForm
/** /**
* Function setValues * Function setValues
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @param array $newValues * @param array $newValues
* @return string * @return string
*/ */
function setValues($newValues=array()) public function setValues ($newValues = array())
{ {
if (! is_array( $newValues )) { if (! is_array( $newValues )) {
return; return;
@@ -215,19 +234,23 @@ class Form extends XmlForm
if (is_array( $newValues[$k] )) { if (is_array( $newValues[$k] )) {
$this->values[$k] = array (); $this->values[$k] = array ();
foreach ($newValues[$k] as $j => $item) { foreach ($newValues[$k] as $j => $item) {
if ($this->fields[$k]->validateValue($newValues[$k][$j], $this )) if ($this->fields[$k]->validateValue( $newValues[$k][$j], $this )) {
$this->values[$k][$j] = $newValues[$k][$j]; $this->values[$k][$j] = $newValues[$k][$j];
} }
if ((sizeof($this->values[$k])===1) && ($v->type!=='grid') && isset($this->values[$k][0]) ) }
if ((sizeof( $this->values[$k] ) === 1) && ($v->type !== 'grid') && isset( $this->values[$k][0] )) {
$this->values[$k] = $this->values[$k][0]; $this->values[$k] = $this->values[$k][0];
if (sizeof($this->values[$k])===0) }
if (sizeof( $this->values[$k] ) === 0) {
$this->values[$k] = ''; $this->values[$k] = '';
}
} else { } else {
if ($this->fields[$k]->validateValue($newValues[$k], $this )) if ($this->fields[$k]->validateValue( $newValues[$k], $this )) {
$this->values[$k] = $newValues[$k]; $this->values[$k] = $newValues[$k];
} }
} }
} }
}
foreach ($newValues as $k => $v) { foreach ($newValues as $k => $v) {
if (strpos( $k, 'SYS_GRID_AGGREGATE_' ) !== false) { if (strpos( $k, 'SYS_GRID_AGGREGATE_' ) !== false) {
$this->values[$k] = $newValues[$k]; $this->values[$k] = $newValues[$k];
@@ -258,20 +281,22 @@ class Form extends XmlForm
$nLabelWidth = (int) $this->labelWidth; $nLabelWidth = (int) $this->labelWidth;
} }
// krumo($nWidth,$nLabelWidth); // krumo($nWidth,$nLabelWidth);
if(($nWidth - $nLabelWidth) > 0) if (($nWidth - $nLabelWidth) > 0) {
$this->fieldContentWidth = (int) ($nWidth - $nLabelWidth); $this->fieldContentWidth = (int) ($nWidth - $nLabelWidth);
} }
} }
}
/** /**
* Function getFields * Function getFields
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @param string template * @param string template
* @param int $therow * @param int $therow
* @return string * @return string
*/ */
function getFields($template, $therow = -1) public function getFields ($template, $therow = -1)
{ {
$o = new xmlformTemplate( $this, $template ); $o = new xmlformTemplate( $this, $template );
return $o->getFields( $this, $therow ); return $o->getFields( $this, $therow );
@@ -279,11 +304,12 @@ class Form extends XmlForm
/** /**
* Function that validates the values retrieved in $_POST * Function that validates the values retrieved in $_POST
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @return array $_POST['form'] * @return array $_POST['form']
*/ */
function validatePost() public function validatePost ()
{ {
$_POST['form'] = $this->validateFields( $_POST['form'] ); $_POST['form'] = $this->validateFields( $_POST['form'] );
return $_POST['form'] = $this->validateArray( $_POST['form'] ); return $_POST['form'] = $this->validateArray( $_POST['form'] );
@@ -292,12 +318,13 @@ class Form extends XmlForm
/** /**
* Function that validates the values retrieved in an Array: * Function that validates the values retrieved in an Array:
* ex $_POST['form'] * ex $_POST['form']
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public * @access public
* @param array $newValues * @param array $newValues
* @return array * @return array
*/ */
function validateArray($newValues) public function validateArray ($newValues)
{ {
$values = array (); $values = array ();
foreach ($this->fields as $k => $v) { foreach ($this->fields as $k => $v) {
@@ -310,14 +337,11 @@ class Form extends XmlForm
$values[$k] = $newValues[$k]; $values[$k] = $newValues[$k];
$values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]]; $values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]];
break; break;
case 'suggest': case 'suggest':
$values[$k] = $newValues[$k]; $values[$k] = $newValues[$k];
$values[$k . "_label"] = $newValues[$k . "_label"]; $values[$k . "_label"] = $newValues[$k . "_label"];
break; break;
case 'checkgroup': case 'checkgroup':
case 'listbox': case 'listbox':
if (is_array( $newValues[$k] )) { if (is_array( $newValues[$k] )) {
$values[$k] = $values[$k . "_label"] = null; $values[$k] = $values[$k . "_label"] = null;
@@ -331,20 +355,23 @@ class Form extends XmlForm
if (isset( $v->options[$value] )) { if (isset( $v->options[$value] )) {
$values[$k . "_label"] .= (($i != 0) ? "|" : null) . $v->options[$value]; $values[$k . "_label"] .= (($i != 0) ? "|" : null) . $v->options[$value];
} } else {
else { // if hasn't options try execute a sql sentence // if hasn't options try execute a sql sentence
$query = G::replaceDataField( $this->fields[$k]->sql, $newValues ); $query = G::replaceDataField( $this->fields[$k]->sql, $newValues );
if ($query != '') { // execute just if a query was set, it should be not empty if ($query != '') {
// execute just if a query was set, it should be not empty
//we do the query to the external connection and we've got the label //we do the query to the external connection and we've got the label
$con = Propel::getConnection( $this->fields[$k]->sqlConnection != "" ? $this->fields[$k]->sqlConnection : "workflow" ); //use default connection workflow if connection is not defined. Same as Dynaforms $con = Propel::getConnection( $this->fields[$k]->sqlConnection != "" ? $this->fields[$k]->sqlConnection : "workflow" ); //use default connection workflow if connection is not defined. Same as Dynaforms
$stmt = $con->prepareStatement( $query ); $stmt = $con->prepareStatement( $query );
$rs = $stmt->executeQuery( ResultSet::FETCHMODE_NUM ); $rs = $stmt->executeQuery( ResultSet::FETCHMODE_NUM );
while ($rs->next()) { while ($rs->next()) {
list ($rowId, $rowContent) = array_values( $rs->getRow() ); //This to be sure that the array is numeric. Some cases when is DBArray result it returns an associative. By JHL list ($rowId, $rowContent) = array_values( $rs->getRow() ); //This to be sure that the array is numeric. Some cases when is DBArray result it returns an associative. By JHL
if ($value == $rowId) { if ($value == $rowId) {
$values[$k . "_label"] .= (($i != 0) ? "|" : null) . $rowContent; $values[$k . "_label"] .= (($i != 0) ? "|" : null) . $rowContent;
break; break;
@@ -361,14 +388,12 @@ class Form extends XmlForm
$values[$k . "_label"] = (isset( $newValues[$k . "_label"] )) ? $newValues[$k . "_label"] : null; $values[$k . "_label"] = (isset( $newValues[$k . "_label"] )) ? $newValues[$k . "_label"] : null;
} }
break; break;
case 'dropdown': case 'dropdown':
$values[$k] = $newValues[$k]; $values[$k] = $newValues[$k];
if (isset( $v->options[$newValues[$k]] )) { if (isset( $v->options[$newValues[$k]] )) {
$values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]]; $values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]];
} } else {
else {
$query = G::replaceDataField( $this->fields[$k]->sql, $newValues ); $query = G::replaceDataField( $this->fields[$k]->sql, $newValues );
// execute just if a query was set, it should be not empty // execute just if a query was set, it should be not empty
@@ -389,7 +414,6 @@ class Form extends XmlForm
} }
} }
break; break;
case 'grid': case 'grid':
foreach ($newValues[$k] as $j => $item) { foreach ($newValues[$k] as $j => $item) {
if (is_array( $item )) { if (is_array( $item )) {
@@ -455,13 +479,11 @@ class Form extends XmlForm
} }
} }
break; break;
default: default:
if ($this->fields[$k]->validateValue($newValues[$k], $this )) if ($this->fields[$k]->validateValue( $newValues[$k], $this )) {
$values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this ); $values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this );
} }
}
} }
} else { } else {
if (isset( $_FILES["form"]["name"][$k] )) { if (isset( $_FILES["form"]["name"][$k] )) {
@@ -486,26 +508,26 @@ class Form extends XmlForm
/** /**
* Function that return the valid fields to replace * Function that return the valid fields to replace
*
* @author Julio Cesar Laura Avendao?=o <juliocesar@colosa.com> * @author Julio Cesar Laura Avendao?=o <juliocesar@colosa.com>
* @access public * @access public
* @param boolean $bWhitSystemVars * @param boolean $bWhitSystemVars
* @return array * @return array
*/ */
function getVars($bWhitSystemVars = true) public function getVars ($bWhitSystemVars = true)
{ {
$aFields = array (); $aFields = array ();
if ($bWhitSystemVars) { if ($bWhitSystemVars) {
$aAux = G::getSystemConstants(); $aAux = G::getSystemConstants();
foreach ($aAux as $sName => $sValue) { foreach ($aAux as $sName => $sValue) {
$aFields[] = array('sName' => $sName, 'sType' => 'system'); $aFields[] = array ('sName' => $sName,'sType' => 'system'
);
} }
} }
foreach ($this->fields as $k => $v) { foreach ($this->fields as $k => $v) {
if (($v->type != 'title') && ($v->type != 'subtitle') && ($v->type != 'link') && if (($v->type != 'title') && ($v->type != 'subtitle') && ($v->type != 'link') && ($v->type != 'file') && ($v->type != 'button') && ($v->type != 'reset') && ($v->type != 'submit') && ($v->type != 'listbox') && ($v->type != 'checkgroup') && ($v->type != 'grid') && ($v->type != 'javascript')) {
($v->type != 'file') && ($v->type != 'button') && ($v->type != 'reset') && $aFields[] = array ('sName' => trim( $k ),'sType' => trim( $v->type )
($v->type != 'submit') && ($v->type != 'listbox') && ($v->type != 'checkgroup') && );
($v->type != 'grid') && ($v->type != 'javascript')) {
$aFields[] = array('sName' => trim($k), 'sType' => trim($v->type));
} }
} }
return $aFields; return $aFields;
@@ -513,21 +535,22 @@ class Form extends XmlForm
/** /**
* Function that verify the required fields without a correct value * Function that verify the required fields without a correct value
*
* @author Erik Amaru Ortiz <erik@colosa.com> * @author Erik Amaru Ortiz <erik@colosa.com>
* @access public * @access public
* @param array $dataFields * @param array $dataFields
* @param array $noRequired * @param array $noRequired
* @return array/false * @return array/false
*/ */
function validateRequiredFields($dataFields, $noRequired = array()) public function validateRequiredFields ($dataFields, $noRequired = array())
{ {
if (! is_array( $noRequired )) { if (! is_array( $noRequired )) {
$noRequired = array (); $noRequired = array ();
} }
$requiredFields = array (); $requiredFields = array ();
$notPassedFields = array (); $notPassedFields = array ();
$skippedFieldsTypes = array('javascript', 'checkbox', 'yesno', 'submit', 'button', 'title', 'subtitle', $skippedFieldsTypes = array ('javascript','checkbox','yesno','submit','button','title','subtitle','button','submit','reset','hidden','link'
'button', 'submit', 'reset', 'hidden', 'link'); );
$requiredFieldsGrids = array (); $requiredFieldsGrids = array ();
$grids = array (); $grids = array ();
@@ -593,7 +616,6 @@ class Form extends XmlForm
break; break;
case "grid": case "grid":
$i = 0; $i = 0;
foreach ($data[$v->name] as $dataGrid) { foreach ($data[$v->name] as $dataGrid) {
$i = $i + 1; $i = $i + 1;
@@ -614,7 +636,7 @@ class Form extends XmlForm
} }
} }
} }
return $data; return $data;
} }
} }

View File

@@ -1,6 +1,8 @@
<?php <?php
/** /**
* class.functionTest.php * class.functionTest.php
*
* @package gulliver.system * @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -25,13 +27,15 @@
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
**/ *
*/
class functionTest class functionTest
{ {
var $dbc; public $dbc;
var $times; public $times;
/** /**
* Starts functionTest with a database connection * Starts functionTest with a database connection
@@ -41,7 +45,8 @@ class functionTest
* @return void * @return void
* *
*/ */
function functionTest( $dbc ) { public function functionTest ($dbc)
{
$this->dbc = $dbc; $this->dbc = $dbc;
} }
@@ -55,7 +60,9 @@ class functionTest
* @return ok * @return ok
* *
*/ */
function sample( $testCase , &$testDomain , &$limeTestObject ) { public function sample ($testCase, &$testDomain, &$limeTestObject)
{
return "OK"; return "OK";
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,8 @@
/** /**
* Class RestClient * Class RestClient
*/ */
class RestClient { class RestClient
{
private $curl; private $curl;
private $url; private $url;
@@ -18,7 +19,8 @@ class RestClient {
/** /**
* Private Constructor, sets default options * Private Constructor, sets default options
*/ */
public function __construct() { public function __construct ()
{
$this->curl = curl_init(); $this->curl = curl_init();
curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $this->curl, CURLOPT_AUTOREFERER, true ); // This make sure will follow redirects curl_setopt( $this->curl, CURLOPT_AUTOREFERER, true ); // This make sure will follow redirects
@@ -28,9 +30,11 @@ class RestClient {
/** /**
* Execute the call to the webservice * Execute the call to the webservice
*
* @return RestClient * @return RestClient
*/ */
public function execute() { public function execute ()
{
if ($this->method === "POST") { if ($this->method === "POST") {
curl_setopt( $this->curl, CURLOPT_POST, true ); curl_setopt( $this->curl, CURLOPT_POST, true );
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $this->params ); curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $this->params );
@@ -55,24 +59,24 @@ class RestClient {
} }
curl_setopt( $this->curl, CURLOPT_URL, $this->url ); curl_setopt( $this->curl, CURLOPT_URL, $this->url );
$r = curl_exec( $this->curl ); $r = curl_exec( $this->curl );
if($this->method !== "DELETE") if ($this->method !== "DELETE") {
{
$this->treatResponse( $r ); // Extract the headers and response $this->treatResponse( $r ); // Extract the headers and response
return $this; return $this;
} } else {
else{
return $this; return $this;
} }
} }
/** /**
* Treats URL * Treats URL
*/ */
private function treatURL(){ private function treatURL ()
if(is_array($this->params) && count($this->params) >= 1) { // Transform parameters in key/value pars in URL {
if(!strpos($this->url,'?')) if (is_array( $this->params ) && count( $this->params ) >= 1) {
// Transform parameters in key/value pars in URL
if (! strpos( $this->url, '?' )) {
$this->url .= '?'; $this->url .= '?';
}
foreach ($this->params as $k => $v) { foreach ($this->params as $k => $v) {
$this->url .= "&" . urlencode( $k ) . "=" . urlencode( $v ); $this->url .= "&" . urlencode( $k ) . "=" . urlencode( $v );
} }
@@ -83,7 +87,8 @@ class RestClient {
/* /*
* Treats the Response for extracting the Headers and Response * Treats the Response for extracting the Headers and Response
*/ */
private function treatResponse($r) { private function treatResponse ($r)
{
if ($r == null or strlen( $r ) < 1) { if ($r == null or strlen( $r ) < 1) {
return; return;
} }
@@ -101,7 +106,8 @@ class RestClient {
$this->headers['code'] = $reg[1]; $this->headers['code'] = $reg[1];
$this->headers['message'] = $reg[2]; $this->headers['message'] = $reg[2];
$this->response = ""; $this->response = "";
for($i=1;$i<count($parts);$i++) {//This make sure that exploded response get back togheter for ($i = 1; $i < count( $parts ); $i ++) {
//This make sure that exploded response get back togheter
if ($i > 1) { if ($i > 1) {
$this->response .= "\n\r"; $this->response .= "\n\r";
} }
@@ -112,14 +118,16 @@ class RestClient {
/* /*
* @return array * @return array
*/ */
public function getHeaders() { public function getHeaders ()
{
return $this->headers; return $this->headers;
} }
/* /*
* @return string * @return string
*/ */
public function getResponse() { public function getResponse ()
{
return $this->response; return $this->response;
} }
@@ -127,7 +135,8 @@ class RestClient {
* HTTP response code (404,401,200,etc) * HTTP response code (404,401,200,etc)
* @return int * @return int
*/ */
public function getResponseCode() { public function getResponseCode ()
{
return (int) $this->headers['code']; return (int) $this->headers['code'];
} }
@@ -135,7 +144,8 @@ class RestClient {
* HTTP response message (Not Found, Continue, etc ) * HTTP response message (Not Found, Continue, etc )
* @return string * @return string
*/ */
public function getResponseMessage() { public function getResponseMessage ()
{
return $this->headers['message']; return $this->headers['message'];
} }
@@ -143,15 +153,18 @@ class RestClient {
* Content-Type (text/plain, application/xml, etc) * Content-Type (text/plain, application/xml, etc)
* @return string * @return string
*/ */
public function getResponseContentType() { public function getResponseContentType ()
{
return $this->headers['content-type']; return $this->headers['content-type'];
} }
/** /**
* This sets that will not follow redirects * This sets that will not follow redirects
*
* @return RestClient * @return RestClient
*/ */
public function setNoFollow() { public function setNoFollow ()
{
curl_setopt( $this->curl, CURLOPT_AUTOREFERER, false ); curl_setopt( $this->curl, CURLOPT_AUTOREFERER, false );
curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, false ); curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, false );
return $this; return $this;
@@ -159,9 +172,11 @@ class RestClient {
/** /**
* This closes the connection and release resources * This closes the connection and release resources
*
* @return RestClient * @return RestClient
*/ */
public function close() { public function close ()
{
curl_close( $this->curl ); curl_close( $this->curl );
$this->curl = null; $this->curl = null;
if ($this->file != null) { if ($this->file != null) {
@@ -172,9 +187,11 @@ class RestClient {
/** /**
* Sets the URL to be Called * Sets the URL to be Called
*
* @return RestClient * @return RestClient
*/ */
public function setUrl($url) { public function setUrl ($url)
{
$this->url = $url; $this->url = $url;
return $this; return $this;
} }
@@ -182,21 +199,25 @@ class RestClient {
/** /**
* Set the Content-Type of the request to be send * Set the Content-Type of the request to be send
* Format like "application/xml" or "text/plain" or other * Format like "application/xml" or "text/plain" or other
*
* @param string $contentType * @param string $contentType
* @return RestClient * @return RestClient
*/ */
public function setContentType($contentType) { public function setContentType ($contentType)
{
$this->contentType = $contentType; $this->contentType = $contentType;
return $this; return $this;
} }
/** /**
* Set the Credentials for BASIC Authentication * Set the Credentials for BASIC Authentication
*
* @param string $user * @param string $user
* @param string $pass * @param string $pass
* @return RestClient * @return RestClient
*/ */
public function setCredentials($user,$pass) { public function setCredentials ($user, $pass)
{
if ($user != null) { if ($user != null) {
curl_setopt( $this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); curl_setopt( $this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt( $this->curl, CURLOPT_USERPWD, "{$user}:{$pass}" ); curl_setopt( $this->curl, CURLOPT_USERPWD, "{$user}:{$pass}" );
@@ -207,10 +228,12 @@ class RestClient {
/** /**
* Set the Request HTTP Method * Set the Request HTTP Method
* For now, only accepts GET and POST * For now, only accepts GET and POST
*
* @param string $method * @param string $method
* @return RestClient * @return RestClient
*/ */
public function setMethod($method) { public function setMethod ($method)
{
$this->method = $method; $this->method = $method;
return $this; return $this;
} }
@@ -220,21 +243,25 @@ class RestClient {
* It can be both a key/value par array (as in array("key"=>"value")) * It can be both a key/value par array (as in array("key"=>"value"))
* or a string containing the body of the request, like a XML, JSON or other * or a string containing the body of the request, like a XML, JSON or other
* Proper content-type should be set for the body if not a array * Proper content-type should be set for the body if not a array
*
* @param mixed $params * @param mixed $params
* @return RestClient * @return RestClient
*/ */
public function setParameters($params) { public function setParameters ($params)
{
$this->params = $params; $this->params = $params;
return $this; return $this;
} }
/** /**
* Creates the RESTClient * Creates the RESTClient
*
* @param string $url=null [optional] * @param string $url=null [optional]
* @return RestClient * @return RestClient
*/ */
public static function createClient($url=null) { public static function createClient ($url = null)
$client = new RestClient ; {
$client = new RestClient();
if ($url != null) { if ($url != null) {
$client->setUrl( $url ); $client->setUrl( $url );
} }
@@ -243,6 +270,7 @@ class RestClient {
/** /**
* Convenience method wrapping a commom POST call * Convenience method wrapping a commom POST call
*
* @param string $url * @param string $url
* @param mixed params * @param mixed params
* @param string $user=null [optional] * @param string $user=null [optional]
@@ -251,13 +279,15 @@ class RestClient {
* @return RestClient * @return RestClient
*/ */
//public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") { //public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") {
public static function post($url,$params,$user,$pwd,$contentType="multipart/form-data") { public static function post ($url, $params, $user, $pwd, $contentType = "multipart/form-data")
{
//return self::call("POST",$url,$params,$user,$pwd,$contentType); //return self::call("POST",$url,$params,$user,$pwd,$contentType);
return self::call( "POST", $url, $params, $user, $pwd, $contentType ); return self::call( "POST", $url, $params, $user, $pwd, $contentType );
} }
/** /**
* Convenience method wrapping a commom PUT call * Convenience method wrapping a commom PUT call
*
* @param string $url * @param string $url
* @param string $body * @param string $body
* @param string $user=null [optional] * @param string $user=null [optional]
@@ -265,12 +295,14 @@ class RestClient {
* @param string $contentType=null [optional] * @param string $contentType=null [optional]
* @return RestClient * @return RestClient
*/ */
public static function put($url,$body,$user=null,$pwd=null,$contentType=null) { public static function put ($url, $body, $user = null, $pwd = null, $contentType = null)
{
return self::call( "PUT", $url, $body, $user, $pwd, $contentType ); return self::call( "PUT", $url, $body, $user, $pwd, $contentType );
} }
/** /**
* Convenience method wrapping a commom GET call * Convenience method wrapping a commom GET call
*
* @param string $url * @param string $url
* @param array params * @param array params
* @param string $user=null [optional] * @param string $user=null [optional]
@@ -278,25 +310,29 @@ class RestClient {
* @return RestClient * @return RestClient
*/ */
//public static function get($url,array $params=null,$user=null,$pwd=null,$contentType=null) { //public static function get($url,array $params=null,$user=null,$pwd=null,$contentType=null) {
public static function get($url,$user,$pwd,$contentType=null) { public static function get ($url, $user, $pwd, $contentType = null)
{
//return self::call("GET",$url,$params,$user,$pwd,$contentType); //return self::call("GET",$url,$params,$user,$pwd,$contentType);
return self::call( "GET", $url, null, $user, $pwd, $contentType ); return self::call( "GET", $url, null, $user, $pwd, $contentType );
} }
/** /**
* Convenience method wrapping a commom delete call * Convenience method wrapping a commom delete call
*
* @param string $url * @param string $url
* @param array params * @param array params
* @param string $user=null [optional] * @param string $user=null [optional]
* @param string $password=null [optional] * @param string $password=null [optional]
* @return RestClient * @return RestClient
*/ */
public static function delete($url,$user=null,$pwd=null,$contentType=null) { public static function delete ($url, $user = null, $pwd = null, $contentType = null)
{
return self::call( "DELETE", $url, null, $user, $pwd, $contentType ); return self::call( "DELETE", $url, null, $user, $pwd, $contentType );
} }
/** /**
* Convenience method wrapping a commom custom call * Convenience method wrapping a commom custom call
*
* @param string $method * @param string $method
* @param string $url * @param string $url
* @param string $body * @param string $body
@@ -305,15 +341,9 @@ class RestClient {
* @param string $contentType=null [optional] * @param string $contentType=null [optional]
* @return RestClient * @return RestClient
*/ */
public static function call($method,$url,$body,$user=null,$pwd=null,$contentType=null) { public static function call ($method, $url, $body, $user = null, $pwd = null, $contentType = null)
return self::createClient($url) {
->setParameters($body) return self::createClient( $url )->setParameters( $body )->setMethod( $method )->setCredentials( $user, $pwd )->setContentType( $contentType )->execute()->close();
->setMethod($method)
->setCredentials($user,$pwd)
->setContentType($contentType)
->execute()
->close();
} }
} }
?>

View File

@@ -1,6 +1,8 @@
<?php <?php
/** /**
* class.ymlTestCases.php * class.ymlTestCases.php
*
* @package gulliver.system * @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -42,12 +44,13 @@
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
*/ */
class ymlTestCases class ymlTestCases
{ {
var $testCaseFile; public $testCaseFile;
var $testCases=array(); public $testCases = array ();
/** /**
* function TestCases * function TestCases
@@ -58,12 +61,13 @@ class ymlTestCases
* @param string $testLime * @param string $testLime
* @return void * @return void
*/ */
function ymlTestCases( $testCaseFile, &$testDomain, &$testLime ) public function ymlTestCases ($testCaseFile, &$testDomain, &$testLime)
{ {
$this->testDomain = & $testDomain; $this->testDomain = & $testDomain;
$this->testLime = & $testLime; $this->testLime = & $testLime;
if (basename($testCaseFile)===$testCaseFile) if (basename( $testCaseFile ) === $testCaseFile) {
$testCaseFile = PATH_FIXTURES . $testCaseFile; $testCaseFile = PATH_FIXTURES . $testCaseFile;
}
$this->testCaseFile = $testCaseFile; $this->testCaseFile = $testCaseFile;
} }
@@ -75,7 +79,7 @@ class ymlTestCases
* @param array $fields * @param array $fields
* @return array * @return array
*/ */
function load( $inputTestCasesIndex = 'TestCases', $fields=array() ) public function load ($inputTestCasesIndex = 'TestCases', $fields = array())
{ {
$testCases = array (); $testCases = array ();
$input = sfYAML::Load( /*PATH_FIXTURES .*/ $this->testCaseFile ); $input = sfYAML::Load( /*PATH_FIXTURES .*/ $this->testCaseFile );
@@ -85,23 +89,17 @@ class ymlTestCases
if (substr( $inputArgument, - 2, 2 ) === '[]') { if (substr( $inputArgument, - 2, 2 ) === '[]') {
//DOMAIN //DOMAIN
$inputArgument = substr( $inputArgument, 0, strlen( $inputArgument ) - 2 ); $inputArgument = substr( $inputArgument, 0, strlen( $inputArgument ) - 2 );
if (!isset($testFunctionInputs[$inputArgument])) if (! isset( $testFunctionInputs[$inputArgument] )) {
$testFunctionInputs[$inputArgument] = array (); $testFunctionInputs[$inputArgument] = array ();
//var_dump($this->testDomain->global,$this->testDomain->get( $value ), $value );
ymlDomain::arrayAppend(
$testFunctionInputs[$inputArgument],
$this->testDomain->get( $value )
);
} }
else{ //var_dump($this->testDomain->global,$this->testDomain->get( $value ), $value );
ymlDomain::arrayAppend( $testFunctionInputs[$inputArgument], $this->testDomain->get( $value ) );
} else {
//SPECIFIC VALUE //SPECIFIC VALUE
if (! isset( $testFunctionInputs[$inputArgument] )) { if (! isset( $testFunctionInputs[$inputArgument] )) {
$testFunctionInputs[$inputArgument] = array (); $testFunctionInputs[$inputArgument] = array ();
} }
ymlDomain::arrayAppend( ymlDomain::arrayAppend( $testFunctionInputs[$inputArgument], array ($value) );
$testFunctionInputs[$inputArgument],
array($value)
);
} }
} }
/* Start Block: "Explode" all the posible test cases defined in the yml /* Start Block: "Explode" all the posible test cases defined in the yml
@@ -111,7 +109,9 @@ class ymlTestCases
$index = array_combine( array_keys( $testFunctionInputs ), array_fill( 0, count( $testFunctionInputs ), 0 ) ); $index = array_combine( array_keys( $testFunctionInputs ), array_fill( 0, count( $testFunctionInputs ), 0 ) );
//array_product() //array_product()
$prod = 1; $prod = 1;
foreach($testFunctionInputs as $values) $prod*=count($values); foreach ($testFunctionInputs as $values) {
$prod *= count( $values );
}
$lastCase = ($prod == 0); $lastCase = ($prod == 0);
while (! $lastCase) { while (! $lastCase) {
//foreach($index as $v) echo($v);echo("\n"); //foreach($index as $v) echo($v);echo("\n");
@@ -130,8 +130,7 @@ class ymlTestCases
$index[$key] ++; $index[$key] ++;
if ($index[$key] >= count( $values )) { if ($index[$key] >= count( $values )) {
$index[$key] = 0; $index[$key] = 0;
} } else {
else{
$lastCase = false; $lastCase = false;
break; break;
} }
@@ -158,36 +157,37 @@ class ymlTestCases
/** /**
* function load * function load
* Increase the number of "planned" tests. * Increase the number of "planned" tests.
*
* @access public * @access public
* @param int $count * @param int $count
* @param int $start * @param int $start
* @return void * @return void
*/ */
function addToPlan( $count=-1, $start=0 ) public function addToPlan ($count = -1, $start = 0)
{ {
foreach ($this->testCases as $testCase) { foreach ($this->testCases as $testCase) {
if (($start == 0) && ($count != 0)) { if (($start == 0) && ($count != 0)) {
if (isset( $testCase['TODO'] )) { if (isset( $testCase['TODO'] )) {
$this->testLime->plan ++; $this->testLime->plan ++;
} } else {
else{
if (isset( $testCase['Output'] )) { if (isset( $testCase['Output'] )) {
if ( isset($testCase['Output']['Type']) || if (isset( $testCase['Output']['Type'] ) || isset( $testCase['Output']['Value'] )) {
isset($testCase['Output']['Value']) )
$this->testLime->plan ++; $this->testLime->plan ++;
} }
} }
} }
else{ } else {
$start --; $start --;
if ($count>0) if ($count > 0) {
$count --; $count --;
} }
} }
} }
}
/** /**
* function run * function run
*
* @access public * @access public
* @param object $testerObject * @param object $testerObject
* @param array $fields * @param array $fields
@@ -195,21 +195,21 @@ class ymlTestCases
* @param int $start * @param int $start
* @return array * @return array
*/ */
function run( &$testerObject, $fields=array(), $count=-1, $start=0 ) public function run (&$testerObject, $fields = array(), $count = -1, $start = 0)
{ {
$results = array (); $results = array ();
//$this->addToPlan( $count, $start ); //$this->addToPlan( $count, $start );
$functions = get_class_methods( get_class( $testerObject ) ); $functions = get_class_methods( get_class( $testerObject ) );
foreach($functions as $id=>$fn) foreach ($functions as $id => $fn) {
$functions[$id] = strtolower( $fn ); $functions[$id] = strtolower( $fn );
}
foreach ($this->testCases as $index => $testCase) { foreach ($this->testCases as $index => $testCase) {
if (($start == 0) && ($count != 0)) { if (($start == 0) && ($count != 0)) {
if (isset( $testCase['TODO'] )) { if (isset( $testCase['TODO'] )) {
$this->testLime->todo( $testCase['TODO'] ); $this->testLime->todo( $testCase['TODO'] );
} } else {
else{
if (isset( $testCase['Function'] )) { if (isset( $testCase['Function'] )) {
if (array_search(strtolower($testCase['Function']),$functions)!==FALSE){ if (array_search( strtolower( $testCase['Function'] ), $functions ) !== false) {
$testCase['Input'] = G::array_merges( $testCase['Input'], $fields ); $testCase['Input'] = G::array_merges( $testCase['Input'], $fields );
$result = eval( 'return $testerObject->' . $testCase['Function'] . '($testCase, $testCase["Input"]);' ); $result = eval( 'return $testerObject->' . $testCase['Function'] . '($testCase, $testCase["Input"]);' );
$results[] = $result; $results[] = $result;
@@ -219,41 +219,39 @@ class ymlTestCases
//$this->testLime->is( $result, $testCase['Output']['Value'], $testCase['Title'] ); //$this->testLime->is( $result, $testCase['Output']['Value'], $testCase['Title'] );
$this->testLime->todo( ($testCase['Output']['Type']) ); $this->testLime->todo( ($testCase['Output']['Type']) );
$this->testLime->diag( "/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204" ); $this->testLime->diag( "/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204" );
} } elseif (isset( $testCase['Output']['Type'] )) {
elseif (isset($testCase['Output']['Type'])){
// $this->testLime->isa_ok( $result, $testCase['Output']['Type'], $testCase['Title'] ); // $this->testLime->isa_ok( $result, $testCase['Output']['Type'], $testCase['Title'] );
$this->testLime->todo( ($testCase['Output']['Type']) ); $this->testLime->todo( ($testCase['Output']['Type']) );
$this->testLime->diag( "/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204" ); $this->testLime->diag( "/processmaker/trunk/gulliver/system/class.ymlTestCases.php at line 204" );
} }
} }
/* End Block */ /* End Block */
} } else {
else{
$this->testLime->fail( 'Case #' . $index . ': Test function (Function) is not present in tester object.' ); $this->testLime->fail( 'Case #' . $index . ': Test function (Function) is not present in tester object.' );
} }
} } else {
else{
$this->testLime->fail( 'Case #' . $index . ' doesn\'t have a test function (Function) defined.' ); $this->testLime->fail( 'Case #' . $index . ' doesn\'t have a test function (Function) defined.' );
} }
} }
} } else {
else{
$start --; $start --;
if ($count>0) if ($count > 0) {
$count --; $count --;
} }
} }
}
return $results; return $results;
} }
/** /**
* function runSingle * function runSingle
*
* @access public * @access public
* @param object $testerObject * @param object $testerObject
* @param array $fields * @param array $fields
* @return array * @return array
*/ */
function runSingle( &$testerObject, $fields=array() ) public function runSingle (&$testerObject, $fields = array())
{ {
$results = $this->run( $testerObject, $fields, 1, 0 ); $results = $this->run( $testerObject, $fields, 1, 0 );
return $results[0]; return $results[0];
@@ -261,6 +259,7 @@ class ymlTestCases
/** /**
* function runMultiple * function runMultiple
*
* @access public * @access public
* @param object $testerObject * @param object $testerObject
* @param array $fields * @param array $fields
@@ -268,8 +267,9 @@ class ymlTestCases
* @param int $start * @param int $start
* @return array * @return array
*/ */
function runMultiple( &$testerObject, $fields=array(), $count = -1, $start=0) public function runMultiple (&$testerObject, $fields = array(), $count = -1, $start = 0)
{ {
return $this->run( $testerObject, $fields, $count, $start ); return $this->run( $testerObject, $fields, $count, $start );
} }
} }