Merge pull request #13152 from civicrm/5.8
[civicrm-core.git] / tests / phpunit / CRM / Contribute / ActionMapping / ByTypeTest.php
CommitLineData
14d24938
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
14d24938 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
14d24938
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
0eea664b 28/**
a6c57fee
TO
29 * Class CRM_Contribute_ActionMapping_ByTypeTest
30 * @group ActionSchedule
31 *
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.
35 *
36 * @see \Civi\ActionSchedule\AbstractMappingTest
acb109b7 37 * @group headless
0eea664b 38 */
14d24938
TO
39class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\AbstractMappingTest {
40
41 /**
42 * Generate a list of test cases, where each is a distinct combination of
43 * data, schedule-rules, and schedule results.
44 *
45 * @return array
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
52 * - subject: regex
53 */
54 public function createTestCases() {
55 $cs = array();
56
cdc402cd
TO
57 // FIXME: CRM-19415: The right email content goes out, but it appears that the dates are incorrect.
58 // $cs[] = array(
59 // '2015-02-01 00:00:00',
60 // 'addAliceDues scheduleForAny startOnTime useHelloFirstName alsoRecipientBob',
61 // array(
62 // array(
63 // 'time' => '2015-02-01 00:00:00',
64 // 'to' => array('alice@example.org'),
65 // 'subject' => '/Hello, Alice.*via subject/',
66 // ),
67 // array(
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...
72 // ),
73 // ),
74 // );
a6c57fee
TO
75
76 $cs[] = array(
77 '2015-02-01 00:00:00',
78 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientBob',
79 array(),
80 );
81
82 $cs[] = array(
83 '2015-02-01 00:00:00',
84 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientAlice',
85 array(
86 array(
87 'time' => '2015-02-01 00:00:00',
88 'to' => array('alice@example.org'),
89 'subject' => '/Hello, Alice.*via subject/',
90 ),
91 ),
92 );
93
94 $cs[] = array(
95 '2015-02-01 00:00:00',
96 // 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstName',
1774b40a 97 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstNameStatus',
14d24938
TO
98 array(
99 array(
100 'time' => '2015-02-01 00:00:00',
101 'to' => array('alice@example.org'),
1774b40a 102 'subject' => '/Hello, Alice. @Completed.*via subject/',
14d24938
TO
103 ),
104 ),
105 );
106
107 $cs[] = array(
108 '2015-02-01 00:00:00',
109 'addAliceDues addBobDonation scheduleForAny startOnTime useHelloFirstName',
110 array(
111 array(
112 'time' => '2015-02-01 00:00:00',
113 'to' => array('alice@example.org'),
114 'subject' => '/Hello, Alice.*via subject/',
115 ),
116 array(
117 'time' => '2015-02-01 00:00:00',
118 'to' => array('bob@example.org'),
119 'subject' => '/Hello, Bob.*via subject/',
120 ),
121 ),
122 );
123
124 $cs[] = array(
125 '2015-02-02 00:00:00',
126 'addAliceDues addBobDonation scheduleForDonation startWeekBefore repeatTwoWeeksAfter useHelloFirstName',
127 array(
128 array(
129 'time' => '2015-01-26 00:00:00',
130 'to' => array('bob@example.org'),
131 'subject' => '/Hello, Bob.*via subject/',
132 ),
133 array(
134 'time' => '2015-02-02 00:00:00',
135 'to' => array('bob@example.org'),
136 'subject' => '/Hello, Bob.*via subject/',
137 ),
138 array(
139 'time' => '2015-02-09 00:00:00',
140 'to' => array('bob@example.org'),
141 'subject' => '/Hello, Bob.*via subject/',
142 ),
143 array(
144 'time' => '2015-02-16 00:00:00',
145 'to' => array('bob@example.org'),
146 'subject' => '/Hello, Bob.*via subject/',
147 ),
148 ),
149 );
150
151 $cs[] = array(
152 '2015-02-03 00:00:00',
153 'addAliceDues addBobDonation scheduleForSoftCreditor startWeekAfter useHelloFirstName',
154 array(
155 array(
156 'time' => '2015-02-10 00:00:00',
157 'to' => array('carol@example.org'),
158 'subject' => '/Hello, Carol.*via subject/',
159 ),
160 ),
161 );
162
163 return $cs;
164 }
165
9c2c0cdd
TO
166 /**
167 * Create a contribution record for Alice with type "Member Dues".
168 */
14d24938
TO
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',
176 'fee_amount' => '5',
177 'net_amount' => '95',
178 'source' => 'SSF',
179 'contribution_status_id' => 1,
180 'soft_credit' => array(
181 '1' => array(
182 'contact_id' => $this->contacts['carol']['id'],
183 'amount' => 50,
184 'soft_credit_type_id' => 3,
185 ),
186 ),
187 ));
188 }
189
9c2c0cdd
TO
190 /**
191 * Create a contribution record for Bob with type "Donation".
192 */
14d24938
TO
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',
200 'fee_amount' => '5',
201 'net_amount' => '145',
202 'source' => 'SSF',
203 'contribution_status_id' => 2,
204 ));
205 }
206
9c2c0cdd
TO
207 /**
208 * Schedule message delivery for contributions of type "Member Dues".
209 */
14d24938
TO
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));
215 }
216
9c2c0cdd
TO
217 /**
218 * Schedule message delivery for contributions of type "Donation".
219 */
14d24938
TO
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);
225 }
226
9c2c0cdd
TO
227 /**
228 * Schedule message delivery for any contribution, regardless of type.
229 */
14d24938
TO
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);
235 }
236
9c2c0cdd
TO
237 /**
238 * Schedule message delivery to the 'soft credit' assignee.
239 */
14d24938
TO
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));
248 }
249
1774b40a
TO
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)';
254 }
255
14d24938 256}