Documentation

AfformTest extends AfformTestCase
in package
implements TransactionalInterface

Afform.Get API Test Case This is a generic test class implemented with PHPUnit.

Tags
group

headless

Table of Contents

Interfaces

TransactionalInterface
Interface HeadlessInterface

Properties

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

Methods

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.
getBasicDirectives()  : mixed
getFormatExamples()  : mixed
getTestRecord()  : array<string|int, mixed>
getWhitespaceExamples()  : mixed
registerTestRecord()  : void
Register a record to be automatically cleaned up during tearDown
saveTestRecords()  : Result
Saves one or more test records, supplying default values.
setUp()  : void
The setup() method is executed before the test is executed (optional).
setUpHeadless()  : mixed
Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
testAutoRequires()  : void
testBasicConvert()  : void
In this test, we receive a layout
testGetUpdateRevert()  : void
This takes the bundled `example-page` and performs some API calls on it.
testUpdateAndGetFormat()  : void
In this test, we update the layout and in one format and then read it back in another format.
testWhitespaceFormat()  : void
This tests that a non-pretty html string will have its whitespace stripped & reformatted when using the "formatWhitespace" option.
userLogout()  : mixed
conditionallyDeleteTestRecords()  : 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
fudgeMarkup()  : array<string|int, mixed>|string
DOMDocument outputs some tags a little different than they were input.
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.
isMissingValue()  : bool
randomLetters()  : string
Generate some random lowercase letters.

Properties

$testRecords

Records created which will be deleted during tearDown

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

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

getBasicDirectives()

public static getBasicDirectives() : mixed

getFormatExamples()

public static getFormatExamples() : mixed

getTestRecord()

public getTestRecord(string $entityName, array<string|int, mixed>|string|int $idOrFilters[, array<string|int, mixed> $select = [] ]) : array<string|int, mixed>
Parameters
$entityName : string
$idOrFilters : array<string|int, mixed>|string|int

Either the entity id or filters like ['name' => 'foo']

$select : array<string|int, mixed> = []
Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

getWhitespaceExamples()

public static getWhitespaceExamples() : mixed

registerTestRecord()

Register a record to be automatically cleaned up during tearDown

public registerTestRecord(string $entityName, string|int|array<string|int, mixed> $where) : void
Parameters
$entityName : string
$where : string|int|array<string|int, mixed>

Where clause (or for short, just the ID)

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

setUp()

The setup() method is executed before the test is executed (optional).

public setUp() : void

setUpHeadless()

Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().

public setUpHeadless() : mixed

See: https://github.com/civicrm/org.civicrm.testapalooza/blob/master/civi-test.md

testAutoRequires()

public testAutoRequires() : void

testBasicConvert()

In this test, we receive a layout

public testBasicConvert(string $formName, string $updateFormat, mixed $updateLayout, string $readFormat, mixed $readLayout, string $exampleName) : void
Parameters
$formName : string

The symbolic name of the form.

$updateFormat : string

The format with which to write the data. 'html' or 'array'

$updateLayout : mixed

The new value to set

$readFormat : string

The format with which to read the data. 'html' or 'array'

$readLayout : mixed

The value that we expect to read.

$exampleName : string

(For debug messages) A symbolic name of the example data-set being tested.

Tags
dataProvider

getFormatExamples

testGetUpdateRevert()

This takes the bundled `example-page` and performs some API calls on it.

public testGetUpdateRevert(string $formName, array<string|int, mixed> $originalMetadata) : void
Parameters
$formName : string

The symbolic name of the form.

$originalMetadata : array<string|int, mixed>
Tags
dataProvider

getBasicDirectives

testUpdateAndGetFormat()

In this test, we update the layout and in one format and then read it back in another format.

public testUpdateAndGetFormat(string $formName, string $updateFormat, mixed $updateLayout, string $readFormat, mixed $readLayout, string $exampleName) : void
Parameters
$formName : string

The symbolic name of the form.

$updateFormat : string

The format with which to write the data. 'html' or 'array'

$updateLayout : mixed

The new value to set

$readFormat : string

The format with which to read the data. 'html' or 'array'

$readLayout : mixed

The value that we expect to read.

$exampleName : string

(For debug messages) A symbolic name of the example data-set being tested.

Tags
dataProvider

getFormatExamples

testWhitespaceFormat()

This tests that a non-pretty html string will have its whitespace stripped & reformatted when using the "formatWhitespace" option.

public testWhitespaceFormat(mixed $directiveName, mixed $example, mixed $exampleName) : void
Parameters
$directiveName : mixed
$example : mixed
$exampleName : mixed
Tags
dataProvider

getWhitespaceExamples

conditionallyDeleteTestRecords()

protected conditionallyDeleteTestRecords() : void

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

fudgeMarkup()

DOMDocument outputs some tags a little different than they were input.

private fudgeMarkup(array<string|int, mixed>|string $markup) : array<string|int, mixed>|string

It's not really a problem but can trip up tests.

Parameters
$markup : array<string|int, mixed>|string
Return values
array<string|int, mixed>|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

isMissingValue()

private static isMissingValue(array<string|int, mixed> $values, string $fieldName) : bool
Parameters
$values : array<string|int, mixed>
$fieldName : string
Return values
bool

randomLetters()

Generate some random lowercase letters.

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

        
On this page

Search results