$this->eventDelete($eventId);
}
+ /**
+ * Test various self-service eligibility scenarios.
+ *
+ * @dataProvider selfServiceScenarios
+ * @param $selfSvcEnabled
+ * @param $selfSvcHours
+ * @param $hoursToEvent
+ * @param $participantStatusId
+ * @param $isBackOffice
+ * @param $successExpected A boolean that indicates whether this test should pass or fail.
+ */
+ 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');
+ $this->callAPISuccess('Event', 'create', [
+ 'id' => $this->_eventId,
+ 'allow_selfcancelxfer' => $selfSvcEnabled,
+ 'selfcancelxfer_time' => $selfSvcHours,
+ 'start_date' => $startDate,
+ ]);
+ $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}");
+ $details = CRM_Event_BAO_Participant::getSelfServiceEligibility($participantId, $url, $isBackOffice);
+ $this->assertEquals($details['eligible'], $successExpected);
+ }
+
+ public function selfServiceScenarios() {
+ // Standard pass scenario
+ $scenarios[] = [
+ 'selfSvcEnabled' => 1,
+ 'selfSvcHours' => 12,
+ 'hoursToEvent' => 16,
+ 'participantStatusId' => 1,
+ 'isBackOffice' => FALSE,
+ 'successExpected' => TRUE,
+ ];
+ // Too late to self-service
+ $scenarios[] = [
+ 'selfSvcEnabled' => 1,
+ 'selfSvcHours' => 12,
+ 'hoursToEvent' => 8,
+ 'participantStatusId' => 1,
+ 'isBackOffice' => FALSE,
+ 'successExpected' => FALSE,
+ ];
+ // Participant status is other than "Registered".
+ $scenarios[] = [
+ 'selfSvcEnabled' => 1,
+ 'selfSvcHours' => 12,
+ 'hoursToEvent' => 16,
+ 'participantStatusId' => 2,
+ 'isBackOffice' => FALSE,
+ 'successExpected' => FALSE,
+ ];
+ // Event doesn't allow self-service
+ $scenarios[] = [
+ 'selfSvcEnabled' => 0,
+ 'selfSvcHours' => 12,
+ 'hoursToEvent' => 16,
+ 'participantStatusId' => 1,
+ 'isBackOffice' => FALSE,
+ 'successExpected' => FALSE,
+ ];
+ // Cancellation deadline is > 24 hours, still ok to cancel
+ $scenarios[] = [
+ 'selfSvcEnabled' => 1,
+ 'selfSvcHours' => 36,
+ 'hoursToEvent' => 46,
+ 'participantStatusId' => 1,
+ 'isBackOffice' => FALSE,
+ 'successExpected' => TRUE,
+ ];
+ // Cancellation deadline is > 24 hours, too late to cancel
+ $scenarios[] = [
+ 'selfSvcEnabled' => 1,
+ 'selfSvcHours' => 36,
+ 'hoursToEvent' => 25,
+ 'participantStatusId' => 1,
+ 'isBackOffice' => FALSE,
+ 'successExpected' => FALSE,
+ ];
+ return $scenarios;
+ }
+
}