ContributionPageTestTrait uses trait:short, trait:short
Helper for event tests.
WARNING - this trait ships with core from 5.68 but the signatures may not yet be stable and it is worth assuming that they will not be stable until 5.72.
This provides functions to set up valid contribution pages for unit tests.
The primary functions in this class are
contributionPageCreatePaid- this is the main function to usecontributionPageCreate- underlying function, use for non-monetary pages.
Calling these function will create contribution pages 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
- $entityLookupDefinitions : array<string|int, mixed>
- Array of defined entity identifiers.
- $entityLookupValues : array<string|int, mixed>
- Array of defined entity values.
Methods
- contributionPageCreate() : array<string|int, mixed>
- Create a contribution page for test purposes.
- contributionPageCreatePaid() : array<string|int, mixed>
- Create a paid contribution page.
- contributionPageQuickConfigCreate() : void
- Set up a contribution page configured with quick config.
- contributionPageWithPriceSetCreate() : void
- Set up a contribution page with a complex price set.
- isDefined() : bool
- Check if an entity can be looked up
- lookup() : mixed
- Retrieve a field value for a defined entity
- createTestEntity() : array<string|int, mixed>
- Create an entity, recording it's details for tearDown.
- define() : void
- Defines a record so its values can be retrieved using `$this->lookup()`
- getBillingSubmitValues() : array<string|int, mixed>
- Get suitable values for submitting the contribution form with a billing block.
- getContributionPageID() : int
- Get the id of the contribution page created in set up.
- getDefinition() : array{entityName: string, identifier: array}|null
- Retrieve entity definition (entityName string, identifier [keys/values])
- setTestEntity() : void
- Set the test entity on the class for access.
- setTestEntityID() : void
- submitOnlineContributionForm() : FormWrapper|EventFormOnline|EventFormParticipant|null
- addProfilesToContributionPage() : void
- Add profiles to the event.
- createContributionPageProfile() : void
- Create a profile attached to 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
= []
$entityLookupDefinitions
Array of defined entity identifiers.
private
array<string|int, mixed>
$entityLookupDefinitions
= []
$entityLookupValues
Array of defined entity values.
private
array<string|int, mixed>
$entityLookupValues
= []
Methods
contributionPageCreate()
Create a contribution page for test purposes.
public
contributionPageCreate([array<string|int, mixed> $contributionPageValues = [] ][, string $identifier = 'ContributionPage' ]) : array<string|int, mixed>
Generally this function is not called directly - use contributionPageCreatePaid.
Parameters
- $contributionPageValues : array<string|int, mixed> = []
- $identifier : string = 'ContributionPage'
Return values
array<string|int, mixed>contributionPageCreatePaid()
Create a paid contribution page.
public
contributionPageCreatePaid(array<string|int, mixed> $contributionPageValues[, array<string|int, mixed> $priceSetParameters = [] ][, string $identifier = 'ContributionPage' ]) : array<string|int, mixed>
This function ensures that the page has pay later configured, unless specified as false and that there is a payment_processor configured, unless the key payment_processor is already set.
Parameters
- $contributionPageValues : array<string|int, mixed>
- $priceSetParameters : array<string|int, mixed> = []
-
Currently if 'id' is passed in then no update is made, but this could change
- $identifier : string = 'ContributionPage'
Return values
array<string|int, mixed>contributionPageQuickConfigCreate()
Set up a contribution page configured with quick config.
public
contributionPageQuickConfigCreate([array<string|int, mixed> $contributionPageParameters = [] ][, array<string|int, mixed> $priceSetParameters = [] ][, bool $isSeparatePayment = false ][, bool $membershipAmountField = true ][, bool $contributionAmountField = true ][, bool $otherAmountField = true ][, string $identifier = 'QuickConfig' ]) : void
The created price set has up to 3 fields.
- Radio field (key = 'contribution_amount') with 3 options ('contribution_amount_25','contribution_amount_15','contribution_amount_0'), financial type ID matches the page financial type.
- Text field ('other_amount') with amount = 1 - ie if qty is 2 then amount is 2, financial type ID matches the page financial type.
- Radio field (key = 'membership_amount') with one option per enabled membership type (General will be created if not exists).
Parameters
- $contributionPageParameters : array<string|int, mixed> = []
- $priceSetParameters : array<string|int, mixed> = []
- $isSeparatePayment : bool = false
- $membershipAmountField : bool = true
-
- use false to suppress the creation of this field.
- $contributionAmountField : bool = true
-
- use false to suppress the creation of this field.
- $otherAmountField : bool = true
-
- use false to suppress the creation of this field.
- $identifier : string = 'QuickConfig'
Tags
contributionPageWithPriceSetCreate()
Set up a contribution page with a complex price set.
public
contributionPageWithPriceSetCreate([array<string|int, mixed> $contributionPageParameters = [] ][, array<string|int, mixed> $priceSetParameters = [] ]) : void
The created price set has 5 fields using a mixture of financial type 1 & 2, 3 which are created.
More fields may be added.
- Radio field (key= 'radio_field') with 3 options ('20_dollars','10_dollars','free'), financial type ID is 'first'
- Select field (key= 'select_field') with 2 options ('40_dollars','30_dollars'), financial type ID is 'second'
- Text field ('text_field_16.95') with amount = 16.95 - ie if qty is 2 then amount is 33.90, financial type ID is 'second'
- Text field ('text_field_2.95') with amount = 2.95 - ie if qty is 2 then amount is 5.90, financial type ID is 'second'
- Text field ('text_field') with amount = 1 - ie if qty is 2 then amount is 2, financial type ID is 'first'
- CheckBox field ('check_box') with amount = 55, financial type ID is 'third'
Parameters
- $contributionPageParameters : array<string|int, mixed> = []
- $priceSetParameters : array<string|int, mixed> = []
isDefined()
Check if an entity can be looked up
public
isDefined(string $nickname) : bool
Parameters
- $nickname : string
Return values
boollookup()
Retrieve a field value for a defined entity
public
lookup(string $nickname, string $fieldName) : mixed
Parameters
- $nickname : string
-
Handle set by
$this->define() - $fieldName : string
Tags
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>define()
Defines a record so its values can be retrieved using `$this->lookup()`
protected
define(string $apiEntityName, string $nickname, array<string|int, mixed> $identifier) : void
Parameters
- $apiEntityName : string
- $nickname : string
-
Handle to use to retrieve values with
$this->lookup() - $identifier : array<string|int, mixed>
-
A unique key or combination of keys to uniquely identify the record (usually id) Most commonly looks like
['id' => 123]
getBillingSubmitValues()
Get suitable values for submitting the contribution form with a billing block.
protected
getBillingSubmitValues([string $processorIdentifier = 'dummy' ]) : array<string|int, mixed>
Parameters
- $processorIdentifier : string = 'dummy'
Return values
array<string|int, mixed>getContributionPageID()
Get the id of the contribution page created in set up.
protected
getContributionPageID([string $identifier = 'ContributionPage' ]) : int
If only one has been created it will be selected. Otherwise you should pass in the appropriate identifier.
Parameters
- $identifier : string = 'ContributionPage'
Return values
intgetDefinition()
Retrieve entity definition (entityName string, identifier [keys/values])
protected
getDefinition(string $nickname) : array{entityName: string, identifier: array}|null
Parameters
- $nickname : string
Return values
array{entityName: string, identifier: array}|nullsetTestEntity()
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
submitOnlineContributionForm()
protected
submitOnlineContributionForm(array<string|int, mixed> $submittedValues[, int|null $contributionPageID = null ][, array<string|int, mixed> $urlParameters = [] ]) : FormWrapper|EventFormOnline|EventFormParticipant|null
Parameters
- $submittedValues : array<string|int, mixed>
- $contributionPageID : int|null = null
-
Will default to calling $this->>getContributionPageID()
- $urlParameters : array<string|int, mixed> = []
Return values
FormWrapper|EventFormOnline|EventFormParticipant|nulladdProfilesToContributionPage()
Add profiles to the event.
private
addProfilesToContributionPage([string $identifier = 'ContributionPage' ]) : 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 = 'ContributionPage'
createContributionPageProfile()
Create a profile attached to an event.
private
createContributionPageProfile(array<string|int, mixed> $profile, string $identifier) : void
Parameters
- $profile : array<string|int, mixed>
- $identifier : string