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
/**
* class.database_base.php
*
* @package gulliver.system
*
* ProcessMaker Open Source Edition
@@ -25,53 +27,56 @@
*/
/**
* Class Form
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @package gulliver.system
* @access public
*/
class Form extends XmlForm
{
var $id='';
var $width = 600;
var $title = '';
var $fields = array();
var $values = array();
var $action = '';
var $ajaxServer = '';
var $enableTemplate = false;
var $ajaxSubmit = false;
var $callback='function(){}';
var $in_progress='function(){}';
var $template;
var $className="formDefault";
var $objectRequiredFields = null;
var $nextstepsave = '';
var $printdynaform = '';
var $adjustgridswidth = '0';
public $id = '';
public $width = 600;
public $title = '';
public $fields = array ();
public $values = array ();
public $action = '';
public $ajaxServer = '';
public $enableTemplate = false;
public $ajaxSubmit = false;
public $callback = 'function(){}';
public $in_progress = 'function(){}';
public $template;
public $className = "formDefault";
public $objectRequiredFields = null;
public $nextstepsave = '';
public $printdynaform = '';
public $adjustgridswidth = '0';
public $visual_frontend;
/**
* Function setDefaultValues
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function setDefaultValues( )
public function setDefaultValues ()
{
foreach ($this->fields as $name => $content) {
if (is_object( $content ) && get_class( $content ) != '__PHP_Incomplete_Class') {
if (isset($content->defaultValue))
if (isset( $content->defaultValue )) {
$this->values[$name] = $content->defaultValue;
else
} else {
$this->values[$name] = '';
}
else {
} else {
$this->values[$name] = '';
}
}
foreach ($this->fields as $k => $v) {
if (is_object($v)) {//julichu
if (is_object( $v )) {
//julichu
$this->fields[$k]->owner = & $this;
}
}
@@ -79,6 +84,7 @@ class Form extends XmlForm
/**
* Function Form
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param string filename
@@ -88,33 +94,40 @@ class Form extends XmlForm
* @param string $visual_frontend
* @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;
if ($language=== '')
if ($language === '') {
$language = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
if ($home=== '')
$home = defined('PATH_XMLFORM')? PATH_XMLFORM :
(defined('PATH_DYNAFORM')? PATH_DYNAFORM: '');
}
if ($home === '') {
$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
//Load and parse the xml file
if ( substr($filename, -4) !== '.xml' )
if (substr( $filename, - 4 ) !== '.xml') {
$filename = $filename . '.xml';
}
$this->home = $home;
$res = parent::parseFile( $filename, $language, $forceParse );
if ($res==1)
if ($res == 1) {
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 );
}
$this->setDefaultValues();
//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.
foreach ($this->fields as $k => $v) {
//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)
if (is_object($v)) {//julichu
if (is_object( $v )) {
//julichu
$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';
@@ -122,23 +135,24 @@ class Form extends XmlForm
/**
* Function printTemplate
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param string template
* @param string scriptContent
* @return string
*/
function printTemplate( $template, &$scriptContent )
public function printTemplate ($template, &$scriptContent)
{
if (! file_exists( $template )) {
throw (new Exception( 'Template "' . basename( $template ) . '" doesn`t exist.' ));
}
$o = new xmlformTemplate( $this, $template );
if (is_array(reset($this->values)))
if (is_array( reset( $this->values ) )) {
$this->rows = count( reset( $this->values ) );
}
if ($this->enableTemplate) {
$filename = substr($this->fileName , 0, -3) .
( $this->type==='xmlform' ? '' : '.' . $this->type ) . 'html';
$filename = substr( $this->fileName, 0, - 3 ) . ($this->type === 'xmlform' ? '' : '.' . $this->type) . 'html';
if (! file_exists( $filename )) {
$o->template = $o->printTemplate( $this );
$f = fopen( $filename, 'w+' );
@@ -154,15 +168,17 @@ class Form extends XmlForm
/**
* Function render
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param string template
* @param string scriptContent
* @return string
*/
function render( $template, &$scriptContent )
public function render ($template, &$scriptContent)
{
/***
/**
* *
* This section was added for store the current used template.
*/
$tmp_var = explode( '/', $template );
@@ -170,13 +186,15 @@ class Form extends XmlForm
$tmp_var = $tmp_var[sizeof( $tmp_var ) - 1];
$this->using_template = $tmp_var;
}
/***/
/**
*/
$this->template = $template;
$o = new xmlformTemplate( $this, $template );
$values = $this->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 );
}
//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 ) )) {
$this->rows = count( reset( $values ) );
@@ -200,12 +218,13 @@ class Form extends XmlForm
/**
* Function setValues
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param array $newValues
* @return string
*/
function setValues($newValues=array())
public function setValues ($newValues = array())
{
if (! is_array( $newValues )) {
return;
@@ -215,19 +234,23 @@ class Form extends XmlForm
if (is_array( $newValues[$k] )) {
$this->values[$k] = array ();
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];
}
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];
if (sizeof($this->values[$k])===0)
}
if (sizeof( $this->values[$k] ) === 0) {
$this->values[$k] = '';
}
} else {
if ($this->fields[$k]->validateValue($newValues[$k], $this ))
if ($this->fields[$k]->validateValue( $newValues[$k], $this )) {
$this->values[$k] = $newValues[$k];
}
}
}
}
foreach ($newValues as $k => $v) {
if (strpos( $k, 'SYS_GRID_AGGREGATE_' ) !== false) {
$this->values[$k] = $newValues[$k];
@@ -258,20 +281,22 @@ class Form extends XmlForm
$nLabelWidth = (int) $this->labelWidth;
}
// krumo($nWidth,$nLabelWidth);
if(($nWidth - $nLabelWidth) > 0)
if (($nWidth - $nLabelWidth) > 0) {
$this->fieldContentWidth = (int) ($nWidth - $nLabelWidth);
}
}
}
/**
* Function getFields
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param string template
* @param int $therow
* @return string
*/
function getFields($template, $therow = -1)
public function getFields ($template, $therow = -1)
{
$o = new xmlformTemplate( $this, $template );
return $o->getFields( $this, $therow );
@@ -279,11 +304,12 @@ class Form extends XmlForm
/**
* Function that validates the values retrieved in $_POST
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return array $_POST['form']
*/
function validatePost()
public function validatePost ()
{
$_POST['form'] = $this->validateFields( $_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:
* ex $_POST['form']
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param array $newValues
* @return array
*/
function validateArray($newValues)
public function validateArray ($newValues)
{
$values = array ();
foreach ($this->fields as $k => $v) {
@@ -310,14 +337,11 @@ class Form extends XmlForm
$values[$k] = $newValues[$k];
$values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]];
break;
case 'suggest':
$values[$k] = $newValues[$k];
$values[$k . "_label"] = $newValues[$k . "_label"];
break;
case 'checkgroup':
case 'listbox':
if (is_array( $newValues[$k] )) {
$values[$k] = $values[$k . "_label"] = null;
@@ -331,20 +355,23 @@ class Form extends XmlForm
if (isset( $v->options[$value] )) {
$values[$k . "_label"] .= (($i != 0) ? "|" : null) . $v->options[$value];
}
else { // if hasn't options try execute a sql sentence
} else {
// if hasn't options try execute a sql sentence
$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
$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 );
$rs = $stmt->executeQuery( ResultSet::FETCHMODE_NUM );
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
if ($value == $rowId) {
$values[$k . "_label"] .= (($i != 0) ? "|" : null) . $rowContent;
break;
@@ -361,14 +388,12 @@ class Form extends XmlForm
$values[$k . "_label"] = (isset( $newValues[$k . "_label"] )) ? $newValues[$k . "_label"] : null;
}
break;
case 'dropdown':
$values[$k] = $newValues[$k];
if (isset( $v->options[$newValues[$k]] )) {
$values[$k . "_label"] = $newValues[$k . "_label"] = $v->options[$newValues[$k]];
}
else {
} else {
$query = G::replaceDataField( $this->fields[$k]->sql, $newValues );
// execute just if a query was set, it should be not empty
@@ -389,7 +414,6 @@ class Form extends XmlForm
}
}
break;
case 'grid':
foreach ($newValues[$k] as $j => $item) {
if (is_array( $item )) {
@@ -455,13 +479,11 @@ class Form extends XmlForm
}
}
break;
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 );
}
}
}
} else {
if (isset( $_FILES["form"]["name"][$k] )) {
@@ -486,26 +508,26 @@ class Form extends XmlForm
/**
* Function that return the valid fields to replace
*
* @author Julio Cesar Laura Avendao?=o <juliocesar@colosa.com>
* @access public
* @param boolean $bWhitSystemVars
* @return array
*/
function getVars($bWhitSystemVars = true)
public function getVars ($bWhitSystemVars = true)
{
$aFields = array ();
if ($bWhitSystemVars) {
$aAux = G::getSystemConstants();
foreach ($aAux as $sName => $sValue) {
$aFields[] = array('sName' => $sName, 'sType' => 'system');
$aFields[] = array ('sName' => $sName,'sType' => 'system'
);
}
}
foreach ($this->fields as $k => $v) {
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')) {
$aFields[] = array('sName' => trim($k), 'sType' => trim($v->type));
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')) {
$aFields[] = array ('sName' => trim( $k ),'sType' => trim( $v->type )
);
}
}
return $aFields;
@@ -513,21 +535,22 @@ class Form extends XmlForm
/**
* Function that verify the required fields without a correct value
*
* @author Erik Amaru Ortiz <erik@colosa.com>
* @access public
* @param array $dataFields
* @param array $noRequired
* @return array/false
*/
function validateRequiredFields($dataFields, $noRequired = array())
public function validateRequiredFields ($dataFields, $noRequired = array())
{
if (! is_array( $noRequired )) {
$noRequired = array ();
}
$requiredFields = array ();
$notPassedFields = array ();
$skippedFieldsTypes = array('javascript', 'checkbox', 'yesno', 'submit', 'button', 'title', 'subtitle',
'button', 'submit', 'reset', 'hidden', 'link');
$skippedFieldsTypes = array ('javascript','checkbox','yesno','submit','button','title','subtitle','button','submit','reset','hidden','link'
);
$requiredFieldsGrids = array ();
$grids = array ();
@@ -593,7 +616,6 @@ class Form extends XmlForm
break;
case "grid":
$i = 0;
foreach ($data[$v->name] as $dataGrid) {
$i = $i + 1;
@@ -614,7 +636,7 @@ class Form extends XmlForm
}
}
}
return $data;
}
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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