Skip to content

Commit

Permalink
Fix test to use order api & setup valid financials
Browse files Browse the repository at this point in the history
Updates a test from 'weird setup' to using the order api
  • Loading branch information
eileenmcnaughton committed Jul 8, 2021
1 parent e343d42 commit ed8a9f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
9 changes: 5 additions & 4 deletions Civi/Test/ContactTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ public function sampleContact($contact_type, $seq = 0, $random = FALSE) {
*
* @return int
* id of contact created
*
* @throws \CiviCRM_API3_Exception
*/
private function _contactCreate($params): int {
$result = civicrm_api3('contact', 'create', $params);
private function _contactCreate(array $params): int {
$version = $this->_apiversion;
$this->_apiversion = 3;
$result = $this->callAPISuccess('contact', 'create', $params);
$this->_apiversion = $version;
return (int) $result['id'];
}

Expand Down
41 changes: 10 additions & 31 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
use CRMTraits_Custom_CustomDataTrait;
use CRMTraits_Financial_OrderTrait;
use CRMTraits_Financial_TaxTrait;
use CRMTraits_Financial_PriceSetTrait;

protected $_individualId;
protected $_contribution;
Expand Down Expand Up @@ -2384,8 +2385,6 @@ public function testRepeatTransactionWithCustomData(): void {
* @throws \CRM_Core_Exception
*/
public function testRepeatTransactionLineItems(): void {
// @todo - figure out why this test is not valid.
$this->isValidateFinancialsOnPostAssert = FALSE;
// CRM-19309
$originalContribution = $this->setUpRepeatTransaction([], 'multiple');
$this->callAPISuccess('contribution', 'repeattransaction', [
Expand Down Expand Up @@ -4384,13 +4383,12 @@ protected function setUpAutoRenewMembership($generalParams = [], $recurParams =
* Set up a repeat transaction.
*
* @param array $recurParams
* @param mixed $flag
* @param string $flag
* @param array $contributionParams
*
* @return array
* @throws \CRM_Core_Exception
*/
protected function setUpRepeatTransaction($recurParams, $flag, $contributionParams = []) {
protected function setUpRepeatTransaction(array $recurParams, $flag, array $contributionParams = []) {
$paymentProcessorID = $this->paymentProcessorCreate();
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([
'contact_id' => $this->_individualId,
Expand All @@ -4407,36 +4405,17 @@ protected function setUpRepeatTransaction($recurParams, $flag, $contributionPara
$originalContribution = '';
if ($flag === 'multiple') {
// CRM-19309 create a contribution + also add in line_items (plural):
$params = array_merge($this->_params, $contributionParams);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$params,
[
'contribution_recur_id' => $contributionRecur['id'],
'skipLineItem' => 1,
'api.line_item.create' => [
[
'price_field_id' => 1,
'qty' => 2,
'line_total' => '20',
'unit_price' => '10',
'financial_type_id' => 1,
],
[
'price_field_id' => 1,
'qty' => 1,
'line_total' => '80',
'unit_price' => '80',
'financial_type_id' => 2,
],
],
]
)
);
$this->createContributionWithTwoLineItemsAgainstPriceSet([
'contact_id' => $this->_individualId,
'contribution_recur_id' => $contributionRecur['id'],
]);
$originalContribution = $this->callAPISuccessGetSingle('Contribution', ['contribution_recur_d' => $contributionRecur['id'], 'return' => 'id']);
}
elseif ($flag === 'single') {
$params = array_merge($this->_params, ['contribution_recur_id' => $contributionRecur['id']]);
$params = array_merge($params, $contributionParams);
$originalContribution = $this->callAPISuccess('contribution', 'create', $params);
$params['api.Payment.create'] = ['total_amount' => $params['total_amount']];
$originalContribution = $this->callAPISuccess('Order', 'create', $params);
}
$originalContribution['contribution_recur_id'] = $contributionRecur['id'];
$originalContribution['payment_processor_id'] = $paymentProcessorID;
Expand Down

0 comments on commit ed8a9f9

Please sign in to comment.