'activity_date_time' => '20120615100000',
'is_current_revision' => 1,
'is_deleted' => 0,
+ 'subject' => 'Phone call',
+ 'details' => 'A phone call about a bear',
];
$this->fixtures['contact'] = [
'is_deceased' => 0,
'{activity.activity_type}',
]);
// Further tokens can be tested in the body text/html.
+ // We use a dummy string to represent the custom token as this is done in setUp which is run after this function is called.
$manyTokensTmpl = implode(';;', [
$someTokensTmpl,
'{contact.email_greeting}',
- $this->fixtures['contact_custom_token']['token'],
+ '{contactCustomToken}',
]);
// Note: The behavior of domain-tokens on a scheduled reminder is undefined. All we
// can really do is check that it has something.
$someTokensExpected = 'Churmondleia Ōtākou;;Female;;Female;;[a-zA-Z0-9 ]+;;Phone Call';
- $manyTokensExpected = sprintf('%s;;Dear Churmondleia;;%s', $someTokensExpected, $this->fixtures['contact_custom_token']['value']);
+ $manyTokensExpected = sprintf('%s;;Dear Churmondleia;;%s', $someTokensExpected, '{contactCustomTokenValue}');
// In this example, we use a lot of tokens cutting across multiple components.
$cases[0] = [
],
];
+ // In this example, we test activity tokens
+ $activityTokens = '{activity.subject};;{activity.details};;{activity.activity_date_time}';
+ $activity = $this->fixtures['phonecall'];
+ $activityTokensExpected = "Phone call;;A phone call about a bear;;June 15th, 2012 10:00 AM";
+ $cases[4] = [
+ // Schedule definition.
+ [
+ 'subject' => "subj $someTokensTmpl",
+ 'body_html' => "html {$activityTokens}",
+ 'body_text' => "text {$activityTokens}",
+ ],
+ // Assertions (regex).
+ [
+ 'from_name' => '/^FIXME$/',
+ 'from_email' => '/^info@EXAMPLE.ORG$/',
+ 'subject' => "/^subj $someTokensExpected\$/",
+ 'body_html' => "/^html $activityTokensExpected\$/",
+ 'body_text' => "/^text $activityTokensExpected\$/",
+ ],
+ ];
+
return $cases;
}
* @dataProvider mailerExamples
*/
public function testMailer(array $schedule, array $patterns): void {
+ // Replace the dummy custom contact token referecnes in schedule and patterns that we had to insert because phpunit
+ // evaluates dataProviders before running setUp
+ foreach ($schedule as $type => $content) {
+ $schedule[$type] = str_replace('{contactCustomToken}', $this->fixtures['contact_custom_token']['token'], $content);
+ }
+ foreach ($patterns as $type => $content) {
+ $patterns[$type] = str_replace('{contactCustomTokenValue}', $this->fixtures['contact_custom_token']['value'], $content);
+ }
$this->createScheduleFromFixtures('sched_activity_1day', $schedule);
$activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phone_call']);
$contact = $this->callAPISuccess('contact', 'create', array_merge(
'contact_id' => $membership['contact_id'],
'email' => 'test-member@example.com',
]);
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
- $actionScheduleOn['effective_start_date'] = '2012-06-14 00:00:00';
- $actionScheduleAfter['effective_end_date'] = '2012-06-15 01:00:00';
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership['contact_id']]));
$this->createScheduleFromFixtures('sched_membership_end_2week', [
- 'entity_value' => $membership->membership_type_id,
- 'effective_start_date' => '2012-06-14 00:00:00',
- 'effective_end_date' => '2012-06-15 01:00:00',
+ 'entity_value' => $membership['membership_type_id'],
+ 'effective_start_date' => '2012-06-01 00:00:00',
]);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
$actionScheduleAfter = $this->fixtures['sched_after_1day_membership_end_date'];
$actionScheduleAfter['effective_start_date'] = '2012-06-15 01:00:00';
$actionScheduleAfter['effective_end_date'] = '2012-06-16 02:00:00';
- $actionScheduleBefore['entity_value'] = $actionScheduleOn['entity_value'] = $actionScheduleAfter['entity_value'] = $membership->membership_type_id;
+ $actionScheduleBefore['entity_value'] = $actionScheduleOn['entity_value'] = $actionScheduleAfter['entity_value'] = $membership['membership_type_id'];
foreach (['actionScheduleBefore', 'actionScheduleOn', 'actionScheduleAfter'] as $value) {
$$value = CRM_Core_BAO_ActionSchedule::add($$value);
}
$membershipBAO->end_date = '2012-06-20';
$membershipBAO->save();
+ // increase the effective end date to future
+ $actionScheduleAfter->effective_end_date = '2012-07-22 00:00:00';
+ $actionScheduleAfter->save();
+
$this->callAPISuccess('Contact', 'get', ['id' => $membership['contact_id']]);
$this->assertCronRuns(
[
// 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_event_type_start_1week_before'];
- $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
+ $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['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
// 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_event_type_start_1week_before'];
- $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
+ $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['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