trait Api3TestTrait

Class Api3TestTrait

Properties

protected int $_apiversion Api version - easier to override than just a define

Methods

array
versionThreeAndFour()

Get the api versions to test.

assertAPIArrayComparison(array $result, $expected, array $valuesToExclude = [], string $prefix = '')

Check that api returned 'is_error' => 1 else provide full message

assertAPIDeleted($entity, $id)

Check that a deleted item has been deleted.

assertAPIFailure(array $apiResult, string $prefix = '', null $expectedError = NULL)

Check that api returned 'is_error' => 1.

assertAPISuccess(array $apiResult, string $prefix = '')

Check that api returned 'is_error' => 0.

array|int
callAPIFailure(string $entity, string $action, array $params, string $expectedErrorMessage = NULL, null $extraOutput = NULL)

This function exists to wrap api functions.

array|int
callAPISuccess(string $entity, string $action, array $params = [], mixed $checkAgainst = NULL)

wrap api functions.

array|int
callAPISuccessGetCount(string $entity, array $params, int $count = NULL)

This function exists to wrap api getValue function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks There is a type check in this

array|int
callAPISuccessGetSingle(string $entity, array $params, array $checkAgainst = NULL)

This function exists to wrap api getsingle function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks

array|int
callAPISuccessGetValue(string $entity, array $params, string $type = NULL)

This function exists to wrap api getValue function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks There is a type check in this

array|int
civicrm_api($entity, $action, array $params = [])

A stub for the API interface. This can be overriden by subclasses to change how the API is called.

array|int
runApi4Legacy($v3Entity, $v3Action, array $v3Params = [])

Emulate v3 syntax so we can run api3 tests on v4

array
runApi4LegacyChain(string $key, mixed $params, string $mainEntity, array $result, bool $sequential)

No description

static string
convertEntityNameToApi4(string $legacyName)

Fix the naming differences between api3 & api4 entities.

Details

at line 24
array versionThreeAndFour()

Get the api versions to test.

Return Value

array

at line 48
assertAPIArrayComparison(array $result, $expected, array $valuesToExclude = [], string $prefix = '')

Check that api returned 'is_error' => 1 else provide full message

Parameters

array $result
$expected
array $valuesToExclude
string $prefix Extra test to add to message.

at line 67
assertAPIDeleted($entity, $id)

Check that a deleted item has been deleted.

Parameters

$entity
$id

at line 80
assertAPIFailure(array $apiResult, string $prefix = '', null $expectedError = NULL)

Check that api returned 'is_error' => 1.

Parameters

array $apiResult Api result.
string $prefix Extra test to add to message.
null $expectedError

at line 99
assertAPISuccess(array $apiResult, string $prefix = '')

Check that api returned 'is_error' => 0.

Parameters

array $apiResult Api result.
string $prefix Extra test to add to message.

at line 125
array|int callAPIFailure(string $entity, string $action, array $params, string $expectedErrorMessage = NULL, null $extraOutput = NULL)

This function exists to wrap api functions.

so we can ensure they fail where expected & throw exceptions without litterering the test with checks

Parameters

string $entity
string $action
array $params
string $expectedErrorMessage Error.
null $extraOutput

Return Value

array|int

at line 153
array|int callAPISuccess(string $entity, string $action, array $params = [], mixed $checkAgainst = NULL)

wrap api functions.

so we can ensure they succeed & throw exceptions without litterering the test with checks

Parameters

string $entity
string $action
array $params
mixed $checkAgainst Optional value to check result against, implemented for getvalue,. getcount, getsingle. Note that for getvalue the type is checked rather than the value for getsingle the array is compared against an array passed in - the id is not compared (for better or worse )

Return Value

array|int

Exceptions

CRM_Core_Exception

at line 188
array|int callAPISuccessGetCount(string $entity, array $params, int $count = NULL)

This function exists to wrap api getValue function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks There is a type check in this

Parameters

string $entity
array $params
int $count

Return Value

array|int

Exceptions

CRM_Core_Exception

at line 222
array|int callAPISuccessGetSingle(string $entity, array $params, array $checkAgainst = NULL)

This function exists to wrap api getsingle function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks

Parameters

string $entity
array $params
array $checkAgainst Array to compare result against. - boolean - integer - double - string - array - object

Return Value

array|int

Exceptions

CRM_Core_Exception

at line 261
array|int callAPISuccessGetValue(string $entity, array $params, string $type = NULL)

This function exists to wrap api getValue function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks There is a type check in this

Parameters

string $entity
array $params
string $type Per http://php.net/manual/en/function.gettype.php possible types. - boolean - integer - double - string - array - object

Return Value

array|int

Exceptions

CRM_Core_Exception

at line 290
array|int civicrm_api($entity, $action, array $params = [])

A stub for the API interface. This can be overriden by subclasses to change how the API is called.

Parameters

$entity
$action
array $params

Return Value

array|int

at line 308
array|int runApi4Legacy($v3Entity, $v3Action, array $v3Params = [])

Emulate v3 syntax so we can run api3 tests on v4

Parameters

$v3Entity
$v3Action
array $v3Params

Return Value

array|int

Exceptions

API_Exception
CiviCRM_API3_Exception
Exception

at line 623
protected array runApi4LegacyChain(string $key, mixed $params, string $mainEntity, array $result, bool $sequential)

Parameters

string $key
mixed $params
string $mainEntity
array $result
bool $sequential

Return Value

array

Exceptions

API_Exception

at line 677
static string convertEntityNameToApi4(string $legacyName)

Fix the naming differences between api3 & api4 entities.

Parameters

string $legacyName

Return Value

string