From c674ed12036eca3bff4f01d3803f1b82fdc09718 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Mon, 9 Nov 2020 18:14:46 -0500 Subject: [PATCH] event#44: Don't allow self-service cancelling after an event when 'hours to cancel' is zero --- CRM/Event/BAO/Participant.php | 8 ++++---- tests/phpunit/CRM/Event/BAO/ParticipantTest.php | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index c68f021c9a..9818d88898 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1922,7 +1922,7 @@ WHERE civicrm_participant.contact_id = {$contactID} AND $start_date = $dao->start; } $timenow = new Datetime(); - if (!$isBackOffice && !empty($time_limit)) { + if (!$isBackOffice && isset($time_limit)) { $cancelHours = abs($time_limit); $cancelInterval = new DateInterval("PT${cancelHours}H"); $cancelInterval->invert = $time_limit < 0 ? 1 : 0; @@ -1930,9 +1930,9 @@ WHERE civicrm_participant.contact_id = {$contactID} AND if ($timenow > $cancelDeadline) { $details['eligible'] = FALSE; // Change the language of the status message based on whether the waitlist time limit is positive or negative. - $afterOrPrior = $time_limit < 0 ? 'after' : 'prior'; - $moreOrLess = $time_limit < 0 ? 'more' : 'less'; - $details['ineligible_message'] = ts("Registration for this event cannot be cancelled or transferred %1 than %2 hours %3 to the event's start time. Contact the event organizer if you have questions.", + $afterOrPrior = $time_limit <= 0 ? 'after' : 'prior to'; + $moreOrLess = $time_limit <= 0 ? 'more' : 'fewer'; + $details['ineligible_message'] = ts("Registration for this event cannot be cancelled or transferred %1 than %2 hours %3 the event's start time. Contact the event organizer if you have questions.", [1 => $moreOrLess, 2 => $cancelHours, 3 => $afterOrPrior]); } diff --git a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php index 4dc15134dc..c274e941c6 100644 --- a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php @@ -426,7 +426,13 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { public function testGetSelfServiceEligibility($selfSvcEnabled, $selfSvcHours, $hoursToEvent, $participantStatusId, $isBackOffice, $successExpected) { $participantId = $this->participantCreate(['contact_id' => $this->_contactId, 'event_id' => $this->_eventId, 'status_id' => $participantStatusId]); $now = new Datetime(); - $startDate = $now->add(new DateInterval("PT{$hoursToEvent}H"))->format('Y-m-d H:i:s'); + if ($hoursToEvent >= 0) { + $startDate = $now->add(new DateInterval("PT{$hoursToEvent}H"))->format('Y-m-d H:i:s'); + } + else { + $hoursAfterEvent = abs($hoursToEvent); + $startDate = $now->sub(new DateInterval("PT{$hoursAfterEvent}H"))->format('Y-m-d H:i:s'); + } $this->callAPISuccess('Event', 'create', [ 'id' => $this->_eventId, 'allow_selfcancelxfer' => $selfSvcEnabled, @@ -502,6 +508,14 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'isBackOffice' => FALSE, 'successExpected' => TRUE, ]; + $scenarios[] = [ + 'selfSvcEnabled' => 1, + 'selfSvcHours' => 0, + 'hoursToEvent' => -6, + 'participantStatusId' => 1, + 'isBackOffice' => FALSE, + 'successExpected' => FALSE, + ]; return $scenarios; } -- 2.25.1