Tests
extends RESTful
in package
Class to facilitate Tests creation author: hl@cloudframework.io
Table of Contents
Properties
- $apiName : mixed
- $argv : mixed
- $auth : mixed
- $code : mixed
- $codeLib : mixed
- $codeLibError : mixed
- $contentTypeReturn : mixed
- $core : Core7|null
- $dv : DataValidation
- $error : mixed
- $errorMsg : mixed
- $errors : mixed
- $errorsMsg : mixed
- $extra_headers : mixed
- $formParams : mixed
- $headers : mixed
- $message : mixed
- $method : mixed
- $ok : mixed
- $org_id : mixed
- $params : mixed
- $rawData : mixed
- $referer : mixed
- $requestHeaders : mixed
- $response : mixed
- $response_headers : mixed
- $returnData : mixed
- $rewrite : mixed
- $server : mixed
- $service : mixed
- $serviceParam : mixed
- $tests : mixed
- $url : mixed
- $urlParams : mixed
Methods
- __construct() : mixed
- Scripts constructor.
- addCodeLib() : mixed
- Add a code for JSON output
- addHeader() : mixed
- addReturnData() : mixed
- Add a new record to be returned
- addsError() : mixed
- addsHeaders() : mixed
- checkBasicAuthSecurity() : bool
- Check if an Authorization-Header Basic has been sent and match with any core.system.authorizations config var.
- checkCloudFrameWorkSecurity() : mixed
- checkFormParamsFromModel() : bool|void
- Evaluate $data and if it is correct using $model. It uses the class DataValidation
- checkMandatoryFormParam() : false|mixed|string
- Validate a $this->formParams[$key] value as mandatory
- checkMandatoryFormParams() : bool|void
- Check if it is received mandatory params
- checkMandatoryParam() : bool
- Validate that a specific parameter exist: /{end-point}/parameter[0]/parameter[1]/parameter[2]/.
- checkMethod() : mixed
- checksIfResponseCodeIs() : mixed
- checksIfResponseContains() : mixed
- checksIfResponseContainsJSON() : mixed
- connects() : mixed
- ends() : mixed
- existBasicAuth() : mixed
- getCloudFrameWorkSecurityInfo() : mixed
- getCodeLib() : mixed
- Return the structure of $code in $this->codeLib if it exists
- getCodeLibError() : int|mixed
- Return the structure of $code in $this->codeLibError if it exists
- getFormParamater() : mixed
- Return the value of $this->formParams[$var]. Return null if $var does not exist
- getHeader() : string
- Return the user header key value. In PHP those are $_SERVER["HTTP_$headerKey}"].
- getHeaderAuthorization() : null|string
- Returns the info of the header Authorization if it exists, otherwise null
- getHeaders() : array<string|int, mixed>
- Return all the header keys sent by the user. In PHP those are $_SERVER['HTTP_{varname}']
- getHeadersToResend() : mixed
- getOptionValue() : mixed
- getRequestHeader() : mixed
- getResponseHeader() : mixed
- Translate Error codes into headers.
- getResponseHeaders() : mixed
- getReturnCode() : int|string
- Return the code applied with setError and defined in __codes
- getReturnStatus() : mixed
- gets() : mixed
- getUrlPathParamater() : mixed
- Return the value of $this->params[$var]. Return null if $var does not exist
- hasOption() : mixed
- posts() : mixed
- prompts() : mixed
- puts() : mixed
- rewriteReturnResponse() : mixed
- says() : mixed
- send() : mixed
- Echo the result
- sendCorsHeaders() : mixed
- Setup CORS Headers to allow Ajax Web Calls
- sendHeaders() : mixed
- sendTerminal() : mixed
- setAuth() : mixed
- setError() : mixed
- Set and error to be return in JSON format with status $returnStatus
- setErrorFromCodelib() : mixed
- Set an error using $code
- setReturnCode() : mixed
- Assign a code
- setReturnData() : mixed
- Init the data to be returned
- setReturnFormat() : mixed
- setReturnResponse() : mixed
- setReturnStatus() : mixed
- updateReturnResponse() : mixed
- useFunction() : bool
- Execute a method if $method is defined.
- validatePostData() : bool
- Check the form paramters received based in a json model
- validatePutData() : bool|void
- Validate data received in $this->formParams to update a record
- validateValue() : mixed
- wants() : mixed
Properties
$apiName
public
mixed
$apiName
= ''
$argv
public
mixed
$argv
$auth
public
mixed
$auth
= \true
$code
public
mixed
$code
= \null
$codeLib
public
mixed
$codeLib
= []
$codeLibError
public
mixed
$codeLibError
= []
$contentTypeReturn
public
mixed
$contentTypeReturn
= 'JSON'
$core
public
Core7|null
$core
= \null
$dv
public
DataValidation
$dv
$error
public
mixed
$error
= 0
$errorMsg
public
mixed
$errorMsg
= []
$errors
public
mixed
$errors
= \false
$errorsMsg
public
mixed
$errorsMsg
= []
$extra_headers
public
mixed
$extra_headers
= []
$formParams
public
mixed
$formParams
= array()
$headers
public
mixed
$headers
= []
$message
public
mixed
$message
= ""
$method
public
mixed
$method
= ''
$ok
public
mixed
$ok
= 200
$org_id
public
mixed
$org_id
= ''
$params
public
mixed
$params
= array()
$rawData
public
mixed
$rawData
= array()
$referer
public
mixed
$referer
= \null
$requestHeaders
public
mixed
$requestHeaders
= array()
$response
public
mixed
$response
= \null
$response_headers
public
mixed
$response_headers
= \null
$returnData
public
mixed
$returnData
= \null
$rewrite
public
mixed
$rewrite
= []
$server
public
mixed
$server
= \null
$service
public
mixed
$service
= ''
$serviceParam
public
mixed
$serviceParam
= ''
$tests
public
mixed
$tests
$url
public
mixed
$url
= ''
$urlParams
public
mixed
$urlParams
= ''
Methods
__construct()
Scripts constructor.
public
__construct(Core $core[, null $argv = null ]) : mixed
Parameters
- $core : Core
- $argv : null = null
addCodeLib()
Add a code for JSON output
public
addCodeLib( $code, $msg[, int $error = 400 ][, null $model = null ]) : mixed
Parameters
addHeader()
public
addHeader(mixed $key, mixed $value) : mixed
Parameters
- $key : mixed
- $value : mixed
addReturnData()
Add a new record to be returned
public
addReturnData( $value) : mixed
Parameters
addsError()
public
addsError(mixed $error) : mixed
Parameters
- $error : mixed
addsHeaders()
public
addsHeaders(mixed $headers) : mixed
Parameters
- $headers : mixed
checkBasicAuthSecurity()
Check if an Authorization-Header Basic has been sent and match with any core.system.authorizations config var.
public
checkBasicAuthSecurity([string $id = '' ]) : bool
Parameters
- $id : string = ''
Return values
boolcheckCloudFrameWorkSecurity()
public
checkCloudFrameWorkSecurity([mixed $time = 0 ][, mixed $id = '' ]) : mixed
Parameters
- $time : mixed = 0
- $id : mixed = ''
checkFormParamsFromModel()
Evaluate $data and if it is correct using $model. It uses the class DataValidation
public
checkFormParamsFromModel( &$model[, bool $all = true ][, string $codelibbase = '' ][, null &$data = null ][, array<string|int, mixed> &$dictionaries = [] ]) : bool|void
Parameters
- $model :
- $all : bool = true
- $codelibbase : string = ''
- $data : null = null
- $dictionaries : array<string|int, mixed> = []
Return values
bool|voidcheckMandatoryFormParam()
Validate a $this->formParams[$key] value as mandatory
public
checkMandatoryFormParam( $key[, string $msg = '' ][, array<string|int, mixed> $values = [] ][, int $min_length = 1 ][, null $code = null ]) : false|mixed|string
Parameters
- $key :
- $msg : string = ''
- $values : array<string|int, mixed> = []
- $min_length : int = 1
- $code : null = null
Return values
false|mixed|stringcheckMandatoryFormParams()
Check if it is received mandatory params
public
checkMandatoryFormParams(array<string|int, mixed> $keys) : bool|void
Parameters
- $keys : array<string|int, mixed>
-
with format: [key1,kye2,..] or [[key1,msg,[allowed,values],min_length],[]]
Return values
bool|voidcheckMandatoryParam()
Validate that a specific parameter exist: /{end-point}/parameter[0]/parameter[1]/parameter[2]/.
public
checkMandatoryParam( $pos[, string $msg = '' ][, array<string|int, mixed> $validation = [] ][, null $code = null ]) : bool
.
Parameters
Return values
boolcheckMethod()
public
checkMethod(mixed $methods[, mixed $msg = '' ]) : mixed
Parameters
- $methods : mixed
- $msg : mixed = ''
checksIfResponseCodeIs()
public
checksIfResponseCodeIs(mixed $code) : mixed
Parameters
- $code : mixed
checksIfResponseContains()
public
checksIfResponseContains(mixed $text) : mixed
Parameters
- $text : mixed
checksIfResponseContainsJSON()
public
checksIfResponseContainsJSON(mixed $json) : mixed
Parameters
- $json : mixed
connects()
public
connects(mixed $server) : mixed
Parameters
- $server : mixed
ends()
public
ends() : mixed
existBasicAuth()
public
existBasicAuth() : mixed
getCloudFrameWorkSecurityInfo()
public
getCloudFrameWorkSecurityInfo() : mixed
getCodeLib()
Return the structure of $code in $this->codeLib if it exists
public
getCodeLib( $code) : mixed
Parameters
getCodeLibError()
Return the structure of $code in $this->codeLibError if it exists
public
getCodeLibError( $code) : int|mixed
Parameters
Return values
int|mixedgetFormParamater()
Return the value of $this->formParams[$var]. Return null if $var does not exist
public
getFormParamater(string $var) : mixed
Parameters
- $var : string
Tags
getHeader()
Return the user header key value. In PHP those are $_SERVER["HTTP_$headerKey}"].
public
getHeader(string $headerKey) : string
Parameters
- $headerKey : string
-
The name of the header. Vars like X-VAR or X_VAR are treated like the same
Return values
string —If the key does not exist return empty string
getHeaderAuthorization()
Returns the info of the header Authorization if it exists, otherwise null
public
getHeaderAuthorization() : null|string
Return values
null|stringgetHeaders()
Return all the header keys sent by the user. In PHP those are $_SERVER['HTTP_{varname}']
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getHeadersToResend()
public
getHeadersToResend([mixed $extra_headers = null ]) : mixed
Parameters
- $extra_headers : mixed = null
getOptionValue()
public
getOptionValue(mixed $option) : mixed
Parameters
- $option : mixed
getRequestHeader()
public
getRequestHeader(mixed $str) : mixed
Parameters
- $str : mixed
getResponseHeader()
Translate Error codes into headers.
public
getResponseHeader() : mixed
Useful info: https://restfulapi.net/http-status-codes/
getResponseHeaders()
public
getResponseHeaders() : mixed
getReturnCode()
Return the code applied with setError and defined in __codes
public
getReturnCode() : int|string
Return values
int|stringgetReturnStatus()
public
getReturnStatus() : mixed
gets()
public
gets(mixed $url[, mixed $data = null ][, mixed $raw = false ]) : mixed
Parameters
- $url : mixed
- $data : mixed = null
- $raw : mixed = false
getUrlPathParamater()
Return the value of $this->params[$var]. Return null if $var does not exist
public
getUrlPathParamater(int $var) : mixed
Parameters
- $var : int
Tags
hasOption()
public
hasOption(mixed $option) : mixed
Parameters
- $option : mixed
posts()
public
posts(mixed $url[, mixed $data = null ][, mixed $raw = false ]) : mixed
Parameters
- $url : mixed
- $data : mixed = null
- $raw : mixed = false
prompts()
public
prompts(mixed $title[, mixed $default = null ]) : mixed
Parameters
- $title : mixed
- $default : mixed = null
puts()
public
puts(mixed $url[, mixed $data = null ][, mixed $raw = false ]) : mixed
Parameters
- $url : mixed
- $data : mixed = null
- $raw : mixed = false
rewriteReturnResponse()
public
rewriteReturnResponse(mixed $response) : mixed
Parameters
- $response : mixed
says()
public
says(mixed $something) : mixed
Parameters
- $something : mixed
send()
Echo the result
public
send([bool $pretty = false ][, bool $return = false ][, array<string|int, mixed> $argv = [] ]) : mixed
Parameters
- $pretty : bool = false
-
if true, returns the JSON string with JSON_PRETTY_PRINT
- $return : bool = false
-
if true, instead to echo then return the output.
- $argv : array<string|int, mixed> = []
-
if we are running from a terminal it will receive the command line args.
sendCorsHeaders()
Setup CORS Headers to allow Ajax Web Calls
public
sendCorsHeaders([string $methods = 'GET,POST,PUT' ][, string $origin = '' ][, string $allow_extra_headers = '' ]) : mixed
Parameters
- $methods : string = 'GET,POST,PUT'
- $origin : string = ''
- $allow_extra_headers : string = ''
-
If you need to add headers to be allowed use this variable.
sendHeaders()
public
sendHeaders() : mixed
sendTerminal()
public
sendTerminal(mixed $info) : mixed
Parameters
- $info : mixed
setAuth()
public
setAuth(mixed $val[, mixed $msg = '' ]) : mixed
Parameters
- $val : mixed
- $msg : mixed = ''
setError()
Set and error to be return in JSON format with status $returnStatus
public
setError(mixed $error[, int $returnStatus = 400 ][, mixed $returnCode = null ][, string $message = '' ]) : mixed
Parameters
- $error : mixed
-
Error to show. It can be a string or and array
- $returnStatus : int = 400
-
integer >=200. 400 by default
- $returnCode : mixed = null
-
optional returnCode
- $message : string = ''
setErrorFromCodelib()
Set an error using $code
public
setErrorFromCodelib( $code[, string $extramsg = '' ]) : mixed
Parameters
Tags
setReturnCode()
Assign a code
public
setReturnCode( $code) : mixed
Parameters
setReturnData()
Init the data to be returned
public
setReturnData( $data) : mixed
Parameters
setReturnFormat()
public
setReturnFormat(mixed $method) : mixed
Parameters
- $method : mixed
setReturnResponse()
public
setReturnResponse(mixed $response) : mixed
Parameters
- $response : mixed
setReturnStatus()
public
setReturnStatus(mixed $status) : mixed
Parameters
- $status : mixed
updateReturnResponse()
public
updateReturnResponse(mixed $response) : mixed
Parameters
- $response : mixed
useFunction()
Execute a method if $method is defined.
public
useFunction(string $method) : bool
Parameters
- $method : string
-
name of the method
Return values
boolvalidatePostData()
Check the form paramters received based in a json model
public
validatePostData(array<string|int, mixed> $model[, string $codelibbase = 'error-form-params' ][, null &$data = null ][, mixed &$dictionaries = [] ]) : bool
Parameters
- $model : array<string|int, mixed>
- $codelibbase : string = 'error-form-params'
- $data : null = null
- $dictionaries : mixed = []
Return values
boolvalidatePutData()
Validate data received in $this->formParams to update a record
public
validatePutData( $model[, string $codelibbase = 'error-form-params' ][, null &$data = null ][, array<string|int, mixed> &$dictionaries = [] ]) : bool|void
Parameters
- $model :
- $codelibbase : string = 'error-form-params'
- $data : null = null
- $dictionaries : array<string|int, mixed> = []
Return values
bool|voidvalidateValue()
public
validateValue(string $field, mix $value, string $type[, string $validation = '' ][, string $msg_error = '' ]) : mixed
Parameters
- $field : string
- $value : mix
- $type : string
- $validation : string = ''
- $msg_error : string = ''
wants()
public
wants(mixed $wish) : mixed
Parameters
- $wish : mixed