Documentation

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
$version  : mixed

Methods

__construct()  : mixed
Scripts constructor.
addCodeLib()  : mixed
Add a code for JSON output
addHeader()  : mixed
addMessage()  : bool
Add a message to the return data: $this->returnData['messages']
addReturnData()  : true
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
Check if $this->formParams[$key] value has been sent.
checkMandatoryFormParams()  : array<string|int, mixed>|false
Check if it is received mandatory params
checkMandatoryParam()  : bool
Validate that a specific parameter exist: /{end-point}/parameter[0]/parameter[1]/parameter[2]/.
checkMethod()  : bool
CHECK if this->method is allowed
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|null
Retrieve a form parameter by its key.
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()  : void
Rewrite the return response with a new value.
says()  : mixed
send()  : mixed
Echo the result
sendCorsHeaders()  : mixed
Send CORS Headers to allow Ajax Web Calls https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
sendHeaders()  : mixed
sendTerminal()  : mixed
setError()  : mixed
Set and error to be return in JSON format with status $returnStatus
setErrorFromCodelib()  : false
Set an error using $code
setMessage()  : bool
Set a message to the return data: $this->returnData['messages']
setReturnCode()  : mixed
Assign a code
setReturnData()  : true
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

$codeLibError

public mixed $codeLibError = []

$contentTypeReturn

public mixed $contentTypeReturn = 'JSON'

$core

public Core7|null $core = \null

$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 = []

$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

$server

public mixed $server = \null

$serviceParam

public mixed $serviceParam = ''

$urlParams

public mixed $urlParams = ''

$version

protected mixed $version = 'v250421'

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
$code :
$msg :
$error : int = 400
$model : null = null

addHeader()

public addHeader(mixed $key, mixed $value) : mixed
Parameters
$key : mixed
$value : mixed

addMessage()

Add a message to the return data: $this->returnData['messages']

public addMessage(string $message[, string $type = 'success' ][, string $description = '' ][, int $time = 5 ][, string $url = '' ]) : bool
Parameters
$message : string

The message to be added

$type : string = 'success'

The type of message (default: 'success'). Other values 'success','error','warning','info','default'

$description : string = ''

The description of the message (default: empty)

$time : int = 5

The time duration for message display (default: 5)

$url : string = ''

The URL associated with the message (default: empty)

Return values
bool

Always returns true after adding the message to returnData

addReturnData()

Add a new record to be returned

public addReturnData( $value) : true
Parameters
$value :
Return values
true

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
bool

checkCloudFrameWorkSecurity()

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|void

checkMandatoryFormParam()

Check if $this->formParams[$key] value has been sent.

public checkMandatoryFormParam(string $key[, string|array<string|int, mixed> $error_msg = '' ][, array<string|int, mixed> $values = [] ][, int $min_length = 1 ][, null|string $code = null ]) : false|mixed|string
Parameters
$key : string

variable to be received in $this->formParams.

$error_msg : string|array<string|int, mixed> = ''

in case of error is the message to be set in $this->setError(..)

$values : array<string|int, mixed> = []

if it is sent the check if the value match with any of $values or return error

$min_length : int = 1

min length of the content

$code : null|string = null

error code to be returned. 'form-params-error' will be the default value

Return values
false|mixed|string

checkMandatoryFormParams()

Check if it is received mandatory params

public checkMandatoryFormParams(array<string|int, mixed> $keys) : array<string|int, mixed>|false
Parameters
$keys : array<string|int, mixed>

with format: [key1,kye2,..] or [[key1,msg,[allowed,values],min_length],[]]

Return values
array<string|int, mixed>|false

if ok returns the array with $keys values else returns false

checkMandatoryParam()

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
$pos :
$msg : string = ''
$validation : array<string|int, mixed> = []
$code : null = null
Return values
bool

checkMethod()

CHECK if this->method is allowed

public checkMethod(string $methods[, string|arrat $error_msg = '' ]) : bool
Parameters
$methods : string

allowed methods separated by ',': GET,POST

$error_msg : string|arrat = ''

error message in case it is not allowed

Return values
bool

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
$code :

getCodeLibError()

Return the structure of $code in $this->codeLibError if it exists

public getCodeLibError( $code) : int|mixed
Parameters
$code :
Return values
int|mixed

getFormParamater()

Retrieve a form parameter by its key.

public getFormParamater(string $var) : mixed|null
Parameters
$var : string

The key of the form parameter to retrieve.

Return values
mixed|null

Returns the value of the form parameter if it exists, or null if it does not.

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|string

getHeaders()

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|string

getReturnStatus()

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 $default = null ]) : mixed
Parameters
$var : int
$default : mixed = null

optional parameter to return its value in case the parameter does not exist

Tags
retun

null|mixed

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()

Rewrite the return response with a new value.

public rewriteReturnResponse(mixed $response) : void
Parameters
$response : mixed

The new response to rewrite

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()

Send CORS Headers to allow Ajax Web Calls https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

public sendCorsHeaders([string $methods = 'GET,POST,PUT' ][, string $allow_origins = '' ][, string $allow_extra_headers = '' ]) : mixed
Parameters
$methods : string = 'GET,POST,PUT'
$allow_origins : string = ''

'*' by default. Set domains separated by ',' to allow specific origins. It can start with http for specific urls

$allow_extra_headers : string = ''

Access-Control-Allow-Headers extra headers. The framework allows: Content-Type,Authorization,X-Requested-With,cache-control,X-CloudFrameWork-AuthToken,X-CLOUDFRAMEWORK-SECURITY,X-DS-TOKEN,X-REST-TOKEN,X-EXTRA-INFO,X-WEB-KEY,X-SERVER-KEY,X-REST-USERNAME,X-REST-PASSWORD,X-APP-KEY,X-DATA-ENV

sendHeaders()

public sendHeaders() : mixed

sendTerminal()

public sendTerminal(mixed $info) : mixed
Parameters
$info : 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(string $code[, string $extramsg = '' ]) : false
Parameters
$code : string
$extramsg : string = ''
Return values
false

setMessage()

Set a message to the return data: $this->returnData['messages']

public setMessage(string $message[, string $type = 'success' ][, string $description = '' ][, int $time = 5 ][, string $url = '' ]) : bool
Parameters
$message : string

The message to be added

$type : string = 'success'

The type of message (default: 'success')

$description : string = ''

The description of the message (default: empty)

$time : int = 5

The time duration for message display (default: 5)

$url : string = ''

The URL associated with the message (default: empty)

Tags
see
addMessage
Return values
bool

Always returns true after adding the message to returnData

setReturnCode()

Assign a code

public setReturnCode( $code) : mixed
Parameters
$code :

setReturnData()

Init the data to be returned

public setReturnData( $data) : true
Parameters
$data :
Return values
true

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
bool

validatePostData()

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
bool

validatePutData()

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|void

validateValue()

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

        
On this page

Search results