CancelTest
extends TestCase
in package
implements
HeadlessInterface, HookInterface, TransactionalInterface
uses
Api3TestTrait, ContactTestTrait, FormTrait
FIXME - Add test description.
Tips:
- With HookInterface, you may implement CiviCRM hooks directly in the test class. Simply create corresponding functions (e.g. "hook_civicrm_post(...)" or similar).
- With TransactionalInterface, any data changes made by setUp() or test****() functions will rollback automatically -- as long as you don't manipulate schema or truncate tables. If this test needs to manipulate schema or truncate tables, then either: a. Do all that using setupHeadless() and Civi\Test. b. Disable TransactionalInterface, and handle all setup/teardown yourself.
Tags
Table of Contents
Interfaces
- HeadlessInterface
- Interface HeadlessInterface
- HookInterface
- TransactionalInterface
- Interface HeadlessInterface
Properties
- $apiversion : int
- API version to use for any api calls.
- $_apiversion : int
- Api version - easier to override than just a define
- $ids : array<string|int, mixed>
- Created ids.
- $form : FormWrapper
Methods
- assertAPIArrayComparison() : mixed
- Check that api returned 'is_error' => 1 else provide full message
- assertAPIDeleted() : mixed
- Check that a deleted item has been deleted.
- assertAPIFailure() : void
- Check that api returned 'is_error' => 1.
- assertAPISuccess() : mixed
- Check that api returned 'is_error' => 0.
- callAPIAndDocument() : array<string|int, mixed>|int
- callAPIFailure() : array<string|int, mixed>|int
- This function exists to wrap api functions.
- callAPISuccess() : array<string|int, mixed>|int
- wrap api functions.
- callAPISuccessGetCount() : array<string|int, mixed>|int
- This function exists to wrap api getValue function & check the result so we can ensure they succeed & throw exceptions without littering the test with checks There is a type check in this
- callAPISuccessGetSingle() : array<string|int, mixed>|int
- This function exists to wrap api getsingle function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks
- callAPISuccessGetValue() : array<string|int, mixed>|int
- This function wraps the getValue api and checks the result.
- civicrm_api() : array<string|int, mixed>|int
- A stub for the API interface. This can be overriden by subclasses to change how the API is called.
- contactDelete() : void
- Delete contact, ensuring it is not the domain contact
- createLoggedInUser() : int
- Emulate a logged in user since certain functions use that.
- createPaymentProcessor() : int
- Create a payment processor.
- getTestForm() : FormWrapper
- groupContactCreate() : int
- Function to add a Group.
- groupCreate() : int
- Add a Group.
- groupDelete() : mixed
- Delete a Group.
- householdCreate() : int
- Generic function to create Household, to be used in test cases
- individualCreate() : int
- Generic function to create Individual, to be used in test cases
- organizationCreate() : int
- Generic function to create Organisation, to be used in test cases
- runApi4Legacy() : array<string|int, mixed>|int
- Emulate v3 syntax so we can run api3 tests on v4
- sampleContact() : array<string|int, mixed>
- Helper function for getting sample contact properties.
- setUpHeadless() : CiviEnvBuilder
- The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
- testCancelFromContributionForm() : void
- Test cancelling a contribution with a membership on the contribution edit form.
- testCancelOrderWithParticipantCancelled() : void
- Test cancel order api.
- testCancelOrderWithParticipantFailed() : void
- Test fail order api.
- testPaypalProCancel() : void
- Test that a cancel from paypal pro results in an order being cancelled.
- testPaypalStandardCancel() : void
- Test that a cancel from PayPal pro results in an order being cancelled.
- versionThreeAndFour() : array<string|int, mixed>
- Get the api versions to test.
- assertMailSentContainingHeaderString() : void
- Assert that the sent mail included the supplied string.
- assertMailSentContainingHeaderStrings() : void
- Assert that the sent mail included the supplied strings.
- assertMailSentContainingString() : void
- Assert that the sent mail included the supplied string.
- assertMailSentContainingStrings() : void
- Assert that the sent mail included the supplied strings.
- assertMailSentCount() : void
- Assert the right number of mails were sent.
- assertMailSentNotContainingString() : void
- Assert that the sent mail included the supplied string.
- assertMailSentNotContainingStrings() : void
- Assert that the sent mail included the supplied strings.
- assertMailSentTo() : void
- Assert that the sent mail included the supplied strings.
- assertPrematureExit() : void
- assertTemplateVariable() : void
- assertValidationError() : void
- Assert that the sent mail included the supplied string.
- createAndUpdateContribution() : void
- createContact() : void
- Create a contact for use in the test.
- createEventOrder() : int
- Create an event and an order for a participant in that event.
- createMembershipOrder() : void
- Create an order with more than one membership.
- createMembershipType() : void
- Create the general membership type.
- getDeprecatedProperty() : mixed
- Retrieve a deprecated property, ensuring a deprecation notice is thrown.
- getEventID() : int
- Get the event ID.
- runApi4LegacyChain() : array<string|int, mixed>
- _contactCreate() : int
- Private helper function for calling civicrm_contact_add.
Properties
$apiversion
API version to use for any api calls.
public
int
$apiversion
= 4
$_apiversion
Api version - easier to override than just a define
protected
int
$_apiversion
= 3
$ids
Created ids.
protected
array<string|int, mixed>
$ids
= []
$form
private
FormWrapper
$form
Methods
assertAPIArrayComparison()
Check that api returned 'is_error' => 1 else provide full message
public
assertAPIArrayComparison(array<string|int, mixed> $result, mixed $expected[, array<string|int, mixed> $valuesToExclude = [] ][, string $prefix = '' ]) : mixed
Parameters
- $result : array<string|int, mixed>
- $expected : mixed
- $valuesToExclude : array<string|int, mixed> = []
- $prefix : string = ''
-
Extra test to add to message.
assertAPIDeleted()
Check that a deleted item has been deleted.
public
assertAPIDeleted(mixed $entity, mixed $id) : mixed
Parameters
- $entity : mixed
- $id : mixed
assertAPIFailure()
Check that api returned 'is_error' => 1.
public
assertAPIFailure(array<string|int, mixed> $apiResult[, string $prefix = '' ][, string|null $expectedError = NULL ]) : void
Parameters
- $apiResult : array<string|int, mixed>
-
Api result.
- $prefix : string = ''
-
Extra test to add to message.
- $expectedError : string|null = NULL
assertAPISuccess()
Check that api returned 'is_error' => 0.
public
assertAPISuccess(array<string|int, mixed> $apiResult[, string $prefix = '' ]) : mixed
Parameters
- $apiResult : array<string|int, mixed>
-
Api result.
- $prefix : string = ''
-
Extra test to add to message.
callAPIAndDocument()
public
callAPIAndDocument(string $entity, string $action, array<string|int, mixed> $params) : array<string|int, mixed>|int
Parameters
- $entity : string
- $action : string
- $params : array<string|int, mixed>
Return values
array<string|int, mixed>|intcallAPIFailure()
This function exists to wrap api functions.
public
callAPIFailure(string $entity, string $action[, array<string|int, mixed> $params = [] ][, string $expectedErrorMessage = NULL ][, null $extraOutput = NULL ]) : array<string|int, mixed>|int
so we can ensure they fail where expected & throw exceptions without litterering the test with checks
Parameters
- $entity : string
- $action : string
- $params : array<string|int, mixed> = []
- $expectedErrorMessage : string = NULL
-
Error.
- $extraOutput : null = NULL
Return values
array<string|int, mixed>|intcallAPISuccess()
wrap api functions.
public
callAPISuccess(string $entity, string $action[, array<string|int, mixed> $params = [] ][, mixed $checkAgainst = NULL ]) : array<string|int, mixed>|int
so we can ensure they succeed & throw exceptions without litterering the test with checks
Parameters
- $entity : string
- $action : string
- $params : array<string|int, mixed> = []
- $checkAgainst : mixed = NULL
-
Optional value to check result against, implemented for getvalue,. getcount, getsingle. Note that for getvalue the type is checked rather than the value for getsingle the array is compared against an array passed in - the id is not compared (for better or worse )
Return values
array<string|int, mixed>|intcallAPISuccessGetCount()
This function exists to wrap api getValue function & check the result so we can ensure they succeed & throw exceptions without littering the test with checks There is a type check in this
public
callAPISuccessGetCount(string $entity, array<string|int, mixed> $params[, int $count = NULL ]) : array<string|int, mixed>|int
Parameters
- $entity : string
- $params : array<string|int, mixed>
- $count : int = NULL
Return values
array<string|int, mixed>|intcallAPISuccessGetSingle()
This function exists to wrap api getsingle function & check the result so we can ensure they succeed & throw exceptions without litterering the test with checks
public
callAPISuccessGetSingle(string $entity, array<string|int, mixed> $params[, array<string|int, mixed> $checkAgainst = NULL ]) : array<string|int, mixed>|int
Parameters
- $entity : string
- $params : array<string|int, mixed>
- $checkAgainst : array<string|int, mixed> = NULL
-
Array to compare result against.
- boolean
- integer
- double
- string
- array
- object
Return values
array<string|int, mixed>|intcallAPISuccessGetValue()
This function wraps the getValue api and checks the result.
public
callAPISuccessGetValue(string $entity, array<string|int, mixed> $params[, string $type = NULL ]) : array<string|int, mixed>|int
Parameters
- $entity : string
- $params : array<string|int, mixed>
- $type : string = NULL
-
Per http://php.net/manual/en/function.gettype.php possible types.
- boolean
- integer
- double
- string
- array
- object
Return values
array<string|int, mixed>|intcivicrm_api()
A stub for the API interface. This can be overriden by subclasses to change how the API is called.
public
civicrm_api(mixed $entity, mixed $action[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>|int
Parameters
- $entity : mixed
- $action : mixed
- $params : array<string|int, mixed> = []
Return values
array<string|int, mixed>|intcontactDelete()
Delete contact, ensuring it is not the domain contact
public
contactDelete(int $contactID) : void
Parameters
- $contactID : int
-
Contact ID to delete
createLoggedInUser()
Emulate a logged in user since certain functions use that.
public
createLoggedInUser() : int
value to store a record in the DB (like activity)
Tags
Return values
int —Contact ID of the created user.
createPaymentProcessor()
Create a payment processor.
public
createPaymentProcessor([array<string|int, mixed> $params = [] ]) : int
Parameters
- $params : array<string|int, mixed> = []
Return values
intgetTestForm()
public
getTestForm(mixed $formName, mixed $submittedValues[, array<string|int, mixed> $urlParameters = [] ]) : FormWrapper
Parameters
- $formName : mixed
- $submittedValues : mixed
- $urlParameters : array<string|int, mixed> = []
Return values
FormWrappergroupContactCreate()
Function to add a Group.
public
groupContactCreate(int $groupID[, int $totalCount = 10 ][, bool $random = FALSE ]) : int
Parameters
- $groupID : int
- $totalCount : int = 10
- $random : bool = FALSE
Tags
Return values
int —groupId of created group
groupCreate()
Add a Group.
public
groupCreate([array<string|int, mixed> $params = [] ][, string $identifier = 'group' ]) : int
Parameters
- $params : array<string|int, mixed> = []
- $identifier : string = 'group'
Return values
int —groupId of created group
groupDelete()
Delete a Group.
public
groupDelete(int $gid) : mixed
Parameters
- $gid : int
householdCreate()
Generic function to create Household, to be used in test cases
public
householdCreate([array<string|int, mixed> $params = [] ][, int|string $identifier = 'household_0' ]) : int
Parameters
- $params : array<string|int, mixed> = []
-
parameters for civicrm_contact_add api function call
- $identifier : int|string = 'household_0'
-
If the identifier is numeric (discouraged) it will affect which contact is loaded. Numeric identifiers and values for random other than FALSE are generally discouraged in favour if specifying data in params where variety is needed.
Return values
int —id of Household created
individualCreate()
Generic function to create Individual, to be used in test cases
public
individualCreate([array<string|int, mixed> $params = [] ][, int|string $identifier = 'individual_0' ][, bool $random = FALSE ]) : int
Parameters
- $params : array<string|int, mixed> = []
-
parameters for civicrm_contact_add api function call
- $identifier : int|string = 'individual_0'
-
If the identifier is numeric (discouraged) it will affect which contact is loaded. Numeric identifiers and values for random other than FALSE are generally discouraged in favour if specifying data in params where variety is needed.
- $random : bool = FALSE
-
Random is deprecated.
Return values
int —id of Individual created
organizationCreate()
Generic function to create Organisation, to be used in test cases
public
organizationCreate([array<string|int, mixed> $params = [] ][, int|string $identifier = 'organization_0' ]) : int
Parameters
- $params : array<string|int, mixed> = []
-
parameters for civicrm_contact_add api function call
- $identifier : int|string = 'organization_0'
-
If the identifier is numeric (discouraged) it will affect which contact is loaded. Numeric identifiers and values for random other than FALSE are generally discouraged in favour if specifying data in params where variety is needed.
Return values
int —id of Organisation created
runApi4Legacy()
Emulate v3 syntax so we can run api3 tests on v4
public
runApi4Legacy(mixed $v3Entity, mixed $v3Action[, array<string|int, mixed> $v3Params = [] ]) : array<string|int, mixed>|int
Parameters
- $v3Entity : mixed
- $v3Action : mixed
- $v3Params : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed>|intsampleContact()
Helper function for getting sample contact properties.
public
sampleContact(string $contact_type[, int $seq = 0 ][, bool $random = FALSE ]) : array<string|int, mixed>
Parameters
- $contact_type : string
-
enum contact type: Individual, Organization
- $seq : int = 0
-
sequence number for the values of this type
- $random : bool = FALSE
Return values
array<string|int, mixed> —properties of sample contact (ie. $params for API call)
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.
Tags
Return values
CiviEnvBuildertestCancelFromContributionForm()
Test cancelling a contribution with a membership on the contribution edit form.
public
testCancelFromContributionForm() : void
Tags
testCancelOrderWithParticipantCancelled()
Test cancel order api.
public
testCancelOrderWithParticipantCancelled() : void
Tags
testCancelOrderWithParticipantFailed()
Test fail order api.
public
testCancelOrderWithParticipantFailed() : void
Tags
testPaypalProCancel()
Test that a cancel from paypal pro results in an order being cancelled.
public
testPaypalProCancel() : void
Tags
testPaypalStandardCancel()
Test that a cancel from PayPal pro results in an order being cancelled.
public
testPaypalStandardCancel() : void
Tags
versionThreeAndFour()
Get the api versions to test.
public
versionThreeAndFour() : array<string|int, mixed>
Return values
array<string|int, mixed>assertMailSentContainingHeaderString()
Assert that the sent mail included the supplied string.
protected
assertMailSentContainingHeaderString(string $string[, int $mailIndex = 0 ]) : void
Parameters
- $string : string
- $mailIndex : int = 0
assertMailSentContainingHeaderStrings()
Assert that the sent mail included the supplied strings.
protected
assertMailSentContainingHeaderStrings(array<string|int, mixed> $strings[, int $mailIndex = 0 ]) : void
Parameters
- $strings : array<string|int, mixed>
- $mailIndex : int = 0
assertMailSentContainingString()
Assert that the sent mail included the supplied string.
protected
assertMailSentContainingString(string $string[, int $mailIndex = 0 ]) : void
Parameters
- $string : string
- $mailIndex : int = 0
assertMailSentContainingStrings()
Assert that the sent mail included the supplied strings.
protected
assertMailSentContainingStrings(array<string|int, mixed> $strings[, int $mailIndex = 0 ]) : void
Parameters
- $strings : array<string|int, mixed>
- $mailIndex : int = 0
assertMailSentCount()
Assert the right number of mails were sent.
protected
assertMailSentCount(int $count) : void
Parameters
- $count : int
assertMailSentNotContainingString()
Assert that the sent mail included the supplied string.
protected
assertMailSentNotContainingString(string $string[, int $mailIndex = 0 ]) : void
Parameters
- $string : string
- $mailIndex : int = 0
assertMailSentNotContainingStrings()
Assert that the sent mail included the supplied strings.
protected
assertMailSentNotContainingStrings(array<string|int, mixed> $strings[, int $mailIndex = 0 ]) : void
Parameters
- $strings : array<string|int, mixed>
- $mailIndex : int = 0
assertMailSentTo()
Assert that the sent mail included the supplied strings.
protected
assertMailSentTo(array<string|int, mixed> $recipients[, int $mailIndex = 0 ]) : void
Parameters
- $recipients : array<string|int, mixed>
- $mailIndex : int = 0
assertPrematureExit()
protected
assertPrematureExit() : void
assertTemplateVariable()
protected
assertTemplateVariable(mixed $name, mixed $expected) : void
Parameters
- $name : mixed
- $expected : mixed
assertValidationError()
Assert that the sent mail included the supplied string.
protected
assertValidationError(array<string|int, mixed> $errors) : void
Parameters
- $errors : array<string|int, mixed>
createAndUpdateContribution()
protected
createAndUpdateContribution(string $status) : void
Parameters
- $status : string
Tags
createContact()
Create a contact for use in the test.
protected
createContact() : void
Tags
createEventOrder()
Create an event and an order for a participant in that event.
protected
createEventOrder() : int
Tags
Return values
intcreateMembershipOrder()
Create an order with more than one membership.
protected
createMembershipOrder() : void
createMembershipType()
Create the general membership type.
protected
createMembershipType() : void
Tags
getDeprecatedProperty()
Retrieve a deprecated property, ensuring a deprecation notice is thrown.
protected
getDeprecatedProperty(string $property) : mixed
Parameters
- $property : string
Tags
getEventID()
Get the event ID.
protected
getEventID() : int
Return values
intrunApi4LegacyChain()
protected
runApi4LegacyChain(string $key, mixed $params, string $mainEntity, array<string|int, mixed> $result, bool $sequential) : array<string|int, mixed>
Parameters
- $key : string
- $params : mixed
- $mainEntity : string
- $result : array<string|int, mixed>
- $sequential : bool
Tags
Return values
array<string|int, mixed>_contactCreate()
Private helper function for calling civicrm_contact_add.
private
_contactCreate(array<string|int, mixed> $params[, string $identifier = 'Contact' ]) : int
Parameters
- $params : array<string|int, mixed>
-
For civicrm_contact_add api function call.
- $identifier : string = 'Contact'
Return values
int —id of contact created