From: Eileen McNaughton Date: Wed, 16 Jun 2021 07:01:00 +0000 (+1200) Subject: Add test validation for Membership & participant payments X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=96e48e2b85c9248f2071b200b66426000f54edb4;p=civicrm-core.git Add test validation for Membership & participant payments --- diff --git a/api/v3/Order.php b/api/v3/Order.php index 870b07fbd4..528a25ef38 100644 --- a/api/v3/Order.php +++ b/api/v3/Order.php @@ -161,11 +161,14 @@ function civicrm_api3_order_create(array $params): array { // if entity is pledge then build pledge param if ($entity === 'pledge') { $paymentParams += $entityParams; + // Pledges are not stored as entity_id in the line_item table. + CRM_Core_Error::deprecatedWarning('This should be unreachable & tests show it is never tested.'); + civicrm_api3('PledgePayment', 'create', $paymentParams); } - elseif ($entity === 'membership') { - $paymentParams['isSkipLineItem'] = TRUE; + if ($entity === 'participant') { + civicrm_api3('ParticipantPayment', 'create', $paymentParams); } - civicrm_api3($entity . '_payment', 'create', $paymentParams); + } } return civicrm_api3_create_success($contribution['values'] ?? [], $params, 'Order', 'create'); diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 0e9f48f829..473bb1f502 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3633,13 +3633,29 @@ VALUES foreach ($contributions as $contribution) { $lineItems = $this->callAPISuccess('LineItem', 'get', [ 'contribution_id' => $contribution['id'], - 'return' => ['tax_amount', 'line_total'], + 'return' => ['tax_amount', 'line_total', 'entity_table', 'entity_id'], ])['values']; $total = 0; $taxTotal = 0; + $memberships = []; + $participants = []; foreach ($lineItems as $lineItem) { $total += $lineItem['line_total']; $taxTotal += (float) ($lineItem['tax_amount'] ?? 0); + if ($lineItem['entity_table'] === 'civicrm_membership') { + $memberships[] = $lineItem['entity_id']; + } + if ($lineItem['entity_table'] === 'civicrm_participant') { + $participants[] = $lineItem['entity_id']; + } + } + $membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', ['contribution_id' => $contribution['id'], 'return' => 'membership_id'])['values']; + $participantPayments = $this->callAPISuccess('ParticipantPayment', 'get', ['contribution_id' => $contribution['id'], 'return' => 'participant_id'])['values']; + $this->assertCount(count($memberships), $membershipPayments); + // @todo not working yet. + // $this->assertCount(count($participants), $participantPayments); + foreach ($membershipPayments as $payment) { + $this->assertContains($payment['membership_id'], $memberships); } $this->assertEquals($taxTotal, (float) ($contribution['tax_amount'] ?? 0)); $this->assertEquals($total + $taxTotal, $contribution['total_amount']);