Documentation

ManagedEntityTest extends TestCase
in package
implements HeadlessInterface, TransactionalInterface, HookInterface uses Api4TestTrait

Tags
group

headless

Table of Contents

Interfaces

HeadlessInterface
Interface HeadlessInterface
TransactionalInterface
Interface HeadlessInterface
HookInterface

Properties

$testRecords  : array<string|int, mixed>
Records created which will be deleted during tearDown
$_managedEntities  : array<string|int, array<string|int, mixed>>

Methods

createTestRecord()  : array<string|int, mixed>|null
Inserts a test record, supplying all required values if not provided.
getTestRecord()  : array<string|int, mixed>
hook_civicrm_managed()  : void
sampleEntityTypes()  : mixed
saveTestRecords()  : Result
Saves one or more test records, supplying default values.
setUp()  : void
setUpHeadless()  : CiviEnvBuilder
The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
tearDown()  : void
testAutoUpdateSearch()  : void
testExportAndCreateGroup()  : void
testGetFields()  : void
testIsApi4ManagedType()  : void
testManagedNavigationWeights()  : void
testMatchExisting()  : void
Tests a scenario where a record may already exist and we want to make it a managed entity.
testMultiDomainNavigation()  : void
Test multisite managed entities
testOptionGroupAndValues()  : void
testRemoveDeleted()  : void
Tests removing a managed record when the underlying entity that has been deleted
testRevertSavedSearch()  : void
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
getCurrentTimestamp()  : string
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

$testRecords

Records created which will be deleted during tearDown

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

$_managedEntities

private array<string|int, array<string|int, mixed>> $_managedEntities = []

Methods

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>

hook_civicrm_managed()

public hook_civicrm_managed(array<string|int, mixed> &$entities) : void
Parameters
$entities : 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

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

testIsApi4ManagedType()

public testIsApi4ManagedType(string $entityName, bool $expected) : void
Parameters
$entityName : string
$expected : bool
Tags
dataProvider

sampleEntityTypes

testMatchExisting()

Tests a scenario where a record may already exist and we want to make it a managed entity.

public testMatchExisting() : void
Tags
throws
CRM_Core_Exception

testMultiDomainNavigation()

Test multisite managed entities

public testMultiDomainNavigation() : void
Tags
see
MultisiteManaged

testRemoveDeleted()

Tests removing a managed record when the underlying entity that has been deleted

public testRemoveDeleted() : void
Tags
throws
CRM_Core_Exception

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

getCurrentTimestamp()

private getCurrentTimestamp() : string
Return values
string

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