From ed66ac46df9505af5aeb8ed167040232b7c91a61 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Wed, 22 Jan 2020 18:13:21 -0500 Subject: [PATCH] event#30 - don't allow multiple waitlist registrations --- CRM/Event/Form/Registration/Register.php | 8 ++-- .../Form/Registration/RegistrationTest.php | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 4065bed5db..be483125d7 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -1186,7 +1186,8 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } $participant->is_test = 0; $participant->find(); - $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); + // Event#30 - Anyone whose status type has `is_counted` OR is on the waitlist should be considered as registered. + $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1') + CRM_Event_PseudoConstant::participantStatus(NULL, "name = 'On waitlist'"); while ($participant->fetch()) { if (array_key_exists($participant->status_id, $statusTypes)) { if (!$isAdditional && !$form->_values['event']['allow_same_participant_emails']) { @@ -1196,8 +1197,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { if ($form->_pcpId) { $registerUrl .= '&pcpId=' . $form->_pcpId; } - - $status = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've received this message in error, please contact the site administrator.") . ' ' . ts('You can also register another participant.', [1 => $registerUrl]); + $registrationType = (CRM_Event_PseudoConstant::getKey('CRM_Event_BAO_Participant', 'participant_status_id', 'On waitlist') == $participant->status_id) ? 'waitlisted' : 'registered'; + $status = ts("It looks like you are already %1 for this event. If you want to change your registration, or you feel that you've received this message in error, please contact the site administrator.", [1 => $registrationType]); + $status .= ' ' . ts('You can also register another participant.', [1 => $registerUrl]); CRM_Core_Session::singleton()->setStatus($status, ts('Oops.'), 'alert'); $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$form->_values['event']['id']}&noFullMsg=true" diff --git a/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php b/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php index a82268ea90..f48137d1c9 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/RegistrationTest.php @@ -57,4 +57,44 @@ class CRM_Event_Form_Registration_RegistrationTest extends CiviUnitTestCase { $this->checkArrayEquals($expectedResult, $errors); } + /** + * event#30 + */ + public function testDoubleWaitlistRegistration() { + // By default, waitlist participant statuses are disabled (which IMO is poor UX). + $sql = "UPDATE civicrm_participant_status_type SET is_active = 1"; + CRM_Core_DAO::executeQuery($sql); + + // Create an event, fill its participant slots. + $event = $this->eventCreate([ + 'has_waitlist' => 1, + 'max_participants' => 1, + 'start_date' => 20351021, + 'end_date' => 20351023, + 'registration_end_date' => 20351015, + ]); + $this->participantCreate(['event_id' => $event['id']]); + + // Add someone to the waitlist. + $waitlistContact = $this->individualCreate(); + + $firstWaitlist = $this->participantCreate(['event_id' => $event['id'], 'contact_id' => $waitlistContact, 'status_id' => 'On waitlist']); + + // We should now have two participants. + $this->callAPISuccessGetCount('Participant', ['event_id' => $event['id']], 2); + + $form = new CRM_Event_Form_Registration_Register(); + $form->controller = new CRM_Core_Controller(); + $form->set('id', $event['id']); + $form->set('cid', $waitlistContact); + // We SHOULD get an error when double registering a waitlisted user. + try { + $form->preProcess(); + } + catch (CRM_Core_Exception_PrematureExitException $e) { + return; + } + $this->fail('Waitlisted users shouldn\'t be allowed to re-register.'); + } + } -- 2.25.1