3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 require_once 'CiviTest/CiviUnitTestCase.php';
15 * Class CRM_Activity_ActionMappingTest
16 * @group ActionSchedule
18 * This class tests various configurations of scheduled-reminders, with a focus on
19 * reminders for *activity types*. It follows a design/pattern described in
20 * AbstractMappingTest.
22 * NOTE: There are also pretty deep tests of activity-based reminders in
23 * CRM_Core_BAO_ActionScheduleTest.
25 * @see \Civi\ActionSchedule\AbstractMappingTest
26 * @see CRM_Core_BAO_ActionScheduleTest
28 class CRM_Activity_ActionMappingTest
extends \Civi\ActionSchedule\AbstractMappingTest
{
31 * Generate a list of test cases, where each is a distinct combination of
32 * data, schedule-rules, and schedule results.
35 * - targetDate: string; eg "2015-02-01 00:00:01"
36 * - setupFuncs: string, space-separated list of setup functions
37 * - messages: array; each item is a message that's expected to be sent
38 * each message may include keys:
39 * - time: approximate time (give or take a few seconds)
40 * - recipients: array of emails
43 public function createTestCases() {
47 '2015-02-01 00:00:00',
48 'addAliceMeeting scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource',
51 'time' => '2015-02-01 00:00:00',
52 'to' => ['alice@example.org'],
53 'subject' => '/Hello, Alice.*via subject/',
58 // FIXME: CRM-19415: This test should pass...
60 // '2015-02-01 00:00:00',
61 // 'addAliceMeeting scheduleForAny startOnTime useHelloFirstName recipientIsBob',
64 // 'time' => '2015-02-01 00:00:00',
65 // 'to' => array('bob@example.org'),
66 // 'subject' => '/Hello, Bob.*via subject/',
67 // // It might make more sense to get Alice's details... but path of least resistance...
73 '2015-02-01 00:00:00',
74 'addAliceMeeting addBobPhoneCall scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource',
77 'time' => '2015-02-01 00:00:00',
78 'to' => ['alice@example.org'],
79 'subject' => '/Hello, Alice.*via subject/',
85 '2015-02-01 00:00:00',
86 'addAliceMeeting addBobPhoneCall scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource',
89 'time' => '2015-02-01 00:00:00',
90 'to' => ['alice@example.org'],
91 'subject' => '/Hello, Alice.*via subject/',
94 'time' => '2015-02-01 00:00:00',
95 'to' => ['bob@example.org'],
96 'subject' => '/Hello, Bob.*via subject/',
102 '2015-02-02 00:00:00',
103 'addAliceMeeting addBobPhoneCall scheduleForPhoneCall startWeekBefore repeatTwoWeeksAfter useHelloFirstName recipientIsActivitySource',
106 'time' => '2015-01-26 00:00:00',
107 'to' => ['bob@example.org'],
108 'subject' => '/Hello, Bob.*via subject/',
111 'time' => '2015-02-02 00:00:00',
112 'to' => ['bob@example.org'],
113 'subject' => '/Hello, Bob.*via subject/',
116 'time' => '2015-02-09 00:00:00',
117 'to' => ['bob@example.org'],
118 'subject' => '/Hello, Bob.*via subject/',
121 'time' => '2015-02-16 00:00:00',
122 'to' => ['bob@example.org'],
123 'subject' => '/Hello, Bob.*via subject/',
128 // No recipients: Dave has `do_not_email`, Edith is dead, and Francis' email
131 '2015-02-01 00:00:00',
132 'addDaveMeeting addEdithMeeting addFrancisMeeting scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource',
136 // Gretchen has one email on hold, but her primary email is not on hold.
138 '2015-02-01 00:00:00',
139 'addGretchenMeeting scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource',
142 'time' => '2015-02-01 00:00:00',
143 'to' => ['gretchen@example.org'],
144 'subject' => '/Hello, Gretchen.*via subject/',
153 * Create an activity record for Alice with type "Meeting".
155 public function addAliceMeeting() {
156 $this->callAPISuccess('Activity', 'create', [
157 'source_contact_id' => $this->contacts
['alice']['id'],
158 'activity_type_id' => 'Meeting',
159 'subject' => 'Subject for Alice',
160 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
162 'assignee_contact_id' => [$this->contacts
['carol']['id']],
167 * Create a contribution record for Bob with type "Donation".
169 public function addBobPhoneCall() {
170 $this->callAPISuccess('Activity', 'create', [
171 'source_contact_id' => $this->contacts
['bob']['id'],
172 'activity_type_id' => 'Phone Call',
173 'subject' => 'Subject for Bob',
174 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
176 'assignee_contact_id' => [$this->contacts
['carol']['id']],
181 * Create an activity record for Dave with type "Meeting". Dave has
182 * "do_not_email" set, so he should never receive an email reminder.
184 public function addDaveMeeting() {
185 $this->callAPISuccess('Activity', 'create', [
186 'source_contact_id' => $this->contacts
['dave']['id'],
187 'activity_type_id' => 'Meeting',
188 'subject' => 'Subject for Dave',
189 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
191 'assignee_contact_id' => [$this->contacts
['carol']['id']],
196 * Create an activity record for Edith with type "Meeting". Edith is dead, so
197 * she should never receive an email reminder.
199 public function addEdithMeeting() {
200 $this->callAPISuccess('Activity', 'create', [
201 'source_contact_id' => $this->contacts
['edith']['id'],
202 'activity_type_id' => 'Meeting',
203 'subject' => 'Subject for Edith',
204 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
206 'assignee_contact_id' => [$this->contacts
['carol']['id']],
211 * Create an activity record for Francis with type "Meeting". Francis' email
212 * is misspelled and has bounced, so he should never receive an email reminder.
214 public function addFrancisMeeting() {
215 $this->callAPISuccess('Activity', 'create', [
216 'source_contact_id' => $this->contacts
['francis']['id'],
217 'activity_type_id' => 'Meeting',
218 'subject' => 'Subject for Francis',
219 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
221 'assignee_contact_id' => [$this->contacts
['carol']['id']],
226 * Create an activity record for Gretchen with type "Meeting".
228 public function addGretchenMeeting() {
229 $this->callAPISuccess('Activity', 'create', [
230 'source_contact_id' => $this->contacts
['gretchen']['id'],
231 'activity_type_id' => 'Meeting',
232 'subject' => 'Subject for Gretchen',
233 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
235 'assignee_contact_id' => [$this->contacts
['carol']['id']],
240 * Schedule message delivery for activities of type "Meeting".
242 public function scheduleForMeeting() {
243 $actTypes = CRM_Activity_BAO_Activity
::buildOptions('activity_type_id');
244 $this->schedule
->mapping_id
= CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
;
245 $this->schedule
->start_action_date
= 'receive_date';
246 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded([array_search('Meeting', $actTypes)]);
247 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded([2]);
251 * Schedule message delivery for activities of type "Phone Call".
253 public function scheduleForPhoneCall() {
254 $actTypes = CRM_Activity_BAO_Activity
::buildOptions('activity_type_id');
255 $this->schedule
->mapping_id
= CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
;
256 $this->schedule
->start_action_date
= 'receive_date';
257 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded([array_search('Phone Call', $actTypes)]);
258 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
262 * Schedule message delivery for any contribution, regardless of type.
264 public function scheduleForAny() {
265 $actTypes = CRM_Activity_BAO_Activity
::buildOptions('activity_type_id');
266 $this->schedule
->mapping_id
= CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
;
267 $this->schedule
->start_action_date
= 'receive_date';
268 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(array_keys($actTypes));
269 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
273 * Set the recipient to "Choose Recipient(s): Bob".
275 public function recipientIsBob() {
276 $this->schedule
->limit_to
= 1;
277 $this->schedule
->recipient
= NULL;
278 $this->schedule
->recipient_listing
= NULL;
279 $this->schedule
->recipient_manual
= $this->contacts
['bob']['id'];
283 * Set the recipient to "Activity Assignee".
285 public function recipientIsActivityAssignee() {
286 $this->schedule
->limit_to
= 1;
287 $this->schedule
->recipient
= 1;
288 $this->schedule
->recipient_listing
= NULL;
289 $this->schedule
->recipient_manual
= NULL;
293 * Set the recipient to "Activity Source".
295 public function recipientIsActivitySource() {
296 $this->schedule
->limit_to
= 1;
297 $this->schedule
->recipient
= 2;
298 $this->schedule
->recipient_listing
= NULL;
299 $this->schedule
->recipient_manual
= NULL;