ContributionPageTestTrait
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 use -
contributionPageCreate
- 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
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.
- 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.
- addProfilesToContributionPage() : void
- Add profiles to the event.
- createContributionPageProfile() : void
- Create a profile attached to an event.
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> = []
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
intaddProfilesToContributionPage()
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