From 57132859d88db9778967bc69c7e261e18245fd81 Mon Sep 17 00:00:00 2001 From: Klaas Eikelboom Date: Thu, 26 May 2022 20:18:04 +0200 Subject: [PATCH] Fixes core#3369 Scheduled Reminder limited by Participant Role fails if any participant has multiple roles --- CRM/Event/ActionMapping.php | 2 +- .../CRM/Core/BAO/ActionScheduleTest.php | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CRM/Event/ActionMapping.php b/CRM/Event/ActionMapping.php index 58569f75eb..ae76bf3df2 100644 --- a/CRM/Event/ActionMapping.php +++ b/CRM/Event/ActionMapping.php @@ -149,7 +149,7 @@ class CRM_Event_ActionMapping extends \Civi\ActionSchedule\Mapping { if ($schedule->recipient_listing && $schedule->limit_to) { switch ($schedule->recipient) { case 'participant_role': - $regex = "([[:cntrl:]]|^)" . implode('([[:cntrl:]]|$)|([[:cntrl:]]|^)', (array) $schedule->recipient_listing) . "([[:cntrl:]]|$)"; + $regex = "([[:cntrl:]]|^)" . implode('([[:cntrl:]]|$)|([[:cntrl:]]|^)', \CRM_Utils_Array::explodePadded($schedule->recipient_listing)) . "([[:cntrl:]]|$)"; $query->where("e.role_id REGEXP (@regex)") ->param('regex', $regex); break; diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index afaa596115..bfd0ea40f0 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -2341,6 +2341,56 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { ]); } + /** + * Test event registration that is limited to a participant role. + * @dataProvider provideEventRegistrationLimitToData + * @throws \CRM_Core_Exception + */ + public function testEventRegistrationLimitTo($testValue, $select): void { + // Create event+participant with start_date = 20120315, end_date = 20120615. + $params = $this->fixtures['participant']; + $params['event_id'] = $this->callAPISuccess('Event', 'create', array_merge($this->fixtures['participant']['event_id'], ['event_type_id' => 1]))['id']; + $params['status_id'] = 2; + $params['role_id'] = $testValue['role_id']; + $params['contact_id'] = $this->individualCreate(array_merge($this->fixtures['contact'], ['email' => 'test-event@example.com'])); + $this->callAPISuccess('Participant', 'create', $params); + + $actionSchedule = $this->fixtures['sched_event_type_start_1week_before']; + $actionSchedule['limit_to'] = TRUE; + $actionSchedule['recipient'] = 'participant_role'; + $actionSchedule['recipient_listing'] = $testValue['recipient_listing']; + $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'event_type_id'); + $this->callAPISuccess('action_schedule', 'create', $actionSchedule); + + // end_date=2012-06-15 ; schedule is 2 weeks before end_date + $this->assertCronRuns([ + [ + 'time' => '2012-03-08 01:00:00', + 'recipients' => $select ? [['test-event@example.com']] : [], + ], + ]); + } + + /** + * provides testdata for testEventRegistrationLimitTo + * @return array[] + */ + public function provideEventRegistrationLimitToData() { + return [ + [['role_id' => 1, 'recipient_listing' => 1], TRUE], + [['role_id' => 1, 'recipient_listing' => 2], FALSE], + [['role_id' => [1, 2], 'recipient_listing' => 2], TRUE], + [['role_id' => [1, 3], 'recipient_listing' => 2], FALSE], + [['role_id' => 1, 'recipient_listing' => \CRM_Utils_Array::implodePadded([1])], TRUE], + [['role_id' => 1, 'recipient_listing' => \CRM_Utils_Array::implodePadded([1, 2])], TRUE], + [['role_id' => 2, 'recipient_listing' => \CRM_Utils_Array::implodePadded([1, 2])], TRUE], + [['role_id' => 3, 'recipient_listing' => \CRM_Utils_Array::implodePadded([1, 2])], FALSE], + [['role_id' => [1, 3], 'recipient_listing' => \CRM_Utils_Array::implodePadded([1, 2])], TRUE], + [['role_id' => [3, 2], 'recipient_listing' => \CRM_Utils_Array::implodePadded([1, 2])], TRUE], + [['role_id' => [3, 4], 'recipient_listing' => \CRM_Utils_Array::implodePadded([1, 2])], FALSE], + ]; + } + /** * Test schedule on event end date. * -- 2.25.1