Documentation

EventTestTrait uses trait:short

Helper for event tests.

This provides functions to set up valid events for unit tests.

The primary functions in this class are

  • eventCreatePaid
  • eventCreateUnpaid

Calling these function will create events with associated profiles and price set data as appropriate.

Table of Contents

Properties

$ids  : array<string|int, mixed>
Array of IDs created to support the test.
$tablesToCleanUp  : array<string|int, mixed>
Track tables we have modified during a test.
$testRecords  : array<string|int, mixed>
Records created which will be deleted during tearDown

Methods

addDiscountPriceSet()  : void
Add a discount price set to the given event.
eventCreate()  : array<string|int, mixed>
Create an Event.
createTestEntity()  : array<string|int, mixed>
Create an entity, recording it's details for tearDown.
eventCreatePaid()  : array<string|int, mixed>
Create a paid event.
eventCreateUnpaid()  : array<string|int, mixed>
Create an unpaid event.
getEvent()  : array<string|int, mixed>
This retrieves the values used to create the event.
getEventExampleData()  : array<string|int, mixed>
Get example data with which to create the event.
getEventID()  : int
Get the event id of the event created in set up.
getEventValue()  : mixed|null
Get a value from an event used in setup.
getPriceFieldOptions()  : array<string|int, array<string|int, mixed>>
Get the options for the price set.
setTestEntity()  : void
Set the test entity on the class for access.
setTestEntityID()  : void
updateEvent()  : void
Update an event.
addProfilesToEvent()  : void
Add profiles to the event.
createEventProfile()  : void
Create a profile attached to an event.
eventCreatePriceSet()  : void
Create a price set for an event.

Properties

$ids

Array of IDs created to support the test.

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

e.g $this->ids = ['Event' => ['descriptive_key' => $eventID], 'Group' => [$groupID]];

$tablesToCleanUp

Track tables we have modified during a test.

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

Set up functions that add entities can register the relevant tables here for the cleanup process.

$testRecords

Records created which will be deleted during tearDown

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

Methods

addDiscountPriceSet()

Add a discount price set to the given event.

public addDiscountPriceSet([string $eventIdentifier = 'PaidEvent' ][, array<string|int, mixed> $discountParameters = [] ][, array<string|int, mixed> $priceSetParameters = [] ][, string $identifier = 'discount' ][, float $fraction = 0.5 ]) : void
Parameters
$eventIdentifier : string = 'PaidEvent'
$discountParameters : array<string|int, mixed> = []
$priceSetParameters : array<string|int, mixed> = []
$identifier : string = 'discount'
$fraction : float = 0.5
Tags
noinspection

PhpUnhandledExceptionInspection

noinspection

PhpDocMissingThrowsInspection

eventCreate()

Create an Event.

public eventCreate([array<string|int, mixed> $params = [] ][, string $identifier = 'event' ]) : array<string|int, mixed>

Note this is not expected to be called directly - call

  • eventCreatePaid
  • eventCreateUnpaid
Parameters
$params : array<string|int, mixed> = []

Name-value pair for an event.

$identifier : string = 'event'
Return values
array<string|int, mixed>

createTestEntity()

Create an entity, recording it's details for tearDown.

protected createTestEntity(string $entity, array<string|int, mixed> $values[, string $identifier = 'default' ]) : array<string|int, mixed>
Parameters
$entity : string
$values : array<string|int, mixed>
$identifier : string = 'default'
Return values
array<string|int, mixed>

eventCreatePaid()

Create a paid event.

protected eventCreatePaid([array<string|int, mixed> $eventParameters = [] ][, array<string|int, mixed> $priceSetParameters = [] ][, string $identifier = 'PaidEvent' ]) : array<string|int, mixed>
Parameters
$eventParameters : array<string|int, mixed> = []

Values to

$priceSetParameters : array<string|int, mixed> = []
$identifier : string = 'PaidEvent'

Index for storing event ID in ids array.

Return values
array<string|int, mixed>

eventCreateUnpaid()

Create an unpaid event.

protected eventCreateUnpaid([array<string|int, mixed> $eventParameters = [] ][, string $identifier = 'event' ]) : array<string|int, mixed>
Parameters
$eventParameters : array<string|int, mixed> = []

Values to

$identifier : string = 'event'

Index for storing event ID in ids array.

Return values
array<string|int, mixed>

getEvent()

This retrieves the values used to create the event.

protected getEvent(string $identifier) : array<string|int, mixed>

Note this does not actually retrieve the event from the database although it arguably might be more useful.

Parameters
$identifier : string
Return values
array<string|int, mixed>

getEventExampleData()

Get example data with which to create the event.

protected getEventExampleData([string $name = 'PaidEvent' ]) : array<string|int, mixed>
Parameters
$name : string = 'PaidEvent'
Return values
array<string|int, mixed>

getEventID()

Get the event id of the event created in set up.

protected getEventID([string $identifier = 'event' ]) : int

If only one has been created it will be selected. Otherwise you should pass in the appropriate identifier.

Parameters
$identifier : string = 'event'
Return values
int

getEventValue()

Get a value from an event used in setup.

protected getEventValue(string $value, string $identifier) : mixed|null
Parameters
$value : string
$identifier : string
Return values
mixed|null

getPriceFieldOptions()

Get the options for the price set.

protected getPriceFieldOptions([string $identifier = 'PaidEvent' ]) : array<string|int, array<string|int, mixed>>
Parameters
$identifier : string = 'PaidEvent'

Optional string if we want to specify different options. This is not currently used but is consistent with our other functions and would allow over-riding.

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

setTestEntity()

Set the test entity on the class for access.

protected setTestEntity(string $entity, array<string|int, mixed> $values, string $identifier) : void

This follows the ids patter and also the api4TestTrait pattern.

Parameters
$entity : string
$values : array<string|int, mixed>
$identifier : string

setTestEntityID()

protected setTestEntityID(string $entity, int $id, string $identifier) : void
Parameters
$entity : string
$id : int
$identifier : string

updateEvent()

Update an event.

protected updateEvent([array<string|int, mixed> $eventParameters = [] ][, string $identifier = 'event' ]) : void
Parameters
$eventParameters : array<string|int, mixed> = []

Values to

$identifier : string = 'event'

Index for storing event ID in ids array.

addProfilesToEvent()

Add profiles to the event.

private addProfilesToEvent([string $identifier = 'event' ]) : void

This function is designed to reflect the normal use case where events do have profiles.

Note if any classes do not want profiles, or want something different, the thinking is they should override this. Once that arises we can review making it protected rather than private & checking we are happy with the signature.

Parameters
$identifier : string = 'event'
Tags
throws
CRM_Core_Exception

createEventProfile()

Create a profile attached to an event.

private createEventProfile(array<string|int, mixed> $profile, string $identifier[, bool $isAdditional = false ]) : void
Parameters
$profile : array<string|int, mixed>
$identifier : string
$isAdditional : bool = false
Tags
throws
CRM_Core_Exception

eventCreatePriceSet()

Create a price set for an event.

private eventCreatePriceSet(array<string|int, mixed> $priceSetParameters, string $identifier) : void
Parameters
$priceSetParameters : array<string|int, mixed>
$identifier : string

        
On this page

Search results