Follow up fixes to participant payment test
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 18 Jun 2021 06:24:28 +0000 (18:24 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 18 Jun 2021 23:40:37 +0000 (11:40 +1200)
With 2 participants now being created the failure to update the
second participant to registered is now exposed

CRM/Contribute/BAO/Contribution.php
tests/phpunit/api/v3/PaymentTest.php

index 8ede9632837cd2c41822fa1cf442aaddbfa0d632..3cbd8f580e259711b1f4c4d1d3100bf588143e78 100644 (file)
@@ -4189,11 +4189,13 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
       );
     }
 
-    $participantPayment = civicrm_api3('ParticipantPayment', 'get', ['contribution_id' => $contributionID, 'return' => 'participant_id', 'sequential' => 1])['values'];
-    if (!empty($participantPayment) && empty($input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'])) {
-      $participantParams['id'] = $participantPayment[0]['participant_id'];
-      $participantParams['status_id'] = 'Registered';
-      civicrm_api3('Participant', 'create', $participantParams);
+    $participantPayments = civicrm_api3('ParticipantPayment', 'get', ['contribution_id' => $contributionID, 'return' => 'participant_id', 'sequential' => 1])['values'];
+    if (!empty($participantPayments) && empty($input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'])) {
+      foreach ($participantPayments as $participantPayment) {
+        $participantParams['id'] = $participantPayment['participant_id'];
+        $participantParams['status_id'] = 'Registered';
+        civicrm_api3('Participant', 'create', $participantParams);
+      }
     }
 
     $contributionParams['id'] = $contributionID;
@@ -5337,9 +5339,7 @@ LIMIT 1;";
       'module' => 'CiviEvent',
     ];
 
-    list($custom_pre_id,
-      $custom_post_ids
-      ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
+    [$custom_pre_id, $custom_post_ids] = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
 
     $values['custom_pre_id'] = $custom_pre_id;
     $values['custom_post_id'] = $custom_post_ids;
index 1325c8d54d5208147e4625a97b5d79a17d87dfd9..8638b5175d7145ea99c5beff8070800e865ec721 100644 (file)
@@ -497,9 +497,8 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
     $paymentParticipant = [
       'contribution_id' => $contribution['id'],
     ];
-    $participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
-    $participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
-    $this->assertEquals('Registered', $participant['values'][$participant['id']]['participant_status']);
+    $this->callAPISuccessGetCount('ParticipantPayment', $paymentParticipant, 2);
+    $this->callAPISuccessGetCount('Participant', ['status_id' => 'Registered'], 2);
   }
 
   /**
@@ -588,9 +587,8 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
     $paymentParticipant = [
       'contribution_id' => $contribution['id'],
     ];
-    $participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
-    $participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
-    $this->assertEquals('Registered', $participant['values'][$participant['id']]['participant_status']);
+    $this->callAPISuccessGetCount('ParticipantPayment', $paymentParticipant, 2);
+    $this->callAPISuccessGetCount('participant', ['status_id' => 'Registered'], 2);
   }
 
   /**