CODE STYLE
files modified: class.form.php
class.functionTest.php
class.rbac.php
class.restClient.php
class.ymlTestCases.php
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* class.functionTest.php
|
||||
* @package gulliver.system
|
||||
*
|
||||
*
|
||||
* @package gulliver.system
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
@@ -13,49 +15,54 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* @package gulliver.system
|
||||
**/
|
||||
*
|
||||
*/
|
||||
|
||||
class functionTest
|
||||
{
|
||||
var $dbc;
|
||||
var $times;
|
||||
|
||||
/**
|
||||
* Starts functionTest with a database connection
|
||||
*
|
||||
* @access public
|
||||
* @param string $dbc
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
function functionTest( $dbc ) {
|
||||
$this->dbc= $dbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* this function is a sample
|
||||
*
|
||||
* @access public
|
||||
* @param string $testCase
|
||||
* @param string $testDomain
|
||||
* @param string $limeTestObject
|
||||
* @return ok
|
||||
*
|
||||
*/
|
||||
function sample( $testCase , &$testDomain , &$limeTestObject ) {
|
||||
return "OK";
|
||||
}
|
||||
public $dbc;
|
||||
public $times;
|
||||
|
||||
/**
|
||||
* Starts functionTest with a database connection
|
||||
*
|
||||
* @access public
|
||||
* @param string $dbc
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public function functionTest ($dbc)
|
||||
{
|
||||
$this->dbc = $dbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* this function is a sample
|
||||
*
|
||||
* @access public
|
||||
* @param string $testCase
|
||||
* @param string $testDomain
|
||||
* @param string $limeTestObject
|
||||
* @return ok
|
||||
*
|
||||
*/
|
||||
public function sample ($testCase, &$testDomain, &$limeTestObject)
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,317 +3,347 @@
|
||||
/**
|
||||
* Class RestClient
|
||||
*/
|
||||
class RestClient {
|
||||
class RestClient
|
||||
{
|
||||
|
||||
private $curl ;
|
||||
private $url ;
|
||||
private $response ="";
|
||||
private $headers = array();
|
||||
private $curl;
|
||||
private $url;
|
||||
private $response = "";
|
||||
private $headers = array ();
|
||||
|
||||
private $method="GET";
|
||||
private $params=null;
|
||||
private $contentType = null;
|
||||
private $file =null;
|
||||
private $method = "GET";
|
||||
private $params = null;
|
||||
private $contentType = null;
|
||||
private $file = null;
|
||||
|
||||
/**
|
||||
* Private Constructor, sets default options
|
||||
*/
|
||||
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
|
||||
curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,true); // This too
|
||||
curl_setopt($this->curl,CURLOPT_HEADER,true); // THis verbose option for extracting the headers
|
||||
}
|
||||
/**
|
||||
* Private Constructor, sets default options
|
||||
*/
|
||||
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
|
||||
curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, true ); // This too
|
||||
curl_setopt( $this->curl, CURLOPT_HEADER, true ); // THis verbose option for extracting the headers
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the call to the webservice
|
||||
* @return RestClient
|
||||
*/
|
||||
public function execute() {
|
||||
if($this->method === "POST") {
|
||||
curl_setopt($this->curl,CURLOPT_POST,true);
|
||||
curl_setopt($this->curl,CURLOPT_POSTFIELDS,$this->params);
|
||||
//var_dump($this->params);
|
||||
//die;
|
||||
} else if($this->method == "GET"){
|
||||
curl_setopt($this->curl,CURLOPT_HTTPGET,true);
|
||||
$this->treatURL();
|
||||
} else if($this->method === "PUT") {
|
||||
curl_setopt($this->curl,CURLOPT_PUT,true);
|
||||
$this->treatURL();
|
||||
$this->file = tmpFile();
|
||||
fwrite($this->file,$this->params);
|
||||
fseek($this->file,0);
|
||||
curl_setopt($this->curl,CURLOPT_INFILE,$this->file);
|
||||
curl_setopt($this->curl,CURLOPT_INFILESIZE,strlen($this->params));
|
||||
} else {
|
||||
curl_setopt($this->curl,CURLOPT_CUSTOMREQUEST,$this->method);
|
||||
}
|
||||
if($this->contentType != null) {
|
||||
curl_setopt($this->curl,CURLOPT_HTTPHEADER,array("Content-Type: ".$this->contentType, "SKEY: 8QRtY5zXyViZ9fjYou"));
|
||||
}
|
||||
curl_setopt($this->curl,CURLOPT_URL,$this->url);
|
||||
$r = curl_exec($this->curl);
|
||||
if($this->method !== "DELETE")
|
||||
{
|
||||
$this->treatResponse($r); // Extract the headers and response
|
||||
return $this ;
|
||||
}
|
||||
else{
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Execute the call to the webservice
|
||||
*
|
||||
* @return RestClient
|
||||
*/
|
||||
public function execute ()
|
||||
{
|
||||
if ($this->method === "POST") {
|
||||
curl_setopt( $this->curl, CURLOPT_POST, true );
|
||||
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $this->params );
|
||||
//var_dump($this->params);
|
||||
//die;
|
||||
} elseif ($this->method == "GET") {
|
||||
curl_setopt( $this->curl, CURLOPT_HTTPGET, true );
|
||||
$this->treatURL();
|
||||
} elseif ($this->method === "PUT") {
|
||||
curl_setopt( $this->curl, CURLOPT_PUT, true );
|
||||
$this->treatURL();
|
||||
$this->file = tmpFile();
|
||||
fwrite( $this->file, $this->params );
|
||||
fseek( $this->file, 0 );
|
||||
curl_setopt( $this->curl, CURLOPT_INFILE, $this->file );
|
||||
curl_setopt( $this->curl, CURLOPT_INFILESIZE, strlen( $this->params ) );
|
||||
} else {
|
||||
curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, $this->method );
|
||||
}
|
||||
if ($this->contentType != null) {
|
||||
curl_setopt( $this->curl, CURLOPT_HTTPHEADER, array ("Content-Type: " . $this->contentType,"SKEY: 8QRtY5zXyViZ9fjYou" ) );
|
||||
}
|
||||
curl_setopt( $this->curl, CURLOPT_URL, $this->url );
|
||||
$r = curl_exec( $this->curl );
|
||||
if ($this->method !== "DELETE") {
|
||||
$this->treatResponse( $r ); // Extract the headers and response
|
||||
return $this;
|
||||
} 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,'?'))
|
||||
$this->url .= '?' ;
|
||||
foreach($this->params as $k=>$v) {
|
||||
$this->url .= "&".urlencode($k)."=".urlencode($v);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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, '?' )) {
|
||||
$this->url .= '?';
|
||||
}
|
||||
foreach ($this->params as $k => $v) {
|
||||
$this->url .= "&" . urlencode( $k ) . "=" . urlencode( $v );
|
||||
}
|
||||
}
|
||||
return $this->url;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Treats the Response for extracting the Headers and Response
|
||||
*/
|
||||
private function treatResponse($r) {
|
||||
if($r == null or strlen($r) < 1) {
|
||||
private function treatResponse ($r)
|
||||
{
|
||||
if ($r == null or strlen( $r ) < 1) {
|
||||
return;
|
||||
}
|
||||
$parts = explode("\n\r",$r); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body
|
||||
while(preg_match('@HTTP/1.[0-1] 100 Continue@',$parts[0]) or preg_match("@Moved@",$parts[0])) {
|
||||
$parts = explode( "\n\r", $r ); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body
|
||||
while (preg_match( '@HTTP/1.[0-1] 100 Continue@', $parts[0] ) or preg_match( "@Moved@", $parts[0] )) {
|
||||
// Continue header must be bypass
|
||||
for($i=1;$i<count($parts);$i++) {
|
||||
$parts[$i - 1] = trim($parts[$i]);
|
||||
for ($i = 1; $i < count( $parts ); $i ++) {
|
||||
$parts[$i - 1] = trim( $parts[$i] );
|
||||
}
|
||||
unset($parts[count($parts) - 1]);
|
||||
unset( $parts[count( $parts ) - 1] );
|
||||
}
|
||||
preg_match("@Content-Type: ([a-zA-Z0-9-]+/?[a-zA-Z0-9-]*)@",$parts[0],$reg);// This extract the content type
|
||||
preg_match( "@Content-Type: ([a-zA-Z0-9-]+/?[a-zA-Z0-9-]*)@", $parts[0], $reg ); // This extract the content type
|
||||
$this->headers['content-type'] = $reg[1];
|
||||
preg_match("@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@",$parts[0],$reg); // This extracts the response header Code and Message
|
||||
preg_match( "@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@", $parts[0], $reg ); // This extracts the response header Code and Message
|
||||
$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
|
||||
if($i > 1) {
|
||||
for ($i = 1; $i < count( $parts ); $i ++) {
|
||||
//This make sure that exploded response get back togheter
|
||||
if ($i > 1) {
|
||||
$this->response .= "\n\r";
|
||||
}
|
||||
$this->response .= $parts[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders() {
|
||||
public function getHeaders ()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponse() {
|
||||
return $this->response ;
|
||||
}
|
||||
public function getResponse ()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* HTTP response code (404,401,200,etc)
|
||||
* @return int
|
||||
*/
|
||||
public function getResponseCode() {
|
||||
return (int) $this->headers['code'];
|
||||
}
|
||||
public function getResponseCode ()
|
||||
{
|
||||
return (int) $this->headers['code'];
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* HTTP response message (Not Found, Continue, etc )
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseMessage() {
|
||||
return $this->headers['message'];
|
||||
}
|
||||
public function getResponseMessage ()
|
||||
{
|
||||
return $this->headers['message'];
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Content-Type (text/plain, application/xml, etc)
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseContentType() {
|
||||
return $this->headers['content-type'];
|
||||
}
|
||||
public function getResponseContentType ()
|
||||
{
|
||||
return $this->headers['content-type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets that will not follow redirects
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setNoFollow() {
|
||||
curl_setopt($this->curl,CURLOPT_AUTOREFERER,false);
|
||||
curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,false);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* This sets that will not follow redirects
|
||||
*
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setNoFollow ()
|
||||
{
|
||||
curl_setopt( $this->curl, CURLOPT_AUTOREFERER, false );
|
||||
curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, false );
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This closes the connection and release resources
|
||||
* @return RestClient
|
||||
*/
|
||||
public function close() {
|
||||
curl_close($this->curl);
|
||||
$this->curl = null ;
|
||||
if($this->file !=null) {
|
||||
fclose($this->file);
|
||||
}
|
||||
return $this ;
|
||||
}
|
||||
/**
|
||||
* This closes the connection and release resources
|
||||
*
|
||||
* @return RestClient
|
||||
*/
|
||||
public function close ()
|
||||
{
|
||||
curl_close( $this->curl );
|
||||
$this->curl = null;
|
||||
if ($this->file != null) {
|
||||
fclose( $this->file );
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URL to be Called
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setUrl($url) {
|
||||
$this->url = $url;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Sets the URL to be Called
|
||||
*
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setUrl ($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$this->contentType = $contentType;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$this->contentType = $contentType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Credentials for BASIC Authentication
|
||||
* @param string $user
|
||||
* @param string $pass
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setCredentials($user,$pass) {
|
||||
if($user != null) {
|
||||
curl_setopt($this->curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
|
||||
curl_setopt($this->curl,CURLOPT_USERPWD,"{$user}:{$pass}");
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the Credentials for BASIC Authentication
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $pass
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setCredentials ($user, $pass)
|
||||
{
|
||||
if ($user != null) {
|
||||
curl_setopt( $this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
|
||||
curl_setopt( $this->curl, CURLOPT_USERPWD, "{$user}:{$pass}" );
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Request HTTP Method
|
||||
* For now, only accepts GET and POST
|
||||
* @param string $method
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setMethod($method) {
|
||||
$this->method=$method;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the Request HTTP Method
|
||||
* For now, only accepts GET and POST
|
||||
*
|
||||
* @param string $method
|
||||
* @return RestClient
|
||||
*/
|
||||
public function setMethod ($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Parameters to be send on the request
|
||||
* 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) {
|
||||
$this->params=$params;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set Parameters to be send on the request
|
||||
* 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)
|
||||
{
|
||||
$this->params = $params;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the RESTClient
|
||||
* @param string $url=null [optional]
|
||||
* @return RestClient
|
||||
*/
|
||||
public static function createClient($url=null) {
|
||||
$client = new RestClient ;
|
||||
if($url != null) {
|
||||
$client->setUrl($url);
|
||||
}
|
||||
return $client;
|
||||
}
|
||||
/**
|
||||
* Creates the RESTClient
|
||||
*
|
||||
* @param string $url=null [optional]
|
||||
* @return RestClient
|
||||
*/
|
||||
public static function createClient ($url = null)
|
||||
{
|
||||
$client = new RestClient();
|
||||
if ($url != null) {
|
||||
$client->setUrl( $url );
|
||||
}
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method wrapping a commom POST call
|
||||
* @param string $url
|
||||
* @param mixed params
|
||||
* @param string $user=null [optional]
|
||||
* @param string $password=null [optional]
|
||||
* @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default
|
||||
* @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") {
|
||||
//return self::call("POST",$url,$params,$user,$pwd,$contentType);
|
||||
return self::call("POST",$url,$params,$user,$pwd,$contentType);
|
||||
}
|
||||
/**
|
||||
* Convenience method wrapping a commom POST call
|
||||
*
|
||||
* @param string $url
|
||||
* @param mixed params
|
||||
* @param string $user=null [optional]
|
||||
* @param string $password=null [optional]
|
||||
* @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default
|
||||
* @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")
|
||||
{
|
||||
//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]
|
||||
* @param string $password=null [optional]
|
||||
* @param string $contentType=null [optional]
|
||||
* @return RestClient
|
||||
*/
|
||||
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 PUT call
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $body
|
||||
* @param string $user=null [optional]
|
||||
* @param string $password=null [optional]
|
||||
* @param string $contentType=null [optional]
|
||||
* @return RestClient
|
||||
*/
|
||||
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]
|
||||
* @param string $password=null [optional]
|
||||
* @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) {
|
||||
//return self::call("GET",$url,$params,$user,$pwd,$contentType);
|
||||
return self::call("GET",$url,null,$user,$pwd,$contentType);
|
||||
}
|
||||
/**
|
||||
* Convenience method wrapping a commom GET call
|
||||
*
|
||||
* @param string $url
|
||||
* @param array params
|
||||
* @param string $user=null [optional]
|
||||
* @param string $password=null [optional]
|
||||
* @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)
|
||||
{
|
||||
//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) {
|
||||
return self::call("DELETE",$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)
|
||||
{
|
||||
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
|
||||
* @param string $user=null [optional]
|
||||
* @param string $password=null [optional]
|
||||
* @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();
|
||||
}
|
||||
/**
|
||||
* Convenience method wrapping a commom custom call
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param string $body
|
||||
* @param string $user=null [optional]
|
||||
* @param string $password=null [optional]
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* class.ymlTestCases.php
|
||||
* @package gulliver.system
|
||||
*
|
||||
* @package gulliver.system
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
@@ -13,11 +15,11 @@
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
@@ -41,235 +43,233 @@
|
||||
* ...
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* @package gulliver.system
|
||||
*/
|
||||
class ymlTestCases
|
||||
{
|
||||
var $testCaseFile;
|
||||
var $testCases=array();
|
||||
|
||||
/**
|
||||
* function TestCases
|
||||
*
|
||||
* @access public
|
||||
* @param string $testCaseFile
|
||||
* @param string $testDomain
|
||||
* @param string $testLime
|
||||
* @return void
|
||||
*/
|
||||
function ymlTestCases( $testCaseFile, &$testDomain, &$testLime )
|
||||
{
|
||||
$this->testDomain =& $testDomain;
|
||||
$this->testLime =& $testLime;
|
||||
if (basename($testCaseFile)===$testCaseFile)
|
||||
$testCaseFile = PATH_FIXTURES . $testCaseFile;
|
||||
$this->testCaseFile=$testCaseFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* function load
|
||||
*
|
||||
* @access public
|
||||
* @param string $inputTestCasesIndex
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
function load( $inputTestCasesIndex = 'TestCases', $fields=array() )
|
||||
{
|
||||
$testCases=array();
|
||||
$input = sfYAML::Load( /*PATH_FIXTURES .*/ $this->testCaseFile );
|
||||
foreach($input[$inputTestCasesIndex] as $preTestCase){
|
||||
$testFunctionInputs=array();
|
||||
foreach($preTestCase['Input'] as $inputArgument => $value ){
|
||||
if (substr($inputArgument,-2,2)==='[]'){
|
||||
//DOMAIN
|
||||
$inputArgument=substr($inputArgument,0,strlen($inputArgument)-2);
|
||||
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{
|
||||
//SPECIFIC VALUE
|
||||
if (!isset($testFunctionInputs[$inputArgument])){
|
||||
$testFunctionInputs[$inputArgument]=array();
|
||||
}
|
||||
ymlDomain::arrayAppend(
|
||||
$testFunctionInputs[$inputArgument],
|
||||
array($value)
|
||||
);
|
||||
}
|
||||
}
|
||||
/* Start Block: "Explode" all the posible test cases defined in the yml
|
||||
* using domains and single values
|
||||
*/
|
||||
//Initialize $index key values for the first test case (5.2 array_fill_keys(array_keys($testFunctionInputs),0))
|
||||
$index=array_combine(array_keys($testFunctionInputs),array_fill(0,count($testFunctionInputs),0));
|
||||
//array_product()
|
||||
$prod=1;
|
||||
foreach($testFunctionInputs as $values) $prod*=count($values);
|
||||
$lastCase=($prod==0);
|
||||
while(!$lastCase){
|
||||
//foreach($index as $v) echo($v);echo("\n");
|
||||
/* Put in $aux one test case */
|
||||
$aux=array();
|
||||
foreach($testFunctionInputs as $key => $values){
|
||||
$aux[$key]=$values[$index[$key]];
|
||||
}
|
||||
/* CREATE TEST CASE: Put $aux test case in $testCases array */
|
||||
$i=count($testCases);
|
||||
$testCases[$i] = $preTestCase;
|
||||
$testCases[$i]['Input']=$aux;
|
||||
/* Increse the $index key values to the next test case */
|
||||
$lastCase=true;
|
||||
foreach($testFunctionInputs as $key => $values){
|
||||
$index[$key]++;
|
||||
if ($index[$key]>=count($values)){
|
||||
$index[$key]=0;
|
||||
}
|
||||
else{
|
||||
$lastCase=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*End Block */
|
||||
}
|
||||
/* Start Block: Replace @@ tags variables */
|
||||
foreach($testCases as $key => $testCase){
|
||||
$testCases[$key]=testTools::replaceVariables( $testCases[$key] );
|
||||
$testCases[$key]['Input']=testTools::replaceVariables( $testCases[$key]['Input'], $fields );
|
||||
if (isset($testCase['Output'])){
|
||||
if (isset($testCase['Output']['Value'])) {
|
||||
/*$testCases[$key]['Output']['Value'] =
|
||||
unserialize($testCases[$key]['Output']['Value']);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
/* End Block */
|
||||
$this->testCases = $testCases;
|
||||
return $testCases;
|
||||
}
|
||||
|
||||
/**
|
||||
* function load
|
||||
* Increase the number of "planned" tests.
|
||||
* @access public
|
||||
* @param int $count
|
||||
* @param int $start
|
||||
* @return void
|
||||
*/
|
||||
function addToPlan( $count=-1, $start=0 )
|
||||
{
|
||||
foreach($this->testCases as $testCase){
|
||||
if (($start==0) && ($count!=0)){
|
||||
if (isset($testCase['TODO'])){
|
||||
$this->testLime->plan++;
|
||||
}
|
||||
else{
|
||||
if(isset($testCase['Output'])){
|
||||
if ( isset($testCase['Output']['Type']) ||
|
||||
isset($testCase['Output']['Value']) )
|
||||
$this->testLime->plan++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$start--;
|
||||
if ($count>0)
|
||||
$count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function run
|
||||
* @access public
|
||||
* @param object $testerObject
|
||||
* @param array $fields
|
||||
* @param int $count
|
||||
* @param int $start
|
||||
* @return array
|
||||
*/
|
||||
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)
|
||||
$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{
|
||||
if (isset($testCase['Function'])){
|
||||
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;
|
||||
/* Start Block: Test the $result */
|
||||
if (isset($testCase['Output'])){
|
||||
if (isset($testCase['Output']['Value'])){
|
||||
//$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'])){
|
||||
// $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{
|
||||
$this->testLime->fail( 'Case #'.$index.': Test function (Function) is not present in tester object.' );
|
||||
}
|
||||
}
|
||||
else{
|
||||
$this->testLime->fail( 'Case #'.$index.' doesn\'t have a test function (Function) defined.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$start--;
|
||||
if ($count>0)
|
||||
$count--;
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* function runSingle
|
||||
* @access public
|
||||
* @param object $testerObject
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
function runSingle( &$testerObject, $fields=array() )
|
||||
{
|
||||
$results = $this->run( $testerObject, $fields, 1, 0 );
|
||||
return $results[0];
|
||||
}
|
||||
public $testCaseFile;
|
||||
public $testCases = array ();
|
||||
|
||||
/**
|
||||
* function runMultiple
|
||||
* @access public
|
||||
* @param object $testerObject
|
||||
* @param array $fields
|
||||
* @param int $count
|
||||
* @param int $start
|
||||
* @return array
|
||||
*/
|
||||
function runMultiple( &$testerObject, $fields=array(), $count = -1, $start=0)
|
||||
{
|
||||
return $this->run( $testerObject, $fields, $count, $start );
|
||||
}
|
||||
/**
|
||||
* function TestCases
|
||||
*
|
||||
* @access public
|
||||
* @param string $testCaseFile
|
||||
* @param string $testDomain
|
||||
* @param string $testLime
|
||||
* @return void
|
||||
*/
|
||||
public function ymlTestCases ($testCaseFile, &$testDomain, &$testLime)
|
||||
{
|
||||
$this->testDomain = & $testDomain;
|
||||
$this->testLime = & $testLime;
|
||||
if (basename( $testCaseFile ) === $testCaseFile) {
|
||||
$testCaseFile = PATH_FIXTURES . $testCaseFile;
|
||||
}
|
||||
$this->testCaseFile = $testCaseFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* function load
|
||||
*
|
||||
* @access public
|
||||
* @param string $inputTestCasesIndex
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
public function load ($inputTestCasesIndex = 'TestCases', $fields = array())
|
||||
{
|
||||
$testCases = array ();
|
||||
$input = sfYAML::Load( /*PATH_FIXTURES .*/ $this->testCaseFile );
|
||||
foreach ($input[$inputTestCasesIndex] as $preTestCase) {
|
||||
$testFunctionInputs = array ();
|
||||
foreach ($preTestCase['Input'] as $inputArgument => $value) {
|
||||
if (substr( $inputArgument, - 2, 2 ) === '[]') {
|
||||
//DOMAIN
|
||||
$inputArgument = substr( $inputArgument, 0, strlen( $inputArgument ) - 2 );
|
||||
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 {
|
||||
//SPECIFIC VALUE
|
||||
if (! isset( $testFunctionInputs[$inputArgument] )) {
|
||||
$testFunctionInputs[$inputArgument] = array ();
|
||||
}
|
||||
ymlDomain::arrayAppend( $testFunctionInputs[$inputArgument], array ($value) );
|
||||
}
|
||||
}
|
||||
/* Start Block: "Explode" all the posible test cases defined in the yml
|
||||
* using domains and single values
|
||||
*/
|
||||
//Initialize $index key values for the first test case (5.2 array_fill_keys(array_keys($testFunctionInputs),0))
|
||||
$index = array_combine( array_keys( $testFunctionInputs ), array_fill( 0, count( $testFunctionInputs ), 0 ) );
|
||||
//array_product()
|
||||
$prod = 1;
|
||||
foreach ($testFunctionInputs as $values) {
|
||||
$prod *= count( $values );
|
||||
}
|
||||
$lastCase = ($prod == 0);
|
||||
while (! $lastCase) {
|
||||
//foreach($index as $v) echo($v);echo("\n");
|
||||
/* Put in $aux one test case */
|
||||
$aux = array ();
|
||||
foreach ($testFunctionInputs as $key => $values) {
|
||||
$aux[$key] = $values[$index[$key]];
|
||||
}
|
||||
/* CREATE TEST CASE: Put $aux test case in $testCases array */
|
||||
$i = count( $testCases );
|
||||
$testCases[$i] = $preTestCase;
|
||||
$testCases[$i]['Input'] = $aux;
|
||||
/* Increse the $index key values to the next test case */
|
||||
$lastCase = true;
|
||||
foreach ($testFunctionInputs as $key => $values) {
|
||||
$index[$key] ++;
|
||||
if ($index[$key] >= count( $values )) {
|
||||
$index[$key] = 0;
|
||||
} else {
|
||||
$lastCase = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*End Block */
|
||||
}
|
||||
/* Start Block: Replace @@ tags variables */
|
||||
foreach ($testCases as $key => $testCase) {
|
||||
$testCases[$key] = testTools::replaceVariables( $testCases[$key] );
|
||||
$testCases[$key]['Input'] = testTools::replaceVariables( $testCases[$key]['Input'], $fields );
|
||||
if (isset( $testCase['Output'] )) {
|
||||
if (isset( $testCase['Output']['Value'] )) {
|
||||
/*$testCases[$key]['Output']['Value'] =
|
||||
unserialize($testCases[$key]['Output']['Value']);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
/* End Block */
|
||||
$this->testCases = $testCases;
|
||||
return $testCases;
|
||||
}
|
||||
|
||||
/**
|
||||
* function load
|
||||
* Increase the number of "planned" tests.
|
||||
*
|
||||
* @access public
|
||||
* @param int $count
|
||||
* @param int $start
|
||||
* @return void
|
||||
*/
|
||||
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 {
|
||||
if (isset( $testCase['Output'] )) {
|
||||
if (isset( $testCase['Output']['Type'] ) || isset( $testCase['Output']['Value'] )) {
|
||||
$this->testLime->plan ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$start --;
|
||||
if ($count > 0) {
|
||||
$count --;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function run
|
||||
*
|
||||
* @access public
|
||||
* @param object $testerObject
|
||||
* @param array $fields
|
||||
* @param int $count
|
||||
* @param int $start
|
||||
* @return array
|
||||
*/
|
||||
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) {
|
||||
$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 {
|
||||
if (isset( $testCase['Function'] )) {
|
||||
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;
|
||||
/* Start Block: Test the $result */
|
||||
if (isset( $testCase['Output'] )) {
|
||||
if (isset( $testCase['Output']['Value'] )) {
|
||||
//$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'] )) {
|
||||
// $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 {
|
||||
$this->testLime->fail( 'Case #' . $index . ': Test function (Function) is not present in tester object.' );
|
||||
}
|
||||
} else {
|
||||
$this->testLime->fail( 'Case #' . $index . ' doesn\'t have a test function (Function) defined.' );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$start --;
|
||||
if ($count > 0) {
|
||||
$count --;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* function runSingle
|
||||
*
|
||||
* @access public
|
||||
* @param object $testerObject
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
public function runSingle (&$testerObject, $fields = array())
|
||||
{
|
||||
$results = $this->run( $testerObject, $fields, 1, 0 );
|
||||
return $results[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* function runMultiple
|
||||
*
|
||||
* @access public
|
||||
* @param object $testerObject
|
||||
* @param array $fields
|
||||
* @param int $count
|
||||
* @param int $start
|
||||
* @return array
|
||||
*/
|
||||
public function runMultiple (&$testerObject, $fields = array(), $count = -1, $start = 0)
|
||||
{
|
||||
return $this->run( $testerObject, $fields, $count, $start );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user