Documentation

ContactAclTest extends Api4TestBase
in package
implements TransactionalInterface, HookInterface uses ACLPermissionTrait

Tags
group

headless

Table of Contents

Interfaces

TransactionalInterface
Interface HeadlessInterface
HookInterface
Interface HookInterface

Properties

$allowedContactId  : int
ContactID of allowed Contact
$allowedContacts  : array<string|int, mixed>
Array of allowed contactIds
$scenarioIDs  : array<string|int, mixed>
Ids created for the scenario in use.
$testRecords  : array<string|int, mixed>
Records created which will be deleted during tearDown

Methods

__construct()  : mixed
aclWhereGreaterThan()  : void
Results after the allowedContact are returned.
aclWhereHookAllResults()  : void
All results returned.
aclWhereHookNoResults()  : void
No results returned.
aclWhereMultipleContacts()  : mixed
Only specified contact returned.
aclWhereOnlyOne()  : void
Only specified contact returned.
aclWhereOnlySecond()  : void
All but first results returned.
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.
getTestRecord()  : array<string|int, mixed>
saveTestRecords()  : Result
Saves one or more test records, supplying default values.
setupCoreACLPermittedAcl()  : void
Set up a core ACL.
setUpHeadless()  : CiviEnvBuilder
The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
setupScenarioCoreACLEveryonePermittedToEvent()  : void
Set up a scenario where everyone can access the permissioned group.
setupScenarioCoreACLEveryonePermittedToGroup()  : void
Set up a scenario where everyone can access the permissioned group.
tearDown()  : void
Post test cleanup.
testBasicContactPermissions()  : void
testContactAclClauseDedupe()  : void
testContactAclForRelatedEntity()  : void
testPermissionInfo()  : void
userLogout()  : mixed
cleanupCachedPermissions()  : void
Clean up places where permissions get cached.
deleteTestRecords()  : void
Delete records previously created by the `saveTestRecords` function.
getRequiredValuesToCreate()  : array<string|int, mixed>
Get the required fields for the api entity + action.
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.

Properties

$allowedContactId

ContactID of allowed Contact

protected int $allowedContactId = 0

$allowedContacts

Array of allowed contactIds

protected array<string|int, mixed> $allowedContacts = []

$scenarioIDs

Ids created for the scenario in use.

protected array<string|int, mixed> $scenarioIDs = []

$testRecords

Records created which will be deleted during tearDown

protected array<string|int, mixed> $testRecords = []

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
see
CiviUnitTestCase

aclWhereGreaterThan()

Results after the allowedContact are returned.

public aclWhereGreaterThan(string $type, array<string|int, mixed> &$tables, array<string|int, mixed> &$whereTables, int &$contactID, string|null &$where) : void
Parameters
$type : string
$tables : array<string|int, mixed>
$whereTables : array<string|int, mixed>
$contactID : int
$where : string|null
Tags
implements

CRM_Utils_Hook::aclWhereClause

noinspection

PhpUnusedParameterInspection

aclWhereHookAllResults()

All results returned.

public aclWhereHookAllResults(string $type, array<string|int, mixed> &$tables, array<string|int, mixed> &$whereTables, int &$contactID, string|null &$where) : void
Parameters
$type : string
$tables : array<string|int, mixed>
$whereTables : array<string|int, mixed>
$contactID : int
$where : string|null
Tags
implements

CRM_Utils_Hook::aclWhereClause

noinspection

PhpUnusedParameterInspection

aclWhereHookNoResults()

No results returned.

public aclWhereHookNoResults(string $type, array<string|int, mixed> &$tables, array<string|int, mixed> &$whereTables, int &$contactID, string|null &$where) : void
Parameters
$type : string
$tables : array<string|int, mixed>
$whereTables : array<string|int, mixed>
$contactID : int
$where : string|null
Tags
implements

CRM_Utils_Hook::aclWhereClause

aclWhereMultipleContacts()

Only specified contact returned.

public aclWhereMultipleContacts(mixed $type, mixed &$tables, mixed &$whereTables, mixed &$contactID, mixed &$where) : mixed
Parameters
$type : mixed
$tables : mixed
$whereTables : mixed
$contactID : mixed
$where : mixed
Tags
implements

CRM_Utils_Hook::aclWhereClause

aclWhereOnlyOne()

Only specified contact returned.

public aclWhereOnlyOne(string $type, array<string|int, mixed> &$tables, array<string|int, mixed> &$whereTables, int &$contactID, string|null &$where) : void
Parameters
$type : string
$tables : array<string|int, mixed>
$whereTables : array<string|int, mixed>
$contactID : int
$where : string|null
Tags
implements

CRM_Utils_Hook::aclWhereClause

noinspection

PhpUnusedParameterInspection

aclWhereOnlySecond()

All but first results returned.

public aclWhereOnlySecond(string $type, array<string|int, mixed> &$tables, array<string|int, mixed> &$whereTables, int &$contactID, string|null &$where) : void
Parameters
$type : string
$tables : array<string|int, mixed>
$whereTables : array<string|int, mixed>
$contactID : int
$where : string|null
Tags
implements

CRM_Utils_Hook::aclWhereClause

noinspection

PhpUnusedParameterInspection

cleanup()

Quick clean by emptying tables created for the test.

public cleanup(array{tablesToTruncate: array} $params) : void
Parameters
$params : array{tablesToTruncate: array}

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
noinspection

PhpDocMissingThrowsInspection

noinspection

PhpUnhandledExceptionInspection

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

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
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

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
noinspection

PhpDocMissingThrowsInspection

noinspection

PhpUnhandledExceptionInspection

Return values
Result

setupCoreACLPermittedAcl()

Set up a core ACL.

public setupCoreACLPermittedAcl([array<string|int, mixed> $permissionedEntities = [] ][, string|int $groupAllowedAccess = 'Everyone' ][, string $operation = 'View' ][, string $entity = 'Group' ]) : void

It is recommended that this helper function is accessed through a scenario function.

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

Array of groups for whom ACLs enable access.

$groupAllowedAccess : string|int = 'Everyone'

Group permitted to access the permissioned Group An ID of 0 means that 'Everyone' can access the group.

$operation : string = 'View'

View|Edit|Create|Delete|Search|All

$entity : string = 'Group'

Group|CustomGroup|Profile|Event

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
CiviEnvBuilder

setupScenarioCoreACLEveryonePermittedToEvent()

Set up a scenario where everyone can access the permissioned group.

public setupScenarioCoreACLEveryonePermittedToEvent() : void

A scenario in this class involves multiple defined assets. In this case we create

  • a group to which the everyone has permission
  • a contact in the group
  • a contact not in the group

These are arrayed as follows $this->scenarioIDs['Contact'] = ['permitted_contact' => x, 'non_permitted_contact' => y] $this->scenarioIDs['Group'] = ['permitted_group' => x]

setupScenarioCoreACLEveryonePermittedToGroup()

Set up a scenario where everyone can access the permissioned group.

public setupScenarioCoreACLEveryonePermittedToGroup() : void

A scenario in this class involves multiple defined assets. In this case we create

  • a group to which the everyone has permission
  • a contact in the group
  • a contact not in the group

These are arrayed as follows $this->scenarioIDs['Contact'] = ['permitted_contact' => x, 'non_permitted_contact' => y] $this->scenarioIDs['Group'] = ['permitted_group' => x]

testBasicContactPermissions()

public testBasicContactPermissions() : void

testContactAclClauseDedupe()

public testContactAclClauseDedupe() : void

testContactAclForRelatedEntity()

public testContactAclForRelatedEntity() : void

cleanupCachedPermissions()

Clean up places where permissions get cached.

protected cleanupCachedPermissions() : void
Tags
noinspection

PhpUnhandledExceptionInspection

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
noinspection

PhpUnhandledExceptionInspection

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
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

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

getFkID()

Get an ID for the appropriate entity.

private getFkID(string $fkEntity) : int
Parameters
$fkEntity : string
Tags
throws
CRM_Core_Exception
Return values
int

getRandomValue()

private getRandomValue(mixed $dataType) : int|null|string
Parameters
$dataType : mixed
Tags
noinspection

PhpUnhandledExceptionInspection

noinspection

PhpDocMissingThrowsInspection

Return values
int|null|string

getRequiredValue()

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
throws
CRM_Core_Exception

randomLetters()

Generate some random lowercase letters.

private randomLetters([int $len = 10 ]) : string
Parameters
$len : int = 10
Return values
string

        
On this page

Search results