Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix financial transfer test to use form flow, allow all pending to transfer #27281

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Event/BAO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ public static function getSelfServiceEligibility(int $participantId, string $url
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;
Expand Down
2 changes: 1 addition & 1 deletion Civi/Test/FormWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FormWrapper {
/**
* @var \CRM_Core_Form[]
*/
protected $subsequentForms;
protected $subsequentForms = [];

private $output;

Expand Down
29 changes: 17 additions & 12 deletions tests/phpunit/CRM/Event/Form/ParticipantTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Civi\Api4\Address;
use Civi\Api4\Event;
use Civi\Api4\LineItem;
use Civi\Api4\LocBlock;
use Civi\Api4\Participant;
Expand Down Expand Up @@ -715,19 +716,23 @@ protected function getRecordContributionParams(string $participantStatus): array
* @throws \CRM_Core_Exception
*/
public function testTransferParticipantRegistration(): void {
//Register a contact to a sample event.
$mut = new CiviMailUtils($this);
$this->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();
Expand All @@ -737,11 +742,11 @@ public function testTransferParticipantRegistration(): void {
'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);

Expand Down