3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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' => array('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' => array('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' => array('alice@example.org'),
107 'subject' => '/Hello, Alice.*via subject/',
110 'time' => '2015-02-01 00:00:00',
111 'to' => array('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' => array('bob@example.org'),
124 'subject' => '/Hello, Bob.*via subject/',
127 'time' => '2015-02-02 00:00:00',
128 'to' => array('bob@example.org'),
129 'subject' => '/Hello, Bob.*via subject/',
132 'time' => '2015-02-09 00:00:00',
133 'to' => array('bob@example.org'),
134 'subject' => '/Hello, Bob.*via subject/',
137 'time' => '2015-02-16 00:00:00',
138 'to' => array('bob@example.org'),
139 'subject' => '/Hello, Bob.*via subject/',
148 * Create an activity record for Alice with type "Meeting".
150 public function addAliceMeeting() {
151 $this->callAPISuccess('Activity', 'create', array(
152 'source_contact_id' => $this->contacts
['alice']['id'],
153 'activity_type_id' => 'Meeting',
154 'subject' => 'Subject for Alice',
155 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
157 'assignee_contact_id' => array($this->contacts
['carol']['id']),
162 * Create a contribution record for Bob with type "Donation".
164 public function addBobPhoneCall() {
165 $this->callAPISuccess('Activity', 'create', array(
166 'source_contact_id' => $this->contacts
['bob']['id'],
167 'activity_type_id' => 'Phone Call',
168 'subject' => 'Subject for Bob',
169 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate
)),
171 'assignee_contact_id' => array($this->contacts
['carol']['id']),
176 * Schedule message delivery for activities of type "Meeting".
178 public function scheduleForMeeting() {
179 $actTypes = CRM_Activity_BAO_Activity
::buildOptions('activity_type_id');
180 $this->schedule
->mapping_id
= CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
;
181 $this->schedule
->start_action_date
= 'receive_date';
182 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(array(array_search('Meeting', $actTypes)));
183 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(array(2));
187 * Schedule message delivery for activities of type "Phone Call".
189 public function scheduleForPhoneCall() {
190 $actTypes = CRM_Activity_BAO_Activity
::buildOptions('activity_type_id');
191 $this->schedule
->mapping_id
= CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
;
192 $this->schedule
->start_action_date
= 'receive_date';
193 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(array(array_search('Phone Call', $actTypes)));
194 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
198 * Schedule message delivery for any contribution, regardless of type.
200 public function scheduleForAny() {
201 $actTypes = CRM_Activity_BAO_Activity
::buildOptions('activity_type_id');
202 $this->schedule
->mapping_id
= CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
;
203 $this->schedule
->start_action_date
= 'receive_date';
204 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(array_keys($actTypes));
205 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
209 * Set the recipient to "Choose Recipient(s): Bob".
211 public function recipientIsBob() {
212 $this->schedule
->limit_to
= 1;
213 $this->schedule
->recipient
= NULL;
214 $this->schedule
->recipient_listing
= NULL;
215 $this->schedule
->recipient_manual
= $this->contacts
['bob']['id'];
219 * Set the recipient to "Activity Assignee".
221 public function recipientIsActivityAssignee() {
222 $this->schedule
->limit_to
= 1;
223 $this->schedule
->recipient
= 1;
224 $this->schedule
->recipient_listing
= NULL;
225 $this->schedule
->recipient_manual
= NULL;
229 * Set the recipient to "Activity Source".
231 public function recipientIsActivitySource() {
232 $this->schedule
->limit_to
= 1;
233 $this->schedule
->recipient
= 2;
234 $this->schedule
->recipient_listing
= NULL;
235 $this->schedule
->recipient_manual
= NULL;