3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Class CRM_Activity_ActionMappingTest
32 * @group ActionSchedule
34 * This class tests various configurations of scheduled-reminders, with a focus on
35 * reminders for *activity types*. It follows a design/pattern described in
36 * AbstractMappingTest.
38 * NOTE: There are also pretty deep tests of activity-based reminders in
39 * CRM_Core_BAO_ActionScheduleTest.
41 * @see \Civi\ActionSchedule\AbstractMappingTest
42 * @see CRM_Core_BAO_ActionScheduleTest
44 class CRM_Activity_ActionMappingTest
extends \Civi\ActionSchedule\AbstractMappingTest
{
47 * Generate a list of test cases, where each is a distinct combination of
48 * data, schedule-rules, and schedule results.
51 * - targetDate: string; eg "2015-02-01 00:00:01"
52 * - setupFuncs: string, space-separated list of setup functions
53 * - messages: array; each item is a message that's expected to be sent
54 * each message may include keys:
55 * - time: approximate time (give or take a few seconds)
56 * - recipients: array of emails
59 public function createTestCases() {
63 '2015-02-01 00:00:00',
64 'addAliceMeeting scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource',
67 'time' => '2015-02-01 00:00:00',
68 'to' => ['alice@example.org'],
69 'subject' => '/Hello, Alice.*via subject/',
74 // FIXME: CRM-19415: This test should pass...
76 // '2015-02-01 00:00:00',
77 // 'addAliceMeeting scheduleForAny startOnTime useHelloFirstName recipientIsBob',
80 // 'time' => '2015-02-01 00:00:00',
81 // 'to' => array('bob@example.org'),
82 // 'subject' => '/Hello, Bob.*via subject/',
83 // // It might make more sense to get Alice's details... but path of least resistance...
89 '2015-02-01 00:00:00',
90 'addAliceMeeting addBobPhoneCall scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource',
93 'time' => '2015-02-01 00:00:00',
94 'to' => ['alice@example.org'],
95 'subject' => '/Hello, Alice.*via subject/',
101 '2015-02-01 00:00:00',
102 'addAliceMeeting addBobPhoneCall scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource',
105 'time' => '2015-02-01 00:00:00',
106 'to' => ['alice@example.org'],
107 'subject' => '/Hello, Alice.*via subject/',
110 'time' => '2015-02-01 00:00:00',
111 'to' => ['bob@example.org'],
112 'subject' => '/Hello, Bob.*via subject/',
118 '2015-02-02 00:00:00',
119 'addAliceMeeting addBobPhoneCall scheduleForPhoneCall startWeekBefore repeatTwoWeeksAfter useHelloFirstName recipientIsActivitySource',
122 'time' => '2015-01-26 00:00:00',
123 'to' => ['bob@example.org'],
124 'subject' => '/Hello, Bob.*via subject/',
127 'time' => '2015-02-02 00:00:00',
128 'to' => ['bob@example.org'],
129 'subject' => '/Hello, Bob.*via subject/',
132 'time' => '2015-02-09 00:00:00',
133 'to' => ['bob@example.org'],
134 'subject' => '/Hello, Bob.*via subject/',
137 'time' => '2015-02-16 00:00:00',
138 'to' => ['bob@example.org'],
139 'subject' => '/Hello, Bob.*via subject/',
144 // No recipients: Dave has `do_not_email`, Edith is dead, and Francis' email
147 '2015-02-01 00:00:00',
148 'addDaveMeeting addEdithMeeting addFrancisMeeting scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource',
156 * Create an activity record for Alice with type "Meeting".
158 public function addAliceMeeting() {
159 $this->callAPISuccess('Activity', 'create', [
160 'source_contact_id' => $this->contacts
['alice']['id'],
161 'activity_type_id' => 'Meeting',
162 'subject' => 'Subject for Alice',
163 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
165 'assignee_contact_id' => [$this->contacts
['carol']['id']],
170 * Create a contribution record for Bob with type "Donation".
172 public function addBobPhoneCall() {
173 $this->callAPISuccess('Activity', 'create', [
174 'source_contact_id' => $this->contacts
['bob']['id'],
175 'activity_type_id' => 'Phone Call',
176 'subject' => 'Subject for Bob',
177 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
179 'assignee_contact_id' => [$this->contacts
['carol']['id']],
184 * Create an activity record for Dave with type "Meeting". Dave has
185 * "do_not_email" set, so he should never receive an email reminder.
187 public function addDaveMeeting() {
188 $this->callAPISuccess('Activity', 'create', [
189 'source_contact_id' => $this->contacts
['dave']['id'],
190 'activity_type_id' => 'Meeting',
191 'subject' => 'Subject for Dave',
192 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
194 'assignee_contact_id' => [$this->contacts
['carol']['id']],
199 * Create an activity record for Edith with type "Meeting". Edith is dead, so
200 * she should never receive an email reminder.
202 public function addEdithMeeting() {
203 $this->callAPISuccess('Activity', 'create', [
204 'source_contact_id' => $this->contacts
['edith']['id'],
205 'activity_type_id' => 'Meeting',
206 'subject' => 'Subject for Edith',
207 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
209 'assignee_contact_id' => [$this->contacts
['carol']['id']],
214 * Create an activity record for Francis with type "Meeting". Francis' email
215 * is misspelled and has bounced, so he should never receive an email reminder.
217 public function addFrancisMeeting() {
218 $this->callAPISuccess('Activity', 'create', [
219 'source_contact_id' => $this->contacts
['francis']['id'],
220 'activity_type_id' => 'Meeting',
221 'subject' => 'Subject for Francis',
222 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
224 'assignee_contact_id' => [$this->contacts
['carol']['id']],
229 * Schedule message delivery for activities of type "Meeting".
231 public function scheduleForMeeting() {
232 $actTypes = CRM_Activity_BAO_Activity
::buildOptions('activity_type_id');
233 $this->schedule
->mapping_id
= CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
;
234 $this->schedule
->start_action_date
= 'receive_date';
235 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded([array_search('Meeting', $actTypes)]);
236 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded([2]);
240 * Schedule message delivery for activities of type "Phone Call".
242 public function scheduleForPhoneCall() {
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('Phone Call', $actTypes)]);
247 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
251 * Schedule message delivery for any contribution, regardless of type.
253 public function scheduleForAny() {
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_keys($actTypes));
258 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
262 * Set the recipient to "Choose Recipient(s): Bob".
264 public function recipientIsBob() {
265 $this->schedule
->limit_to
= 1;
266 $this->schedule
->recipient
= NULL;
267 $this->schedule
->recipient_listing
= NULL;
268 $this->schedule
->recipient_manual
= $this->contacts
['bob']['id'];
272 * Set the recipient to "Activity Assignee".
274 public function recipientIsActivityAssignee() {
275 $this->schedule
->limit_to
= 1;
276 $this->schedule
->recipient
= 1;
277 $this->schedule
->recipient_listing
= NULL;
278 $this->schedule
->recipient_manual
= NULL;
282 * Set the recipient to "Activity Source".
284 public function recipientIsActivitySource() {
285 $this->schedule
->limit_to
= 1;
286 $this->schedule
->recipient
= 2;
287 $this->schedule
->recipient_listing
= NULL;
288 $this->schedule
->recipient_manual
= NULL;