CRM_Core_Payment_PayflowProTest
extends TestCase
in package
implements
HeadlessInterface, HookInterface
uses
GuzzleTestTrait, Api3TestTrait
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
Properties
- $ids : array<string|int, mixed>
- Created Object Ids
- $_apiversion : int
- Api version - easier to override than just a define
- $baseUri : string
- The url to mock-interact with.
- $container : array<string|int, mixed>
- Array containing guzzle history of requests and responses.
- $guzzleClient : Client
- $mockHandler : MockHandler
- Mockhandler to simulate guzzle requests.
- $processor : CRM_Core_Payment_PayflowPro
- Instance of CRM_Core_Payment_PayflowPro|null
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.
- getBaseUri() : mixed
- getContainer() : array<string|int, mixed>
- getExpectedRecurringPaymentRequests() : array<string|int, mixed>
- getExpectedRecurringPaymentResponses() : array<string|int, mixed>
- getExpectedSinglePaymentErrorResponses() : array<string|int, mixed>
- getExpectedSinglePaymentRequests() : array<string|int, mixed>
- Get the expected request from Payflow Pro.
- getExpectedSinglePaymentResponses() : array<string|int, mixed>
- Get the expected response from Payflow Pro for a single payment.
- getGuzzleClient() : Client
- getMockHandler() : MockHandler
- runApi4Legacy() : array<string|int, mixed>|int
- Emulate v3 syntax so we can run api3 tests on v4
- setBaseUri() : mixed
- setContainer() : mixed
- setGuzzleClient() : mixed
- setMockHandler() : mixed
- setUp() : void
- setUpHeadless() : mixed
- The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
- setUpPayflowProcessor() : void
- tearDown() : void
- testErrorSinglePayment() : void
- Test making a failed once off payment
- testRecurringPayment() : void
- Test making a recurring payment
- testSinglePayment() : void
- Test making a once off payment
- versionThreeAndFour() : array<string|int, mixed>
- Get the api versions to test.
- createMockHandler() : mixed
- createMockHandlerForFiles() : mixed
- getBillingParams() : array<string|int, mixed>
- Get some basic billing parameters.
- getRequestBodies() : array<string|int, mixed>
- Get the bodies of the requests sent via Guzzle.
- getRequestHeaders() : array<string|int, mixed>
- Get the bodies of the requests sent via Guzzle.
- getRequestUrls() : array<string|int, mixed>
- Get the bodies of the requests sent via Guzzle.
- getResponseBodies() : array<string|int, mixed>
- Get the bodies of the responses returned via Guzzle.
- runApi4LegacyChain() : array<string|int, mixed>
- setUpClientWithHistoryContainer() : mixed
- Set up a guzzle client with a history container.
- setupMockHandler() : void
- Add a mock handler to the Payflow Pro processor for testing.
Properties
$ids
Created Object Ids
public
array<string|int, mixed>
$ids
$_apiversion
Api version - easier to override than just a define
protected
int
$_apiversion
= 3
$baseUri
The url to mock-interact with.
protected
string
$baseUri
$container
Array containing guzzle history of requests and responses.
protected
array<string|int, mixed>
$container
$guzzleClient
protected
Client
$guzzleClient
$mockHandler
Mockhandler to simulate guzzle requests.
protected
MockHandler
$mockHandler
$processor
Instance of CRM_Core_Payment_PayflowPro|null
protected
CRM_Core_Payment_PayflowPro
$processor
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>|intgetBaseUri()
public
getBaseUri() : mixed
getContainer()
public
getContainer() : array<string|int, mixed>
Return values
array<string|int, mixed>getExpectedRecurringPaymentRequests()
public
getExpectedRecurringPaymentRequests() : array<string|int, mixed>
Return values
array<string|int, mixed>getExpectedRecurringPaymentResponses()
public
getExpectedRecurringPaymentResponses() : array<string|int, mixed>
Return values
array<string|int, mixed>getExpectedSinglePaymentErrorResponses()
public
getExpectedSinglePaymentErrorResponses() : array<string|int, mixed>
Return values
array<string|int, mixed>getExpectedSinglePaymentRequests()
Get the expected request from Payflow Pro.
public
getExpectedSinglePaymentRequests() : array<string|int, mixed>
Return values
array<string|int, mixed>getExpectedSinglePaymentResponses()
Get the expected response from Payflow Pro for a single payment.
public
getExpectedSinglePaymentResponses() : array<string|int, mixed>
Return values
array<string|int, mixed>getGuzzleClient()
public
getGuzzleClient() : Client
Return values
ClientgetMockHandler()
public
getMockHandler() : MockHandler
Return values
MockHandlerrunApi4Legacy()
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>|intsetBaseUri()
public
setBaseUri(mixed $baseUri) : mixed
Parameters
- $baseUri : mixed
setContainer()
public
setContainer(array<string|int, mixed> $container) : mixed
Parameters
- $container : array<string|int, mixed>
setGuzzleClient()
public
setGuzzleClient(Client $guzzleClient) : mixed
Parameters
- $guzzleClient : Client
setMockHandler()
public
setMockHandler(MockHandler $mockHandler) : mixed
Parameters
- $mockHandler : MockHandler
setUp()
public
setUp() : void
setUpHeadless()
The setupHeadless function runs at the start of each test case, right before the headless environment reboots.
public
setUpHeadless() : mixed
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.
setUpPayflowProcessor()
public
setUpPayflowProcessor() : void
tearDown()
public
tearDown() : void
testErrorSinglePayment()
Test making a failed once off payment
public
testErrorSinglePayment() : void
testRecurringPayment()
Test making a recurring payment
public
testRecurringPayment() : void
testSinglePayment()
Test making a once off payment
public
testSinglePayment() : void
versionThreeAndFour()
Get the api versions to test.
public
versionThreeAndFour() : array<string|int, mixed>
Return values
array<string|int, mixed>createMockHandler()
protected
createMockHandler(mixed $responses) : mixed
Parameters
- $responses : mixed
createMockHandlerForFiles()
protected
createMockHandlerForFiles(mixed $files) : mixed
Parameters
- $files : mixed
getBillingParams()
Get some basic billing parameters.
protected
getBillingParams() : array<string|int, mixed>
These are what are entered by the form-filler.
Return values
array<string|int, mixed>getRequestBodies()
Get the bodies of the requests sent via Guzzle.
protected
getRequestBodies() : array<string|int, mixed>
Return values
array<string|int, mixed>getRequestHeaders()
Get the bodies of the requests sent via Guzzle.
protected
getRequestHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getRequestUrls()
Get the bodies of the requests sent via Guzzle.
protected
getRequestUrls() : array<string|int, mixed>
Return values
array<string|int, mixed>getResponseBodies()
Get the bodies of the responses returned via Guzzle.
protected
getResponseBodies() : array<string|int, mixed>
Return values
array<string|int, mixed>runApi4LegacyChain()
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>setUpClientWithHistoryContainer()
Set up a guzzle client with a history container.
protected
setUpClientWithHistoryContainer() : mixed
After you have run the requests you can inspect $this->container for the outgoing requests and incoming responses.
If $this->mock is defined then no outgoing http calls will be made and the responses configured on the handler will be returned instead of replies from a remote provider.
setupMockHandler()
Add a mock handler to the Payflow Pro processor for testing.
protected
setupMockHandler([int|null $id = NULL ][, bool $error = FALSE ][, bool $recurring = FALSE ]) : void
Parameters
- $id : int|null = NULL
- $error : bool = FALSE
- $recurring : bool = FALSE