Skip to content

Commit

Permalink
Add effective end and start date, extend unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Apr 6, 2021
1 parent 177b66d commit f235617
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Civi/ActionSchedule/RecipientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ protected function prepareStartDateClauses() {
else {
$startDateClauses[] = "DATE_SUB(!casNow, INTERVAL 1 DAY ) <= {$date}";
}
$startDateClauses[] = "(effective_start_date IS NULL OR effective_start_date <= {$date})";
$startDateClauses[] = "(effective_end_date IS NULL OR effective_end_date > {$date})";
}
elseif ($actionSchedule->absolute_date) {
$startDateClauses[] = "DATEDIFF(DATE('!casNow'),'{$actionSchedule->absolute_date}') = 0";
Expand Down
53 changes: 53 additions & 0 deletions tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public function setUp(): void {
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => '1-Day (non-repeating) (about {activity.activity_type})',
'effective_start_date' => '2012-06-14 00:00:00',
'effective_end_date' => '2012-06-15 00:00:00',
];
$this->fixtures['sched_activity_1day_r'] = [
'name' => 'One_Day_Phone_Call_Notice_R',
Expand Down Expand Up @@ -183,6 +185,7 @@ public function setUp(): void {
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => '1-Day (repeating) (about {activity.activity_type})',
'effective_end_date' => '2012-06-14 01:00:01',
];
$this->fixtures['sched_activity_1day_r_on_abs_date'] = [
'name' => 'One_Day_Phone_Call_Notice_R',
Expand Down Expand Up @@ -2065,6 +2068,56 @@ public function testEventTypeStartDate(): void {
'recipients' => [],
],
]);

// CASE 2: Create a schedule reminder which was created 1 day after the schdule day,
// so it shouldn't deliver reminders schedule to send 1 week before the event start date
$actionSchedule = $this->fixtures['sched_eventtype_start_1week_before'];
$actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
$actionSchedule['effective_start_date'] = '20120309000000';
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
[
// 2 weeks before
'time' => '2012-03-02 01:00:00',
'recipients' => [],
],
[
// 1 week before
'time' => '2012-03-08 01:00:00',
'recipients' => [],
],
[
// And then nothing else
'time' => '2012-03-16 01:00:00',
'recipients' => [],
],
]);

// CASE 3: Create a schedule reminder which is created less then a week before the event start date,
// so it should deliver reminders schedule to send 1 week before the event start date, set the effective end date just an hour later the reminder delivery date
$actionSchedule = $this->fixtures['sched_eventtype_start_1week_before'];
$actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
$actionSchedule['effective_end_date'] = '20120309010000';
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$this->assertCronRuns([
[
// 2 weeks before
'time' => '2012-03-02 01:00:00',
'recipients' => [],
],
[
// 1 week before
'time' => '2012-03-08 01:00:00',
'recipients' => [['test-event@example.com']],
],
[
// And then nothing else
'time' => '2012-03-16 01:00:00',
'recipients' => [],
],
]);
}

/**
Expand Down

0 comments on commit f235617

Please sign in to comment.