3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
29 * Class CRM_Contribute_ActionMapping_ByTypeTest
30 * @group ActionSchedule
32 * This class tests various configurations of scheduled-reminders, with a focus on
33 * reminders for *contribution types*. It follows a design/pattern described in
34 * AbstractMappingTest.
36 * @see \Civi\ActionSchedule\AbstractMappingTest
39 class CRM_Contribute_ActionMapping_ByTypeTest
extends \Civi\ActionSchedule\AbstractMappingTest
{
42 * Generate a list of test cases, where each is a distinct combination of
43 * data, schedule-rules, and schedule results.
46 * - targetDate: string; eg "2015-02-01 00:00:01"
47 * - setupFuncs: string, space-separated list of setup functions
48 * - messages: array; each item is a message that's expected to be sent
49 * each message may include keys:
50 * - time: approximate time (give or take a few seconds)
51 * - recipients: array of emails
54 public function createTestCases() {
57 // FIXME: CRM-19415: The right email content goes out, but it appears that the dates are incorrect.
59 // '2015-02-01 00:00:00',
60 // 'addAliceDues scheduleForAny startOnTime useHelloFirstName alsoRecipientBob',
63 // 'time' => '2015-02-01 00:00:00',
64 // 'to' => array('alice@example.org'),
65 // 'subject' => '/Hello, Alice.*via subject/',
68 // 'time' => '2015-02-01 00:00:00',
69 // 'to' => array('bob@example.org'),
70 // 'subject' => '/Hello, Bob.*via subject/',
71 // // It might make more sense to get Alice's details... but path of least resistance...
77 '2015-02-01 00:00:00',
78 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientBob',
83 '2015-02-01 00:00:00',
84 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientAlice',
87 'time' => '2015-02-01 00:00:00',
88 'to' => array('alice@example.org'),
89 'subject' => '/Hello, Alice.*via subject/',
95 '2015-02-01 00:00:00',
96 // 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstName',
97 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstNameStatus',
100 'time' => '2015-02-01 00:00:00',
101 'to' => array('alice@example.org'),
102 'subject' => '/Hello, Alice. @Completed.*via subject/',
108 '2015-02-01 00:00:00',
109 'addAliceDues addBobDonation scheduleForAny startOnTime useHelloFirstName',
112 'time' => '2015-02-01 00:00:00',
113 'to' => array('alice@example.org'),
114 'subject' => '/Hello, Alice.*via subject/',
117 'time' => '2015-02-01 00:00:00',
118 'to' => array('bob@example.org'),
119 'subject' => '/Hello, Bob.*via subject/',
125 '2015-02-02 00:00:00',
126 'addAliceDues addBobDonation scheduleForDonation startWeekBefore repeatTwoWeeksAfter useHelloFirstName',
129 'time' => '2015-01-26 00:00:00',
130 'to' => array('bob@example.org'),
131 'subject' => '/Hello, Bob.*via subject/',
134 'time' => '2015-02-02 00:00:00',
135 'to' => array('bob@example.org'),
136 'subject' => '/Hello, Bob.*via subject/',
139 'time' => '2015-02-09 00:00:00',
140 'to' => array('bob@example.org'),
141 'subject' => '/Hello, Bob.*via subject/',
144 'time' => '2015-02-16 00:00:00',
145 'to' => array('bob@example.org'),
146 'subject' => '/Hello, Bob.*via subject/',
152 '2015-02-03 00:00:00',
153 'addAliceDues addBobDonation scheduleForSoftCreditor startWeekAfter useHelloFirstName',
156 'time' => '2015-02-10 00:00:00',
157 'to' => array('carol@example.org'),
158 'subject' => '/Hello, Carol.*via subject/',
167 * Create a contribution record for Alice with type "Member Dues".
169 public function addAliceDues() {
170 $this->callAPISuccess('Contribution', 'create', array(
171 'contact_id' => $this->contacts
['alice']['id'],
172 'receive_date' => date('Ymd', strtotime($this->targetDate
)),
173 'total_amount' => '100',
174 'financial_type_id' => 1,
175 'non_deductible_amount' => '10',
177 'net_amount' => '95',
179 'contribution_status_id' => 1,
180 'soft_credit' => array(
182 'contact_id' => $this->contacts
['carol']['id'],
184 'soft_credit_type_id' => 3,
191 * Create a contribution record for Bob with type "Donation".
193 public function addBobDonation() {
194 $this->callAPISuccess('Contribution', 'create', array(
195 'contact_id' => $this->contacts
['bob']['id'],
196 'receive_date' => date('Ymd', strtotime($this->targetDate
)),
197 'total_amount' => '150',
198 'financial_type_id' => 2,
199 'non_deductible_amount' => '10',
201 'net_amount' => '145',
203 'contribution_status_id' => 2,
208 * Schedule message delivery for contributions of type "Member Dues".
210 public function scheduleForDues() {
211 $this->schedule
->mapping_id
= CRM_Contribute_ActionMapping_ByType
::MAPPING_ID
;
212 $this->schedule
->start_action_date
= 'receive_date';
213 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(array(1));
214 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(array(1));
218 * Schedule message delivery for contributions of type "Donation".
220 public function scheduleForDonation() {
221 $this->schedule
->mapping_id
= CRM_Contribute_ActionMapping_ByType
::MAPPING_ID
;
222 $this->schedule
->start_action_date
= 'receive_date';
223 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(array(2));
224 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
228 * Schedule message delivery for any contribution, regardless of type.
230 public function scheduleForAny() {
231 $this->schedule
->mapping_id
= CRM_Contribute_ActionMapping_ByType
::MAPPING_ID
;
232 $this->schedule
->start_action_date
= 'receive_date';
233 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(NULL);
234 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
238 * Schedule message delivery to the 'soft credit' assignee.
240 public function scheduleForSoftCreditor() {
241 $this->schedule
->mapping_id
= CRM_Contribute_ActionMapping_ByType
::MAPPING_ID
;
242 $this->schedule
->start_action_date
= 'receive_date';
243 $this->schedule
->entity_value
= CRM_Utils_Array
::implodePadded(NULL);
244 $this->schedule
->entity_status
= CRM_Utils_Array
::implodePadded(NULL);
245 $this->schedule
->limit_to
= 1;
246 $this->schedule
->recipient
= 'soft_credit_type';
247 $this->schedule
->recipient_listing
= CRM_Utils_Array
::implodePadded(array(3));
250 public function useHelloFirstNameStatus() {
251 $this->schedule
->subject
= 'Hello, {contact.first_name}. @{contribution.status}. (via subject)';
252 $this->schedule
->body_html
= '<p>Hello, {contact.first_name}. @{contribution.status}. (via body_html)</p>';
253 $this->schedule
->body_text
= 'Hello, {contact.first_name}. @{contribution.status}. (via body_text)';