From 8880193fc73775edf2f67bc88cee95eafcb5c66e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 4 Sep 2023 16:07:15 +1200 Subject: [PATCH] Fix financial transfer test to use form flow, allow all pending to transfer --- CRM/Event/BAO/Participant.php | 2 +- Civi/Test/FormWrapper.php | 2 +- .../CRM/Event/Form/ParticipantTest.php | 29 +++++++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 40ce885d08..64768f27e0 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1858,7 +1858,7 @@ WHERE civicrm_participant.contact_id = {$contactID} AND return $details; } // Verify participant status is one that can be self-cancelled - if (!in_array($details['status'], ['Registered', 'Pending from pay later', 'On waitlist'])) { + if (!in_array($details['status'], ['Registered', 'Pending from pay later', 'On waitlist', 'Pending from incomplete transaction'])) { $details['eligible'] = FALSE; $details['ineligible_message'] = ts('You cannot transfer or cancel your registration for %1 as you are not currently registered for this event.', [1 => $eventTitle]); return $details; diff --git a/Civi/Test/FormWrapper.php b/Civi/Test/FormWrapper.php index 308cd4d269..f9af7110a1 100644 --- a/Civi/Test/FormWrapper.php +++ b/Civi/Test/FormWrapper.php @@ -28,7 +28,7 @@ class FormWrapper { /** * @var \CRM_Core_Form[] */ - protected $subsequentForms; + protected $subsequentForms = []; private $output; diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 9a16722644..0a69e56a43 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -1,6 +1,7 @@ swapMessageTemplateForInput('event_online_receipt', '{domain.name} {contact.first_name}'); + $this->createEventOrder(); + Event::update()->addWhere('id', '=', $this->getEventID())->setValues([ + 'start_date' => 'next week', + 'allow_selfcancelxfer' => TRUE, + ])->execute(); $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'id']); - //Check line item count of the contribution id before transfer. - $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']); - $this->assertCount(2, $lineItems); + $toContactID = $this->individualCreate([], 'to'); $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $contribution['id'], 'participant_id', 'contribution_id'); - /** @var CRM_Event_Form_SelfSvcTransfer $form */ - $form = $this->getFormObject('CRM_Event_Form_SelfSvcTransfer'); - $toContactId = $this->individualCreate(); - $mut = new CiviMailUtils($this); - $this->swapMessageTemplateForInput('event_online_receipt', '{domain.name} {contact.first_name}'); - $form->transferParticipantRegistration($toContactId, $participantId); + $this->getTestForm('CRM_Event_Form_SelfSvcTransfer', [ + 'contact_id' => $toContactID, + ], [ + 'pid' => $participantId, + 'is_backoffice' => 1, + ])->processForm(); $mut->checkAllMailLog(['Default Domain Name Anthony']); $mut->clearMessages(); $this->revertTemplateToReservedTemplate(); @@ -737,11 +742,11 @@ London,', 'return' => ['transferred_to_contact_id'], 'id' => $participantId, ]); - $this->assertEquals($participant['transferred_to_contact_id'], $toContactId); + $this->assertEquals($participant['transferred_to_contact_id'], $toContactID); //Assert $toContactId has a new registration. $toParticipant = $this->callAPISuccess('Participant', 'getsingle', [ - 'contact_id' => $toContactId, + 'contact_id' => $toContactID, ]); $this->assertEquals($toParticipant['participant_registered_by_id'], $participantId); -- 2.25.1