ConformanceTest
extends Api4TestBase
in package
implements
HookInterface
uses
CheckAccessTrait, TableDropperTrait
Tags
Table of Contents
Interfaces
- HookInterface
Properties
- $checkAccessCounts : array<string|int, mixed>
- Number of times hook_checkAccess has fired.
- $testRecords : array<string|int, mixed>
- Records created which will be deleted during tearDown
- $checkAccessGrants : array<string|int, mixed>
- Specify whether to grant access to an entity-action via hook_checkAccess.
Methods
- __construct() : mixed
- cleanup() : void
- Quick clean by emptying tables created for the test.
- createLoggedInUser() : int
- Emulate a logged in user since certain functions use that.
- createTestRecord() : array<string|int, mixed>|null
- Inserts a test record, supplying all required values if not provided.
- getEntitiesHitech() : array<string|int, mixed>
- Get entities to test.
- getEntitiesLotech() : array<string|int, mixed>
- Get entities to test.
- getTestRecord() : array<string|int, mixed>
- on_civi_api4_authorizeRecord() : void
- Listen to 'civi.api4.authorizeRecord'. Override decisions with specified grants.
- saveTestRecords() : Result
- Saves one or more test records, supplying default values.
- setUp() : void
- Set up baseline for testing
- setUpHeadless() : CiviEnvBuilder
- The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
- tearDown() : void
- Post test cleanup.
- testConformance() : void
- testEntitiesProvider() : void
- Ensure that "getEntitiesLotech()" (which is the 'dataProvider') is up to date with "getEntitiesHitech()" (which is a live feed available entities).
- userLogout() : mixed
- checkActions() : array<string|int, mixed>
- checkCreation() : array<string|int, mixed>
- checkCreationDenied() : void
- checkDeleteWithNoId() : mixed
- checkDeletionAllowed() : mixed
- Delete an entity - while having a targeted grant (hook_civirm_checkAccess).
- checkDeletionDenied() : mixed
- Attempt to delete an entity while having explicitly denied permission (hook_civicrm_checkAccess).
- checkEntityInfo() : void
- checkFields() : mixed
- checkGet() : array<string|int, mixed>
- checkGetAllowed() : mixed
- FIXME: Not working. `civi.api4.authorizeRecord` does not work on `get` actions.
- checkGetCount() : void
- checkPostDelete() : mixed
- checkUpdate() : void
- Ensure updating an entity does not alter it
- checkUpdateFailsFromCreate() : void
- checkWrongParamType() : mixed
- deleteTestRecords() : void
- Delete records previously created by the `saveTestRecords` function.
- dropByPrefix() : mixed
- getRequiredValuesToCreate() : array<string|int, mixed>
- Get the required fields for the api entity + action.
- isReadOnly() : bool
- resetCheckAccess() : mixed
- setCheckAccessGrants() : mixed
- toDataProviderArray() : array<string|int, mixed>
- withPrePostLogging() : array<string|int, mixed>
- Temporarily enable logging for `hook_civicrm_pre` and `hook_civicrm_post`.
- createOptionValue() : mixed|null
- Creates a dummy option value when one is required but the option list is empty
- getFkID() : int
- Get an ID for the appropriate entity.
- getRandomValue() : int|null|string
- getRequiredValue() : mixed
- Attempt to get a value using field option, defaults, FKEntity, or a random value based on the data type.
- randomLetters() : string
- Generate some random lowercase letters.
- valsToClause() : mixed
Properties
$checkAccessCounts
Number of times hook_checkAccess has fired.
protected
array<string|int, mixed>
$checkAccessCounts
= []
$testRecords
Records created which will be deleted during tearDown
protected
array<string|int, mixed>
$testRecords
= []
$checkAccessGrants
Specify whether to grant access to an entity-action via hook_checkAccess.
private
array<string|int, mixed>
$checkAccessGrants
= []
Array(string $entityAction => bool $grant). TRUE=>Allow. FALSE=>Deny. Undefined=>No preference.
Methods
__construct()
public
__construct([string $name = NULL ][, array<string|int, mixed> $data = [] ][, string $dataName = '' ]) : mixed
Parameters
- $name : string = NULL
- $data : array<string|int, mixed> = []
- $dataName : string = ''
Tags
cleanup()
Quick clean by emptying tables created for the test.
public
cleanup(array{tablesToTruncate: array} $params) : void
Parameters
- $params : array{tablesToTruncate: array}
createLoggedInUser()
Emulate a logged in user since certain functions use that.
public
createLoggedInUser() : int
value to store a record in the DB (like activity)
Tags
Return values
int —Contact ID of the created user.
createTestRecord()
Inserts a test record, supplying all required values if not provided.
public
createTestRecord(string $entityName[, array<string|int, mixed> $values = [] ]) : array<string|int, mixed>|null
Test records will be automatically deleted if deleteTestRecords
is called.
This is a convenience helper for saveTestRecords
when working with a
single entity.
Parameters
- $entityName : string
- $values : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed>|nullgetEntitiesHitech()
Get entities to test.
public
getEntitiesHitech() : array<string|int, mixed>
This is the hi-tech list as generated via Civi's runtime services. It is canonical, but relies on services that may not be available during early parts of PHPUnit lifecycle.
Tags
Return values
array<string|int, mixed>getEntitiesLotech()
Get entities to test.
public
getEntitiesLotech() : array<string|int, mixed>
This method uses file-scanning only and doesn't include dynamic entities (e.g. from multi-record custom fields) But it may be summoned at any time during PHPUnit lifecycle.
Return values
array<string|int, mixed>getTestRecord()
public
getTestRecord(string $entityName, array<string|int, mixed>|string|int $idOrFilters) : array<string|int, mixed>
Parameters
- $entityName : string
- $idOrFilters : array<string|int, mixed>|string|int
-
Either the entity id or filters like ['name' => 'foo']
Tags
Return values
array<string|int, mixed>on_civi_api4_authorizeRecord()
Listen to 'civi.api4.authorizeRecord'. Override decisions with specified grants.
public
on_civi_api4_authorizeRecord(AuthorizeRecordEvent $e) : void
Parameters
- $e : AuthorizeRecordEvent
saveTestRecords()
Saves one or more test records, supplying default values.
public
saveTestRecords(string $entityName, array<string|int, mixed> $saveParams) : Result
Test records will be deleted when the deleteTestRecords
function is
called, usually in tearDown
.
If the transactional method is in use (and nothing is down to cause
the transaction to commit, such as creating custom fields) then the
deleteTestRecords
function does not need to be called.
Parameters
- $entityName : string
- $saveParams : array<string|int, mixed>
Tags
Return values
ResultsetUp()
Set up baseline for testing
public
setUp() : void
Tags
setUpHeadless()
The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
public
setUpHeadless() : CiviEnvBuilder
It should perform any necessary steps required for putting the database in a consistent baseline -- such as loading schema and extensions.
The utility \Civi\Test::headless()
provides a number of helper functions
for managing this setup, and it includes optimizations to avoid redundant
setup work.
Return values
CiviEnvBuildertearDown()
Post test cleanup.
public
tearDown() : void
Tags
testConformance()
public
testConformance(string $entityName) : void
Parameters
- $entityName : string
-
Ex: 'Contact'
Tags
testEntitiesProvider()
Ensure that "getEntitiesLotech()" (which is the 'dataProvider') is up to date with "getEntitiesHitech()" (which is a live feed available entities).
public
testEntitiesProvider() : void
userLogout()
public
userLogout() : mixed
checkActions()
protected
checkActions(AbstractEntity|string $entityClass) : array<string|int, mixed>
Parameters
- $entityClass : AbstractEntity|string
Tags
Return values
array<string|int, mixed>checkCreation()
protected
checkCreation(string $entityName) : array<string|int, mixed>
Parameters
- $entityName : string
Return values
array<string|int, mixed>checkCreationDenied()
protected
checkCreationDenied(string $entityName, AbstractEntity|string $entityClass) : void
Parameters
- $entityName : string
- $entityClass : AbstractEntity|string
checkDeleteWithNoId()
protected
checkDeleteWithNoId(AbstractEntity|string $entityClass) : mixed
Parameters
- $entityClass : AbstractEntity|string
checkDeletionAllowed()
Delete an entity - while having a targeted grant (hook_civirm_checkAccess).
protected
checkDeletionAllowed(AbstractEntity|string $entityClass, array<string|int, mixed> $entityKeys, string $entityName) : mixed
Parameters
- $entityClass : AbstractEntity|string
- $entityKeys : array<string|int, mixed>
- $entityName : string
checkDeletionDenied()
Attempt to delete an entity while having explicitly denied permission (hook_civicrm_checkAccess).
protected
checkDeletionDenied(AbstractEntity|string $entityClass, array<string|int, mixed> $entityKeys, string $entityName) : mixed
Parameters
- $entityClass : AbstractEntity|string
- $entityKeys : array<string|int, mixed>
- $entityName : string
checkEntityInfo()
protected
checkEntityInfo(AbstractEntity|string $entityClass) : void
Parameters
- $entityClass : AbstractEntity|string
checkFields()
protected
checkFields(string $entityName) : mixed
Parameters
- $entityName : string
Tags
checkGet()
protected
checkGet(string $entityName, array<string|int, mixed> $entityKeys) : array<string|int, mixed>
Parameters
- $entityName : string
- $entityKeys : array<string|int, mixed>
Return values
array<string|int, mixed>checkGetAllowed()
FIXME: Not working. `civi.api4.authorizeRecord` does not work on `get` actions.
protected
checkGetAllowed(mixed $entityClass, mixed $id, mixed $entityName) : mixed
Parameters
- $entityClass : mixed
- $id : mixed
- $entityName : mixed
checkGetCount()
protected
checkGetCount(AbstractEntity|string $entityClass, array<string|int, mixed> $entityKeys, string $entityName) : void
Parameters
- $entityClass : AbstractEntity|string
- $entityKeys : array<string|int, mixed>
- $entityName : string
checkPostDelete()
protected
checkPostDelete(AbstractEntity|string $entityClass, array<string|int, mixed> $entityKeys, string $entityName) : mixed
Parameters
- $entityClass : AbstractEntity|string
- $entityKeys : array<string|int, mixed>
- $entityName : string
checkUpdate()
Ensure updating an entity does not alter it
protected
checkUpdate(string $entityName, array<string|int, mixed> $entityKeys, array<string|int, mixed> $getResult) : void
Parameters
- $entityName : string
- $entityKeys : array<string|int, mixed>
- $getResult : array<string|int, mixed>
Tags
checkUpdateFailsFromCreate()
protected
checkUpdateFailsFromCreate(AbstractEntity|string $entityClass, array<string|int, mixed> $entityKeys) : void
Parameters
- $entityClass : AbstractEntity|string
- $entityKeys : array<string|int, mixed>
checkWrongParamType()
protected
checkWrongParamType(AbstractEntity|string $entityClass) : mixed
Parameters
- $entityClass : AbstractEntity|string
deleteTestRecords()
Delete records previously created by the `saveTestRecords` function.
protected
deleteTestRecords() : void
This should be called during the tearDown
function if the test
class does not use the transactional interface.
Tags
dropByPrefix()
protected
dropByPrefix(mixed $prefix) : mixed
Parameters
- $prefix : mixed
getRequiredValuesToCreate()
Get the required fields for the api entity + action.
protected
getRequiredValuesToCreate(string $entity[, array<string|int, mixed> $values = [] ]) : array<string|int, mixed>
Parameters
- $entity : string
- $values : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed>isReadOnly()
protected
isReadOnly(string $entityName) : bool
Parameters
- $entityName : string
Return values
boolresetCheckAccess()
protected
resetCheckAccess() : mixed
setCheckAccessGrants()
protected
setCheckAccessGrants(array<string|int, mixed> $list) : mixed
Parameters
- $list : array<string|int, mixed>
-
Ex: ["Event::delete" => TRUE, "Contribution::delete" => FALSE]
toDataProviderArray()
protected
toDataProviderArray(array<string|int, mixed> $names) : array<string|int, mixed>
Parameters
- $names : array<string|int, mixed>
-
List of entity names. Ex: ['Foo', 'Bar']
Return values
array<string|int, mixed> —List of data-provider arguments, one for each entity-name. Ex: ['Foo' => ['Foo'], 'Bar' => ['Bar']]
withPrePostLogging()
Temporarily enable logging for `hook_civicrm_pre` and `hook_civicrm_post`.
protected
withPrePostLogging(callable $callable) : array<string|int, mixed>
Parameters
- $callable : callable
-
Run this function. Create a log while running this function.
Return values
array<string|int, mixed> —Log; list of times the hooks were called. Ex: ['pre.Event.delete', 'post.Event.delete']
createOptionValue()
Creates a dummy option value when one is required but the option list is empty
private
createOptionValue(string $tableName, string $fieldName) : mixed|null
Parameters
- $tableName : string
- $fieldName : string
Return values
mixed|nullgetFkID()
Get an ID for the appropriate entity.
private
getFkID(string $fkEntity) : int
Parameters
- $fkEntity : string
Tags
Return values
intgetRandomValue()
private
getRandomValue(mixed $dataType) : int|null|string
Parameters
- $dataType : mixed
Tags
Return values
int|null|stringgetRequiredValue()
Attempt to get a value using field option, defaults, FKEntity, or a random value based on the data type.
private
getRequiredValue(array<string|int, mixed> $field) : mixed
Parameters
- $field : array<string|int, mixed>
Tags
randomLetters()
Generate some random lowercase letters.
private
randomLetters([int $len = 10 ]) : string
Parameters
- $len : int = 10
Return values
stringvalsToClause()
private
static valsToClause(array<string|int, mixed> $vals) : mixed
Parameters
- $vals : array<string|int, mixed>