Add test validation for Membership & participant payments
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 16 Jun 2021 07:01:00 +0000 (19:01 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 18 Jun 2021 01:42:40 +0000 (13:42 +1200)
api/v3/Order.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 870b07fbd44253baec3415a32a700c5c3bed1d33..528a25ef38c5c932a9a785b78a1e636caf50fc0a 100644 (file)
@@ -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');
index 0e9f48f829db798e23587fec19624bd6dc5c6969..473bb1f5021a41ae30d815d9281ed4f9189058e5 100644 (file)
@@ -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']);