Commit | Line | Data |
---|---|---|
14d24938 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
14d24938 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
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 |
39 | class 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() { | |
9099cab3 | 55 | $cs = []; |
14d24938 | 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 | 75 | |
9099cab3 | 76 | $cs[] = [ |
a6c57fee TO |
77 | '2015-02-01 00:00:00', |
78 | 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientBob', | |
9099cab3 CW |
79 | [], |
80 | ]; | |
a6c57fee | 81 | |
9099cab3 | 82 | $cs[] = [ |
a6c57fee TO |
83 | '2015-02-01 00:00:00', |
84 | 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientAlice', | |
9099cab3 CW |
85 | [ |
86 | [ | |
a6c57fee | 87 | 'time' => '2015-02-01 00:00:00', |
9099cab3 | 88 | 'to' => ['alice@example.org'], |
a6c57fee | 89 | 'subject' => '/Hello, Alice.*via subject/', |
9099cab3 CW |
90 | ], |
91 | ], | |
92 | ]; | |
a6c57fee | 93 | |
9099cab3 | 94 | $cs[] = [ |
a6c57fee TO |
95 | '2015-02-01 00:00:00', |
96 | // 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstName', | |
1774b40a | 97 | 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstNameStatus', |
9099cab3 CW |
98 | [ |
99 | [ | |
14d24938 | 100 | 'time' => '2015-02-01 00:00:00', |
9099cab3 | 101 | 'to' => ['alice@example.org'], |
1774b40a | 102 | 'subject' => '/Hello, Alice. @Completed.*via subject/', |
9099cab3 CW |
103 | ], |
104 | ], | |
105 | ]; | |
14d24938 | 106 | |
9099cab3 | 107 | $cs[] = [ |
14d24938 TO |
108 | '2015-02-01 00:00:00', |
109 | 'addAliceDues addBobDonation scheduleForAny startOnTime useHelloFirstName', | |
9099cab3 CW |
110 | [ |
111 | [ | |
14d24938 | 112 | 'time' => '2015-02-01 00:00:00', |
9099cab3 | 113 | 'to' => ['alice@example.org'], |
14d24938 | 114 | 'subject' => '/Hello, Alice.*via subject/', |
9099cab3 CW |
115 | ], |
116 | [ | |
14d24938 | 117 | 'time' => '2015-02-01 00:00:00', |
9099cab3 | 118 | 'to' => ['bob@example.org'], |
14d24938 | 119 | 'subject' => '/Hello, Bob.*via subject/', |
9099cab3 CW |
120 | ], |
121 | ], | |
122 | ]; | |
14d24938 | 123 | |
9099cab3 | 124 | $cs[] = [ |
14d24938 TO |
125 | '2015-02-02 00:00:00', |
126 | 'addAliceDues addBobDonation scheduleForDonation startWeekBefore repeatTwoWeeksAfter useHelloFirstName', | |
9099cab3 CW |
127 | [ |
128 | [ | |
14d24938 | 129 | 'time' => '2015-01-26 00:00:00', |
9099cab3 | 130 | 'to' => ['bob@example.org'], |
14d24938 | 131 | 'subject' => '/Hello, Bob.*via subject/', |
9099cab3 CW |
132 | ], |
133 | [ | |
14d24938 | 134 | 'time' => '2015-02-02 00:00:00', |
9099cab3 | 135 | 'to' => ['bob@example.org'], |
14d24938 | 136 | 'subject' => '/Hello, Bob.*via subject/', |
9099cab3 CW |
137 | ], |
138 | [ | |
14d24938 | 139 | 'time' => '2015-02-09 00:00:00', |
9099cab3 | 140 | 'to' => ['bob@example.org'], |
14d24938 | 141 | 'subject' => '/Hello, Bob.*via subject/', |
9099cab3 CW |
142 | ], |
143 | [ | |
14d24938 | 144 | 'time' => '2015-02-16 00:00:00', |
9099cab3 | 145 | 'to' => ['bob@example.org'], |
14d24938 | 146 | 'subject' => '/Hello, Bob.*via subject/', |
9099cab3 CW |
147 | ], |
148 | ], | |
149 | ]; | |
14d24938 | 150 | |
9099cab3 | 151 | $cs[] = [ |
14d24938 TO |
152 | '2015-02-03 00:00:00', |
153 | 'addAliceDues addBobDonation scheduleForSoftCreditor startWeekAfter useHelloFirstName', | |
9099cab3 CW |
154 | [ |
155 | [ | |
14d24938 | 156 | 'time' => '2015-02-10 00:00:00', |
9099cab3 | 157 | 'to' => ['carol@example.org'], |
14d24938 | 158 | 'subject' => '/Hello, Carol.*via subject/', |
9099cab3 CW |
159 | ], |
160 | ], | |
161 | ]; | |
14d24938 TO |
162 | |
163 | return $cs; | |
164 | } | |
165 | ||
9c2c0cdd TO |
166 | /** |
167 | * Create a contribution record for Alice with type "Member Dues". | |
168 | */ | |
14d24938 | 169 | public function addAliceDues() { |
9099cab3 | 170 | $this->callAPISuccess('Contribution', 'create', [ |
14d24938 TO |
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, | |
9099cab3 CW |
180 | 'soft_credit' => [ |
181 | '1' => [ | |
14d24938 TO |
182 | 'contact_id' => $this->contacts['carol']['id'], |
183 | 'amount' => 50, | |
184 | 'soft_credit_type_id' => 3, | |
9099cab3 CW |
185 | ], |
186 | ], | |
187 | ]); | |
14d24938 TO |
188 | } |
189 | ||
9c2c0cdd TO |
190 | /** |
191 | * Create a contribution record for Bob with type "Donation". | |
192 | */ | |
14d24938 | 193 | public function addBobDonation() { |
9099cab3 | 194 | $this->callAPISuccess('Contribution', 'create', [ |
14d24938 TO |
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, | |
9099cab3 | 204 | ]); |
14d24938 TO |
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'; | |
9099cab3 CW |
213 | $this->schedule->entity_value = CRM_Utils_Array::implodePadded([1]); |
214 | $this->schedule->entity_status = CRM_Utils_Array::implodePadded([1]); | |
14d24938 TO |
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'; | |
9099cab3 | 223 | $this->schedule->entity_value = CRM_Utils_Array::implodePadded([2]); |
14d24938 TO |
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'; | |
9099cab3 | 247 | $this->schedule->recipient_listing = CRM_Utils_Array::implodePadded([3]); |
14d24938 TO |
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 | } |