Skip to content

Commit

Permalink
Merge pull request #20676 from eileenmcnaughton/recur
Browse files Browse the repository at this point in the history
Fix test to use valid financials
  • Loading branch information
colemanw authored Jul 1, 2021
2 parents a25640f + a33b79a commit 7642e55
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase {

use CRMTraits_Financial_OrderTrait;

protected $isValidateFinancialsOnPostAssert = TRUE;

/**
* Set up for test.
*
Expand Down Expand Up @@ -407,34 +409,20 @@ public function testAutoRenewalWhenOneMemberIsDeceased(): void {
'is_deceased' => 1,
]);

// We delete latest membership payment and line item.
$lineItemId = $this->callAPISuccessGetValue('LineItem', [
'contribution_id' => $contribution['id'],
'entity_id' => $membershipId2,
'entity_table' => 'civicrm_membership',
'return' => 'id',
]);

// No api to delete membership payment.
CRM_Core_DAO::executeQuery('
DELETE FROM civicrm_membership_payment
WHERE contribution_id = %1
AND membership_id = %2
', [
1 => [$contribution['id'], 'Integer'],
2 => [$membershipId2, 'Integer'],
]);

$this->callAPISuccess('LineItem', 'delete', [
'id' => $lineItemId,
]);

// set membership recurring to null.
$this->callAPISuccess('Membership', 'create', [
'id' => $membershipId2,
'contribution_recur_id' => NULL,
]);

$this->callAPISuccess('Contribution', 'delete', ['id' => $contribution['id']]);
unset($params['line_items'][1]);
$params['total_amount'] = 100;
$params['line_items'][0]['params']['id'] = $membershipId1;
$params['api.Payment.create']['total_amount'] = 100;

$order = $this->callAPISuccess('Order', 'create', $params);

// check line item and membership payment count.
$this->validateAllCounts($membershipId1, 5);
$this->validateAllCounts($membershipId2, 4);
Expand All @@ -446,7 +434,7 @@ public function testAutoRenewalWhenOneMemberIsDeceased(): void {

// record next subsequent payment (6th payment).
$this->callAPISuccess('Contribution', 'repeattransaction', [
'original_contribution_id' => $contributionId,
'original_contribution_id' => $order['id'],
'contribution_status_id' => 'Completed',
'total_amount' => '100',
]);
Expand Down Expand Up @@ -485,6 +473,7 @@ public function validateAllCounts(int $membershipId, int $count): void {
$lineItemParams = [
'entity_id' => $membershipId,
'entity_table' => 'civicrm_membership',
'contribution_id' => ['>' => 0],
];
$this->callAPISuccessGetCount('LineItem', $lineItemParams, $count);
$this->callAPISuccessGetCount('MembershipPayment', $memPayParams, $count);
Expand Down

0 comments on commit 7642e55

Please sign in to comment.