Documentation

MessageTemplateTest extends Api4TestBase
in package
implements TransactionalInterface uses GenericAssertionsTrait, DbTestTrait

Tags
group

headless

group

msgtpl

Table of Contents

Interfaces

TransactionalInterface
Interface HeadlessInterface

Properties

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

Methods

__construct()  : mixed
assertApproxEquals()  : mixed
Assert that two numbers are approximately equal, give or take some $tolerance.
assertArrayKeyExists()  : mixed
assertArrayValueNotNull()  : mixed
assertArrayValuesEqual()  : mixed
Assert the 2 arrays have the same values.
assertAttributesEquals()  : mixed
Assert attributes are equal.
assertDBCompareValue()  : mixed
Compare a single column value in a retrieved DB record to an expected value.
assertDBCompareValues()  : mixed
Compare all values in a single retrieved DB record to an array of expected values.
assertDBNotNull()  : null|string
Request a record from the DB by seachColumn+searchValue. Success if a record is found.
assertDBNull()  : mixed
Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL.
assertDBQuery()  : void
Assert that a SQL query returns a given value.
assertDBRowExist()  : mixed
Request a record from the DB by id. Success if row not found.
assertDBRowNotExist()  : mixed
Request a record from the DB by id. Success if row not found.
assertDBState()  : void
Generic function to compare expected values after an api call to retrieved.
assertTreeEquals()  : mixed
Assert that two array-trees are exactly equal.
assertType()  : 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.
getTestRecord()  : array<string|int, mixed>
saveTestRecords()  : Result
Saves one or more test records, supplying default values.
setUpHeadless()  : CiviEnvBuilder
The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
tearDown()  : void
Post test cleanup.
testMessageTemplateMasterID()  : void
Test APIv4 calculated field master_id
testSaveNoId()  : void
Test save with no id
testSaveNullId()  : void
Test save with an explicit null id
testWorkflowId_legacyMatch()  : void
Create/update a MessageTempalte with workflow_id. Ensure the newer workflow_name is set.
testWorkflowName_clean()  : void
Create/update a MessageTemplate with workflow_name and no corresponding workflow_id.
testWorkflowName_legacyMatch()  : void
Create/update a MessageTemplate with workflow_name - a name which happens to have an older/corresponding workflow_id.
userLogout()  : mixed
createFirstSecond()  : mixed
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

$testRecords

Records created which will be deleted during tearDown

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

$baseTpl

private mixed $baseTpl = ['msg_title' => 'My Template', 'msg_subject' => 'My Subject', 'msg_text' => 'My body as text', 'msg_html' => '<p>My body as HTML</p>', 'is_reserved' => TRUE, 'is_default' => FALSE]

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

assertApproxEquals()

Assert that two numbers are approximately equal, give or take some $tolerance.

public assertApproxEquals(int|float $expected, int|float $actual, int|float $tolerance[, string $message = NULL ]) : mixed
Parameters
$expected : int|float
$actual : int|float
$tolerance : int|float

Any differences <$tolerance are considered irrelevant. Differences >=$tolerance are considered relevant.

$message : string = NULL

assertArrayKeyExists()

public assertArrayKeyExists(string|int $key, array<string|int, mixed> &$list) : mixed
Parameters
$key : string|int
$list : array<string|int, mixed>

assertArrayValueNotNull()

public assertArrayValueNotNull(string|int $key, array<string|int, mixed> &$list) : mixed
Parameters
$key : string|int
$list : array<string|int, mixed>

assertArrayValuesEqual()

Assert the 2 arrays have the same values.

public assertArrayValuesEqual(array<string|int, mixed> $array1, array<string|int, mixed> $array2) : mixed

The order of arrays, and keys of the arrays, do not affect the outcome.

Parameters
$array1 : array<string|int, mixed>
$array2 : array<string|int, mixed>

assertAttributesEquals()

Assert attributes are equal.

public assertAttributesEquals(array<string|int, mixed> $expectedValues, array<string|int, mixed> $actualValues[, string $message = NULL ]) : mixed
Parameters
$expectedValues : array<string|int, mixed>
$actualValues : array<string|int, mixed>
$message : string = NULL
Tags
throws
PHPUnit_Framework_AssertionFailedError

assertDBCompareValue()

Compare a single column value in a retrieved DB record to an expected value.

public assertDBCompareValue(string $daoName, mixed $searchValue, mixed $returnColumn, mixed $searchColumn, mixed $expectedValue, mixed $message) : mixed
Parameters
$daoName : string
$searchValue : mixed
$returnColumn : mixed
$searchColumn : mixed
$expectedValue : mixed
$message : mixed

assertDBCompareValues()

Compare all values in a single retrieved DB record to an array of expected values.

public assertDBCompareValues(string $daoName, array<string|int, mixed> $searchParams, mixed $expectedValues) : mixed
Parameters
$daoName : string
$searchParams : array<string|int, mixed>
$expectedValues : mixed

assertDBNotNull()

Request a record from the DB by seachColumn+searchValue. Success if a record is found.

public assertDBNotNull(string $daoName, mixed $searchValue, mixed $returnColumn, mixed $searchColumn, mixed $message) : null|string
Parameters
$daoName : string
$searchValue : mixed
$returnColumn : mixed
$searchColumn : mixed
$message : mixed
Tags
throws
PHPUnit_Framework_AssertionFailedError
Return values
null|string

assertDBNull()

Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL.

public assertDBNull(string $daoName, mixed $searchValue, mixed $returnColumn, mixed $searchColumn, mixed $message) : mixed
Parameters
$daoName : string
$searchValue : mixed
$returnColumn : mixed
$searchColumn : mixed
$message : mixed

assertDBQuery()

Assert that a SQL query returns a given value.

public assertDBQuery(string|null|int $expected, string $query[, array<string|int, mixed> $params = [] ][, string $message = '' ]) : void

The first argument is an expected value. The remaining arguments are passed to CRM_Core_DAO::singleValueQuery

Example: $this->assertSql(2, 'select count(*) from foo where foo.bar like "%1"', array(1 => array("Whiz", "String")));

Parameters
$expected : string|null|int
$query : string
$params : array<string|int, mixed> = []
$message : string = ''
Tags
noinspection

PhpUnhandledExceptionInspection

noinspection

PhpDocMissingThrowsInspection

assertDBRowExist()

Request a record from the DB by id. Success if row not found.

public assertDBRowExist(string $daoName, int $id[, null $message = NULL ]) : mixed
Parameters
$daoName : string
$id : int
$message : null = NULL

assertDBRowNotExist()

Request a record from the DB by id. Success if row not found.

public assertDBRowNotExist(string $daoName, int $id[, null $message = NULL ]) : mixed
Parameters
$daoName : string
$id : int
$message : null = NULL

assertDBState()

Generic function to compare expected values after an api call to retrieved.

public assertDBState(mixed $daoName, mixed $id, mixed $match[, bool $delete = FALSE ]) : void

DB values.

Parameters
$daoName : mixed
$id : mixed
$match : mixed
$delete : bool = FALSE
Tags
daoName

string DAO Name of object we're evaluating.

id

int Id of object

match

array Associative array of field name => expected value. Empty if asserting that a DELETE occurred

delete

boolean True if we're checking that a DELETE action occurred.

assertTreeEquals()

Assert that two array-trees are exactly equal.

public assertTreeEquals(array<string|int, mixed> $expected, array<string|int, mixed> $actual) : mixed

The ordering of keys do not affect the outcome (within either the roots or in any child elements).

Error messages will reveal a readable -path-, regardless of how many levels of nesting are present.

Parameters
$expected : array<string|int, mixed>
$actual : array<string|int, mixed>

assertType()

public assertType(string $expected, mixed $actual[, string $message = '' ]) : mixed
Parameters
$expected : string

Ex: 'array', 'object', 'int'

$actual : mixed

The variable/item to check.

$message : string = ''

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

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

testMessageTemplateMasterID()

Test APIv4 calculated field master_id

public testMessageTemplateMasterID() : void

testWorkflowId_legacyMatch()

Create/update a MessageTempalte with workflow_id. Ensure the newer workflow_name is set.

public testWorkflowId_legacyMatch() : void

testWorkflowName_clean()

Create/update a MessageTemplate with workflow_name and no corresponding workflow_id.

public testWorkflowName_clean() : void

testWorkflowName_legacyMatch()

Create/update a MessageTemplate with workflow_name - a name which happens to have an older/corresponding workflow_id.

public testWorkflowName_legacyMatch() : 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

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