From 395c7838e229a3ffdfeb77fd8b1453d5a95f0805 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 18 Jun 2021 18:24:28 +1200 Subject: [PATCH] Follow up fixes to participant payment test With 2 participants now being created the failure to update the second participant to registered is now exposed --- CRM/Contribute/BAO/Contribution.php | 16 ++++++++-------- tests/phpunit/api/v3/PaymentTest.php | 10 ++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 8ede963283..3cbd8f580e 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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; diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 1325c8d54d..8638b5175d 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -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); } /** -- 2.25.1