Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
e9479dcf EM |
28 | /** |
29 | * Class CRM_Core_BAO_ActionScheduleTest | |
acb109b7 | 30 | * @group headless |
e9479dcf | 31 | */ |
6a488035 | 32 | class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { |
63e9c3fd | 33 | |
6a488035 | 34 | /** |
f8c3594b | 35 | * @var CiviMailUtils |
6a488035 | 36 | */ |
567b2076 | 37 | public $mut; |
cee19268 | 38 | |
00be9182 | 39 | public function setUp() { |
6a488035 TO |
40 | parent::setUp(); |
41 | ||
42 | require_once 'CiviTest/CiviMailUtils.php'; | |
6c6e6187 | 43 | $this->mut = new CiviMailUtils($this, TRUE); |
6a488035 | 44 | |
57507ae6 | 45 | $this->fixtures['rolling_membership'] = array( |
6a488035 TO |
46 | 'membership_type_id' => array( |
47 | 'period_type' => 'rolling', | |
48 | 'duration_unit' => 'month', | |
49 | 'duration_interval' => '3', | |
50 | 'is_active' => 1, | |
51 | ), | |
52 | 'join_date' => '20120315', | |
53 | 'start_date' => '20120315', | |
54 | 'end_date' => '20120615', | |
b29be8c2 | 55 | 'is_override' => 0, |
6a488035 | 56 | ); |
4b1efa1d | 57 | |
63e9c3fd | 58 | $this->fixtures['rolling_membership_past'] = array( |
4b1efa1d | 59 | 'membership_type_id' => array( |
60 | 'period_type' => 'rolling', | |
61 | 'duration_unit' => 'month', | |
62 | 'duration_interval' => '3', | |
63 | 'is_active' => 1, | |
64 | ), | |
65 | 'join_date' => '20100310', | |
66 | 'start_date' => '20100310', | |
67 | 'end_date' => '20100610', | |
68 | 'is_override' => 'NULL', | |
69 | ); | |
d3eae6ea TO |
70 | $this->fixtures['participant'] = array( |
71 | 'event_id' => array( | |
72 | 'is_active' => 1, | |
73 | 'is_template' => 0, | |
74 | 'title' => 'Example Event', | |
75 | 'start_date' => '20120315', | |
76 | 'end_date' => '20120615', | |
77 | ), | |
78 | 'role_id' => '1', // Attendee. | |
79 | 'status_id' => '8', // No-show. | |
80 | ); | |
fe265b4e | 81 | |
db7de9c1 | 82 | $this->fixtures['phonecall'] = array( |
6a488035 TO |
83 | 'status_id' => 1, |
84 | 'activity_type_id' => 2, | |
85 | 'activity_date_time' => '20120615100000', | |
86 | 'is_current_revision' => 1, | |
87 | 'is_deleted' => 0, | |
88 | ); | |
db7de9c1 | 89 | $this->fixtures['contact'] = array( |
b29be8c2 | 90 | 'is_deceased' => 0, |
6a488035 TO |
91 | 'contact_type' => 'Individual', |
92 | 'email' => 'test-member@example.com', | |
43ceab3f | 93 | 'gender_id' => 'Female', |
6a488035 | 94 | ); |
db7de9c1 | 95 | $this->fixtures['contact_birthdate'] = array( |
43030baf AH |
96 | 'is_deceased' => 0, |
97 | 'contact_type' => 'Individual', | |
98 | 'email' => 'test-bday@example.com', | |
99 | 'birth_date' => '20050707', | |
100 | ); | |
db7de9c1 | 101 | $this->fixtures['sched_activity_1day'] = array( |
6a488035 TO |
102 | 'name' => 'One_Day_Phone_Call_Notice', |
103 | 'title' => 'One Day Phone Call Notice', | |
84a3e359 | 104 | 'limit_to' => '1', |
6a488035 TO |
105 | 'absolute_date' => NULL, |
106 | 'body_html' => '<p>1-Day (non-repeating)</p>', | |
107 | 'body_text' => '1-Day (non-repeating)', | |
108 | 'end_action' => NULL, | |
109 | 'end_date' => NULL, | |
110 | 'end_frequency_interval' => NULL, | |
111 | 'end_frequency_unit' => NULL, | |
112 | 'entity_status' => '1', | |
113 | 'entity_value' => '2', | |
114 | 'group_id' => NULL, | |
115 | 'is_active' => '1', | |
116 | 'is_repeat' => '0', | |
117 | 'mapping_id' => '1', | |
118 | 'msg_template_id' => NULL, | |
119 | 'recipient' => '2', | |
120 | 'recipient_listing' => NULL, | |
121 | 'recipient_manual' => NULL, | |
122 | 'record_activity' => NULL, | |
123 | 'repetition_frequency_interval' => NULL, | |
124 | 'repetition_frequency_unit' => NULL, | |
125 | 'start_action_condition' => 'before', | |
126 | 'start_action_date' => 'activity_date_time', | |
127 | 'start_action_offset' => '1', | |
128 | 'start_action_unit' => 'day', | |
f8c3594b | 129 | 'subject' => '1-Day (non-repeating) (about {activity.activity_type})', |
6a488035 TO |
130 | ); |
131 | $this->fixtures['sched_activity_1day_r'] = array( | |
132 | 'name' => 'One_Day_Phone_Call_Notice_R', | |
133 | 'title' => 'One Day Phone Call Notice R', | |
84a3e359 | 134 | 'limit_to' => 1, |
6a488035 TO |
135 | 'absolute_date' => NULL, |
136 | 'body_html' => '<p>1-Day (repeating)</p>', | |
137 | 'body_text' => '1-Day (repeating)', | |
138 | 'end_action' => 'after', | |
139 | 'end_date' => 'activity_date_time', | |
140 | 'end_frequency_interval' => '2', | |
141 | 'end_frequency_unit' => 'day', | |
142 | 'entity_status' => '1', | |
143 | 'entity_value' => '2', | |
144 | 'group_id' => NULL, | |
145 | 'is_active' => '1', | |
146 | 'is_repeat' => '1', | |
147 | 'mapping_id' => '1', | |
148 | 'msg_template_id' => NULL, | |
149 | 'recipient' => '2', | |
150 | 'recipient_listing' => NULL, | |
151 | 'recipient_manual' => NULL, | |
152 | 'record_activity' => NULL, | |
153 | 'repetition_frequency_interval' => '6', | |
154 | 'repetition_frequency_unit' => 'hour', | |
155 | 'start_action_condition' => 'before', | |
156 | 'start_action_date' => 'activity_date_time', | |
157 | 'start_action_offset' => '1', | |
158 | 'start_action_unit' => 'day', | |
f8c3594b | 159 | 'subject' => '1-Day (repeating) (about {activity.activity_type})', |
6a488035 | 160 | ); |
567b2076 | 161 | $this->fixtures['sched_membership_join_2week'] = array( |
6a488035 TO |
162 | 'name' => 'sched_membership_join_2week', |
163 | 'title' => 'sched_membership_join_2week', | |
164 | 'absolute_date' => '', | |
165 | 'body_html' => '<p>body sched_membership_join_2week</p>', | |
166 | 'body_text' => 'body sched_membership_join_2week', | |
167 | 'end_action' => '', | |
168 | 'end_date' => '', | |
169 | 'end_frequency_interval' => '', | |
170 | 'end_frequency_unit' => '', | |
171 | 'entity_status' => '', | |
172 | 'entity_value' => '', | |
173 | 'group_id' => '', | |
174 | 'is_active' => 1, | |
175 | 'is_repeat' => '0', | |
176 | 'mapping_id' => 4, | |
177 | 'msg_template_id' => '', | |
178 | 'recipient' => '', | |
179 | 'recipient_listing' => '', | |
180 | 'recipient_manual' => '', | |
181 | 'record_activity' => 1, | |
182 | 'repetition_frequency_interval' => '', | |
183 | 'repetition_frequency_unit' => '', | |
184 | 'start_action_condition' => 'after', | |
185 | 'start_action_date' => 'membership_join_date', | |
186 | 'start_action_offset' => '2', | |
187 | 'start_action_unit' => 'week', | |
f8c3594b | 188 | 'subject' => 'subject sched_membership_join_2week (joined {membership.join_date})', |
6a488035 | 189 | ); |
567b2076 | 190 | $this->fixtures['sched_membership_end_2week'] = array( |
6a488035 TO |
191 | 'name' => 'sched_membership_end_2week', |
192 | 'title' => 'sched_membership_end_2week', | |
193 | 'absolute_date' => '', | |
194 | 'body_html' => '<p>body sched_membership_end_2week</p>', | |
195 | 'body_text' => 'body sched_membership_end_2week', | |
196 | 'end_action' => '', | |
197 | 'end_date' => '', | |
198 | 'end_frequency_interval' => '', | |
199 | 'end_frequency_unit' => '', | |
200 | 'entity_status' => '', | |
201 | 'entity_value' => '', | |
202 | 'group_id' => '', | |
203 | 'is_active' => 1, | |
204 | 'is_repeat' => '0', | |
205 | 'mapping_id' => 4, | |
206 | 'msg_template_id' => '', | |
207 | 'recipient' => '', | |
208 | 'recipient_listing' => '', | |
209 | 'recipient_manual' => '', | |
210 | 'record_activity' => 1, | |
211 | 'repetition_frequency_interval' => '', | |
212 | 'repetition_frequency_unit' => '', | |
213 | 'start_action_condition' => 'before', | |
214 | 'start_action_date' => 'membership_end_date', | |
215 | 'start_action_offset' => '2', | |
216 | 'start_action_unit' => 'week', | |
217 | 'subject' => 'subject sched_membership_end_2week', | |
218 | ); | |
cbcb7579 | 219 | $this->fixtures['sched_on_membership_end_date'] = array( |
d2868251 | 220 | 'name' => 'sched_on_membership_end_date', |
221 | 'title' => 'sched_on_membership_end_date', | |
222 | 'body_html' => '<p>Your membership expired today</p>', | |
223 | 'body_text' => 'Your membership expired today', | |
224 | 'is_active' => 1, | |
225 | 'mapping_id' => 4, | |
226 | 'record_activity' => 1, | |
227 | 'start_action_condition' => 'after', | |
228 | 'start_action_date' => 'membership_end_date', | |
229 | 'start_action_offset' => '0', | |
230 | 'start_action_unit' => 'hour', | |
231 | 'subject' => 'subject send reminder on membership_end_date', | |
232 | ); | |
cbcb7579 | 233 | $this->fixtures['sched_after_1day_membership_end_date'] = array( |
d2868251 | 234 | 'name' => 'sched_after_1day_membership_end_date', |
235 | 'title' => 'sched_after_1day_membership_end_date', | |
236 | 'body_html' => '<p>Your membership expired yesterday</p>', | |
237 | 'body_text' => 'Your membership expired yesterday', | |
238 | 'is_active' => 1, | |
239 | 'mapping_id' => 4, | |
240 | 'record_activity' => 1, | |
241 | 'start_action_condition' => 'after', | |
242 | 'start_action_date' => 'membership_end_date', | |
243 | 'start_action_offset' => '1', | |
244 | 'start_action_unit' => 'day', | |
245 | 'subject' => 'subject send reminder on membership_end_date', | |
246 | ); | |
4b1efa1d | 247 | |
567b2076 | 248 | $this->fixtures['sched_membership_end_2month'] = array( |
4b1efa1d | 249 | 'name' => 'sched_membership_end_2month', |
250 | 'title' => 'sched_membership_end_2month', | |
251 | 'absolute_date' => '', | |
252 | 'body_html' => '<p>body sched_membership_end_2month</p>', | |
253 | 'body_text' => 'body sched_membership_end_2month', | |
254 | 'end_action' => '', | |
255 | 'end_date' => '', | |
256 | 'end_frequency_interval' => '', | |
257 | 'end_frequency_unit' => '', | |
258 | 'entity_status' => '', | |
259 | 'entity_value' => '', | |
260 | 'group_id' => '', | |
261 | 'is_active' => 1, | |
262 | 'is_repeat' => '0', | |
263 | 'mapping_id' => 4, | |
264 | 'msg_template_id' => '', | |
265 | 'recipient' => '', | |
266 | 'recipient_listing' => '', | |
267 | 'recipient_manual' => '', | |
268 | 'record_activity' => 1, | |
269 | 'repetition_frequency_interval' => '', | |
270 | 'repetition_frequency_unit' => '', | |
271 | 'start_action_condition' => 'after', | |
272 | 'start_action_date' => 'membership_end_date', | |
273 | 'start_action_offset' => '2', | |
274 | 'start_action_unit' => 'month', | |
275 | 'subject' => 'subject sched_membership_end_2month', | |
276 | ); | |
277 | ||
567b2076 | 278 | $this->fixtures['sched_contact_bday_yesterday'] = array( |
43030baf AH |
279 | 'name' => 'sched_contact_bday_yesterday', |
280 | 'title' => 'sched_contact_bday_yesterday', | |
281 | 'absolute_date' => '', | |
282 | 'body_html' => '<p>you look like you were born yesterday!</p>', | |
283 | 'body_text' => 'you look like you were born yesterday!', | |
284 | 'end_action' => '', | |
285 | 'end_date' => '', | |
286 | 'end_frequency_interval' => '', | |
287 | 'end_frequency_unit' => '', | |
288 | 'entity_status' => 1, | |
289 | 'entity_value' => 'birth_date', | |
290 | 'group_id' => '', | |
291 | 'is_active' => 1, | |
292 | 'is_repeat' => '0', | |
293 | 'mapping_id' => 6, | |
294 | 'msg_template_id' => '', | |
295 | 'recipient' => '', | |
296 | 'recipient_listing' => '', | |
297 | 'recipient_manual' => '', | |
298 | 'record_activity' => 1, | |
299 | 'repetition_frequency_interval' => '', | |
300 | 'repetition_frequency_unit' => '', | |
301 | 'start_action_condition' => 'after', | |
302 | 'start_action_date' => 'date_field', | |
303 | 'start_action_offset' => '1', | |
304 | 'start_action_unit' => 'day', | |
305 | 'subject' => 'subject sched_contact_bday_yesterday', | |
306 | ); | |
307 | ||
567b2076 | 308 | $this->fixtures['sched_contact_bday_anniv'] = array( |
43030baf AH |
309 | 'name' => 'sched_contact_bday_anniv', |
310 | 'title' => 'sched_contact_bday_anniv', | |
311 | 'absolute_date' => '', | |
312 | 'body_html' => '<p>happy birthday!</p>', | |
313 | 'body_text' => 'happy birthday!', | |
314 | 'end_action' => '', | |
315 | 'end_date' => '', | |
316 | 'end_frequency_interval' => '', | |
317 | 'end_frequency_unit' => '', | |
318 | 'entity_status' => 2, | |
319 | 'entity_value' => 'birth_date', | |
320 | 'group_id' => '', | |
321 | 'is_active' => 1, | |
322 | 'is_repeat' => '0', | |
323 | 'mapping_id' => 6, | |
324 | 'msg_template_id' => '', | |
325 | 'recipient' => '', | |
326 | 'recipient_listing' => '', | |
327 | 'recipient_manual' => '', | |
328 | 'record_activity' => 1, | |
329 | 'repetition_frequency_interval' => '', | |
330 | 'repetition_frequency_unit' => '', | |
331 | 'start_action_condition' => 'before', | |
332 | 'start_action_date' => 'date_field', | |
333 | 'start_action_offset' => '1', | |
334 | 'start_action_unit' => 'day', | |
335 | 'subject' => 'subject sched_contact_bday_anniv', | |
336 | ); | |
337 | ||
567b2076 | 338 | $this->fixtures['sched_contact_grad_tomorrow'] = array( |
43030baf AH |
339 | 'name' => 'sched_contact_grad_tomorrow', |
340 | 'title' => 'sched_contact_grad_tomorrow', | |
341 | 'absolute_date' => '', | |
342 | 'body_html' => '<p>congratulations on your graduation!</p>', | |
343 | 'body_text' => 'congratulations on your graduation!', | |
344 | 'end_action' => '', | |
345 | 'end_date' => '', | |
346 | 'end_frequency_interval' => '', | |
347 | 'end_frequency_unit' => '', | |
348 | 'entity_status' => 1, | |
349 | 'group_id' => '', | |
350 | 'is_active' => 1, | |
351 | 'is_repeat' => '0', | |
352 | 'mapping_id' => 6, | |
353 | 'msg_template_id' => '', | |
354 | 'recipient' => '', | |
355 | 'recipient_listing' => '', | |
356 | 'recipient_manual' => '', | |
357 | 'record_activity' => 1, | |
358 | 'repetition_frequency_interval' => '', | |
359 | 'repetition_frequency_unit' => '', | |
360 | 'start_action_condition' => 'before', | |
361 | 'start_action_date' => 'date_field', | |
362 | 'start_action_offset' => '1', | |
363 | 'start_action_unit' => 'day', | |
364 | 'subject' => 'subject sched_contact_grad_tomorrow', | |
365 | ); | |
366 | ||
567b2076 | 367 | $this->fixtures['sched_contact_grad_anniv'] = array( |
43030baf AH |
368 | 'name' => 'sched_contact_grad_anniv', |
369 | 'title' => 'sched_contact_grad_anniv', | |
370 | 'absolute_date' => '', | |
371 | 'body_html' => '<p>dear alum, please send us money.</p>', | |
372 | 'body_text' => 'dear alum, please send us money.', | |
373 | 'end_action' => '', | |
374 | 'end_date' => '', | |
375 | 'end_frequency_interval' => '', | |
376 | 'end_frequency_unit' => '', | |
377 | 'entity_status' => 2, | |
378 | 'group_id' => '', | |
379 | 'is_active' => 1, | |
380 | 'is_repeat' => '0', | |
381 | 'mapping_id' => 6, | |
382 | 'msg_template_id' => '', | |
383 | 'recipient' => '', | |
384 | 'recipient_listing' => '', | |
385 | 'recipient_manual' => '', | |
386 | 'record_activity' => 1, | |
387 | 'repetition_frequency_interval' => '', | |
388 | 'repetition_frequency_unit' => '', | |
389 | 'start_action_condition' => 'after', | |
390 | 'start_action_date' => 'date_field', | |
391 | 'start_action_offset' => '1', | |
392 | 'start_action_unit' => 'week', | |
393 | 'subject' => 'subject sched_contact_grad_anniv', | |
394 | ); | |
4aff0253 AH |
395 | |
396 | $this->fixtures['sched_contact_created_yesterday'] = array( | |
397 | 'name' => 'sched_contact_created_yesterday', | |
398 | 'title' => 'sched_contact_created_yesterday', | |
399 | 'absolute_date' => '', | |
400 | 'body_html' => '<p>Your contact was created yesterday</p>', | |
401 | 'body_text' => 'Your contact was created yesterday!', | |
402 | 'end_action' => '', | |
403 | 'end_date' => '', | |
404 | 'end_frequency_interval' => '', | |
405 | 'end_frequency_unit' => '', | |
406 | 'entity_status' => 1, | |
407 | 'entity_value' => 'created_date', | |
408 | 'group_id' => '', | |
409 | 'is_active' => 1, | |
410 | 'is_repeat' => '0', | |
411 | 'mapping_id' => 6, | |
412 | 'msg_template_id' => '', | |
413 | 'recipient' => '', | |
414 | 'recipient_listing' => '', | |
415 | 'recipient_manual' => '', | |
416 | 'record_activity' => 1, | |
417 | 'repetition_frequency_interval' => '', | |
418 | 'repetition_frequency_unit' => '', | |
419 | 'start_action_condition' => 'after', | |
420 | 'start_action_date' => 'date_field', | |
421 | 'start_action_offset' => '1', | |
422 | 'start_action_unit' => 'day', | |
423 | 'subject' => 'subject sched_contact_created_yesterday', | |
424 | ); | |
425 | ||
426 | $this->fixtures['sched_contact_mod_anniv'] = array( | |
427 | 'name' => 'sched_contact_mod_anniv', | |
428 | 'title' => 'sched_contact_mod_anniv', | |
429 | 'absolute_date' => '', | |
430 | 'body_html' => '<p>You last updated your data last year</p>', | |
431 | 'body_text' => 'Go update your stuff!', | |
432 | 'end_action' => '', | |
433 | 'end_date' => '', | |
434 | 'end_frequency_interval' => '', | |
435 | 'end_frequency_unit' => '', | |
436 | 'entity_status' => 2, | |
437 | 'entity_value' => 'modified_date', | |
438 | 'group_id' => '', | |
439 | 'is_active' => 1, | |
440 | 'is_repeat' => '0', | |
441 | 'mapping_id' => 6, | |
442 | 'msg_template_id' => '', | |
443 | 'recipient' => '', | |
444 | 'recipient_listing' => '', | |
445 | 'recipient_manual' => '', | |
446 | 'record_activity' => 1, | |
447 | 'repetition_frequency_interval' => '', | |
448 | 'repetition_frequency_unit' => '', | |
449 | 'start_action_condition' => 'before', | |
450 | 'start_action_date' => 'date_field', | |
451 | 'start_action_offset' => '1', | |
452 | 'start_action_unit' => 'day', | |
453 | 'subject' => 'subject sched_contact_mod_anniv', | |
454 | ); | |
455 | ||
d3eae6ea TO |
456 | $this->fixtures['sched_eventtype_start_1week_before'] = array( |
457 | 'name' => 'sched_eventtype_start_1week_before', | |
458 | 'title' => 'sched_eventtype_start_1week_before', | |
459 | 'absolute_date' => '', | |
460 | 'body_html' => '<p>body sched_eventtype_start_1week_before ({event.title})</p>', | |
461 | 'body_text' => 'body sched_eventtype_start_1week_before ({event.title})', | |
462 | 'end_action' => '', | |
463 | 'end_date' => '', | |
464 | 'end_frequency_interval' => '', | |
465 | 'end_frequency_unit' => '', | |
466 | 'entity_status' => '', // participant status id | |
467 | 'entity_value' => '', // event type id | |
468 | 'group_id' => '', | |
469 | 'is_active' => 1, | |
470 | 'is_repeat' => '0', | |
471 | 'mapping_id' => 2, // event type | |
472 | 'msg_template_id' => '', | |
473 | 'recipient' => '', | |
474 | 'recipient_listing' => '', | |
475 | 'recipient_manual' => '', | |
476 | 'record_activity' => 1, | |
477 | 'repetition_frequency_interval' => '', | |
478 | 'repetition_frequency_unit' => '', | |
479 | 'start_action_condition' => 'before', | |
480 | 'start_action_date' => 'event_start_date', | |
481 | 'start_action_offset' => '1', | |
482 | 'start_action_unit' => 'week', | |
483 | 'subject' => 'subject sched_eventtype_start_1week_before ({event.title})', | |
484 | ); | |
485 | $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'] = array( | |
486 | 'name' => 'sched_eventtype_end_2month_repeat_twice_2_weeks', | |
487 | 'title' => 'sched_eventtype_end_2month_repeat_twice_2_weeks', | |
488 | 'absolute_date' => '', | |
489 | 'body_html' => '<p>body sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}</p>', | |
490 | 'body_text' => 'body sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}', | |
491 | 'end_action' => 'after', | |
492 | 'end_date' => 'event_end_date', | |
493 | 'end_frequency_interval' => '3', | |
494 | 'end_frequency_unit' => 'month', | |
495 | 'entity_status' => '', // participant status id | |
496 | 'entity_value' => '', // event type id | |
497 | 'group_id' => '', | |
498 | 'is_active' => 1, | |
499 | 'is_repeat' => '1', | |
500 | 'mapping_id' => 2, // event type | |
501 | 'msg_template_id' => '', | |
502 | 'recipient' => '', | |
503 | 'recipient_listing' => '', | |
504 | 'recipient_manual' => '', | |
505 | 'record_activity' => 1, | |
506 | 'repetition_frequency_interval' => '2', | |
507 | 'repetition_frequency_unit' => 'week', | |
508 | 'start_action_condition' => 'after', | |
509 | 'start_action_date' => 'event_end_date', | |
510 | 'start_action_offset' => '2', | |
511 | 'start_action_unit' => 'month', | |
512 | 'subject' => 'subject sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}', | |
513 | ); | |
514 | ||
567b2076 | 515 | $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'] = array( |
861d11c4 DG |
516 | 'name' => 'sched_membership_end_2month', |
517 | 'title' => 'sched_membership_end_2month', | |
518 | 'absolute_date' => '', | |
519 | 'body_html' => '<p>body sched_membership_end_2month</p>', | |
520 | 'body_text' => 'body sched_membership_end_2month', | |
521 | 'end_action' => '', | |
5c4d6559 | 522 | 'end_date' => 'membership_end_date', |
861d11c4 DG |
523 | 'end_frequency_interval' => '4', |
524 | 'end_frequency_unit' => 'month', | |
525 | 'entity_status' => '', | |
526 | 'entity_value' => '', | |
527 | 'group_id' => '', | |
528 | 'is_active' => 1, | |
529 | 'is_repeat' => '1', | |
530 | 'mapping_id' => 4, | |
531 | 'msg_template_id' => '', | |
532 | 'recipient' => '', | |
533 | 'recipient_listing' => '', | |
534 | 'recipient_manual' => '', | |
535 | 'record_activity' => 1, | |
536 | 'repetition_frequency_interval' => '4', | |
537 | 'repetition_frequency_unit' => 'week', | |
538 | 'start_action_condition' => 'after', | |
539 | 'start_action_date' => 'membership_end_date', | |
540 | 'start_action_offset' => '2', | |
541 | 'start_action_unit' => 'month', | |
542 | 'subject' => 'subject sched_membership_end_2month', | |
543 | ); | |
567b2076 | 544 | $this->fixtures['sched_membership_end_limit_to_none'] = array( |
baa85770 EM |
545 | 'name' => 'limit to none', |
546 | 'title' => 'limit to none', | |
547 | 'absolute_date' => '', | |
548 | 'body_html' => '<p>body sched_membership_end_2month</p>', | |
549 | 'body_text' => 'body sched_membership_end_2month', | |
550 | 'end_action' => '', | |
551 | 'end_date' => '', | |
552 | 'end_frequency_interval' => '4', | |
553 | 'end_frequency_unit' => 'month', | |
554 | 'entity_status' => '', | |
555 | 'entity_value' => '', | |
556 | 'limit_to' => 0, | |
557 | 'group_id' => '', | |
558 | 'is_active' => 1, | |
559 | 'is_repeat' => '1', | |
560 | 'mapping_id' => 4, | |
561 | 'msg_template_id' => '', | |
562 | 'recipient' => '', | |
563 | 'recipient_listing' => '', | |
564 | 'recipient_manual' => '', | |
565 | 'record_activity' => 1, | |
566 | 'repetition_frequency_interval' => '4', | |
567 | 'repetition_frequency_unit' => 'week', | |
568 | 'start_action_condition' => 'after', | |
569 | 'start_action_date' => 'membership_end_date', | |
570 | 'start_action_offset' => '2', | |
571 | 'start_action_unit' => 'month', | |
572 | 'subject' => 'limit to none', | |
573 | ); | |
52f09320 PH |
574 | $this->fixtures['sched_on_membership_end_date_repeat_interval'] = array( |
575 | 'name' => 'sched_on_membership_end_date', | |
576 | 'title' => 'sched_on_membership_end_date', | |
577 | 'body_html' => '<p>Your membership expired 1 unit ago</p>', | |
578 | 'body_text' => 'Your membership expired 1 unit ago', | |
579 | 'end_frequency_interval' => 10, | |
580 | 'end_frequency_unit' => 'year', | |
581 | 'is_active' => 1, | |
582 | 'is_repeat' => TRUE, | |
583 | 'mapping_id' => 4, | |
584 | 'record_activity' => 1, | |
585 | 'start_action_condition' => 'after', | |
586 | 'start_action_date' => 'membership_end_date', | |
587 | 'start_action_offset' => '0', | |
588 | 'start_action_unit' => 'hour', | |
589 | 'subject' => 'subject send reminder every unit after membership_end_date', | |
590 | ); | |
591 | ||
6a488035 | 592 | $this->_setUp(); |
6a488035 TO |
593 | } |
594 | ||
595 | /** | |
596 | * Tears down the fixture, for example, closes a network connection. | |
92c99a4a | 597 | * |
6a488035 | 598 | * This method is called after a test is executed. |
6a488035 | 599 | */ |
00be9182 | 600 | public function tearDown() { |
6a488035 TO |
601 | parent::tearDown(); |
602 | ||
603 | $this->mut->clearMessages(); | |
604 | $this->mut->stop(); | |
605 | unset($this->mut); | |
92c99a4a EM |
606 | $this->quickCleanup(array( |
607 | 'civicrm_action_schedule', | |
608 | 'civicrm_action_log', | |
609 | 'civicrm_membership', | |
d3eae6ea TO |
610 | 'civicrm_participant', |
611 | 'civicrm_event', | |
92c99a4a EM |
612 | 'civicrm_email', |
613 | )); | |
6a488035 TO |
614 | $this->_tearDown(); |
615 | } | |
616 | ||
43ceab3f TO |
617 | public function mailerExamples() { |
618 | $cases = array(); | |
619 | ||
620 | $manyTokensTmpl = implode(';;', array( | |
621 | '{contact.display_name}', // basic contact token | |
622 | '{contact.gender}', // funny legacy contact token | |
623 | '{contact.gender_id}', // funny legacy contact token | |
624 | '{domain.name}', // domain token | |
625 | '{activity.activity_type}', // action-scheduler token | |
626 | )); | |
ccdf6bd5 TO |
627 | // Note: The behavior of domain-tokens on a scheduled reminder is undefined. All we |
628 | // can really do is check that it has something. | |
629 | $manyTokensExpected = 'test-member@example.com;;Female;;Female;;[a-zA-Z0-9 ]+;;Phone Call'; | |
43ceab3f TO |
630 | |
631 | // In this example, we use a lot of tokens cutting across multiple components.. | |
632 | $cases[0] = array( | |
633 | // Schedule definition. | |
634 | array( | |
635 | 'subject' => "subj $manyTokensTmpl", | |
636 | 'body_html' => "html $manyTokensTmpl", | |
637 | 'body_text' => "text $manyTokensTmpl", | |
638 | ), | |
639 | // Assertions (regex). | |
640 | array( | |
641 | 'from_name' => "/^FIXME\$/", | |
642 | 'from_email' => "/^info@EXAMPLE.ORG\$/", | |
643 | 'subject' => "/^subj $manyTokensExpected\$/", | |
644 | 'body_html' => "/^html $manyTokensExpected\$/", | |
645 | 'body_text' => "/^text $manyTokensExpected\$/", | |
646 | ), | |
647 | ); | |
648 | ||
649 | // In this example, we customize the from address. | |
650 | $cases[1] = array( | |
651 | // Schedule definition. | |
652 | array( | |
653 | 'from_name' => 'Bob', | |
654 | 'from_email' => 'bob@example.org', | |
655 | ), | |
656 | // Assertions (regex). | |
657 | array( | |
658 | 'from_name' => "/^Bob\$/", | |
659 | 'from_email' => "/^bob@example.org\$/", | |
660 | ), | |
661 | ); | |
662 | ||
663 | // In this example, we autoconvert HTML to text | |
664 | $cases[2] = array( | |
665 | // Schedule definition. | |
666 | array( | |
667 | 'body_html' => '<p>Hello & stuff.</p>', | |
668 | 'body_text' => '', | |
669 | ), | |
670 | // Assertions (regex). | |
671 | array( | |
672 | 'body_html' => '/^' . preg_quote('<p>Hello & stuff.</p>', '/') . '/', | |
673 | 'body_text' => '/^' . preg_quote('Hello & stuff.', '/') . '/', | |
674 | ), | |
675 | ); | |
676 | ||
677 | // In this example, we autoconvert HTML to text | |
678 | $cases[3] = array( | |
679 | // Schedule definition. | |
680 | array( | |
681 | 'body_html' => '', | |
682 | 'body_text' => 'Hello world', | |
683 | ), | |
684 | // Assertions (regex). | |
685 | array( | |
686 | 'body_html' => '/^--UNDEFINED--$/', | |
687 | 'body_text' => '/^Hello world$/', | |
688 | ), | |
689 | ); | |
690 | ||
691 | return $cases; | |
692 | } | |
693 | ||
694 | /** | |
695 | * This generates a single mailing through the scheduled-reminder | |
696 | * system (using an activity-reminder as a baseline) and | |
697 | * checks that the resulting message satisfies various | |
698 | * regular expressions. | |
699 | * | |
700 | * @param array $schedule | |
701 | * Values to set/override in the schedule. | |
702 | * Ex: array('subject' => 'Hello, {contact.first_name}!'). | |
703 | * @param array $patterns | |
704 | * A list of regexes to compare with the actual email. | |
705 | * Ex: array('subject' => '/^Hello, Alice!/'). | |
706 | * Keys: subject, body_text, body_html, from_name, from_email. | |
707 | * @dataProvider mailerExamples | |
708 | */ | |
709 | public function testMailer($schedule, $patterns) { | |
710 | $actionSchedule = array_merge($this->fixtures['sched_activity_1day'], $schedule); | |
711 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
712 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
713 | ||
714 | $activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phonecall']); | |
715 | $this->assertTrue(is_numeric($activity->id)); | |
716 | $contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']); | |
717 | $activity->save(); | |
718 | ||
719 | $source['contact_id'] = $contact['id']; | |
720 | $source['activity_id'] = $activity->id; | |
721 | $source['record_type_id'] = 2; | |
722 | $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source); | |
723 | $activityContact->save(); | |
724 | ||
725 | CRM_Utils_Time::setTime('2012-06-14 15:00:00'); | |
726 | $this->callAPISuccess('job', 'send_reminder', array()); | |
727 | $this->mut->assertRecipients(array(array('test-member@example.com'))); | |
728 | foreach ($this->mut->getAllMessages('ezc') as $message) { | |
729 | /** @var ezcMail $message */ | |
730 | ||
731 | $messageArray = array(); | |
732 | $messageArray['subject'] = $message->subject; | |
733 | $messageArray['from_name'] = $message->from->name; | |
734 | $messageArray['from_email'] = $message->from->email; | |
735 | $messageArray['body_text'] = '--UNDEFINED--'; | |
736 | $messageArray['body_html'] = '--UNDEFINED--'; | |
737 | ||
738 | foreach ($message->fetchParts() as $part) { | |
739 | /** @var ezcMailText ezcMailText */ | |
740 | if ($part instanceof ezcMailText && $part->subType == 'html') { | |
741 | $messageArray['body_html'] = $part->text; | |
742 | } | |
743 | if ($part instanceof ezcMailText && $part->subType == 'plain') { | |
744 | $messageArray['body_text'] = $part->text; | |
745 | } | |
746 | } | |
747 | ||
748 | foreach ($patterns as $field => $pattern) { | |
749 | $this->assertRegExp($pattern, $messageArray[$field], | |
750 | "Check that '$field'' matches regex. " . print_r(array('expected' => $patterns, 'actual' => $messageArray), 1)); | |
751 | } | |
752 | } | |
753 | $this->mut->clearMessages(); | |
754 | ||
755 | } | |
756 | ||
92c99a4a | 757 | public function testActivityDateTimeMatchNonRepeatableSchedule() { |
cee19268 | 758 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($this->fixtures['sched_activity_1day']); |
6a488035 TO |
759 | $this->assertTrue(is_numeric($actionScheduleDao->id)); |
760 | ||
761 | $activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phonecall']); | |
6a488035 | 762 | $this->assertTrue(is_numeric($activity->id)); |
6c6e6187 | 763 | $contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']); |
6a488035 TO |
764 | $activity->save(); |
765 | ||
4f20f356 | 766 | $source['contact_id'] = $contact['id']; |
767 | $source['activity_id'] = $activity->id; | |
768 | $source['record_type_id'] = 2; | |
769 | $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source); | |
770 | $activityContact->save(); | |
771 | ||
6a488035 | 772 | $this->assertCronRuns(array( |
567b2076 EM |
773 | array( |
774 | // Before the 24-hour mark, no email | |
6a488035 TO |
775 | 'time' => '2012-06-14 04:00:00', |
776 | 'recipients' => array(), | |
f8c3594b | 777 | 'subjects' => array(), |
6a488035 | 778 | ), |
567b2076 EM |
779 | array( |
780 | // After the 24-hour mark, an email | |
6a488035 TO |
781 | 'time' => '2012-06-14 15:00:00', |
782 | 'recipients' => array(array('test-member@example.com')), | |
f8c3594b | 783 | 'subjects' => array('1-Day (non-repeating) (about Phone Call)'), |
6a488035 | 784 | ), |
567b2076 EM |
785 | array( |
786 | // Run cron again; message already sent | |
6a488035 TO |
787 | 'time' => '', |
788 | 'recipients' => array(), | |
789 | ), | |
790 | )); | |
791 | } | |
792 | ||
92c99a4a | 793 | public function testActivityDateTimeMatchRepeatableSchedule() { |
cee19268 | 794 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($this->fixtures['sched_activity_1day_r']); |
6a488035 TO |
795 | $this->assertTrue(is_numeric($actionScheduleDao->id)); |
796 | ||
797 | $activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phonecall']); | |
798 | $this->assertTrue(is_numeric($activity->id)); | |
6c6e6187 | 799 | $contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']); |
6a488035 TO |
800 | $activity->save(); |
801 | ||
4f20f356 | 802 | $source['contact_id'] = $contact['id']; |
803 | $source['activity_id'] = $activity->id; | |
6c6e6187 | 804 | $source['record_type_id'] = 2; |
4f20f356 | 805 | $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source); |
806 | $activityContact->save(); | |
807 | ||
6a488035 | 808 | $this->assertCronRuns(array( |
567b2076 EM |
809 | array( |
810 | // Before the 24-hour mark, no email | |
6a488035 TO |
811 | 'time' => '012-06-14 04:00:00', |
812 | 'recipients' => array(), | |
f8c3594b | 813 | 'subjects' => array(), |
6a488035 | 814 | ), |
567b2076 EM |
815 | array( |
816 | // After the 24-hour mark, an email | |
6a488035 TO |
817 | 'time' => '2012-06-14 15:00:00', |
818 | 'recipients' => array(array('test-member@example.com')), | |
f8c3594b | 819 | 'subjects' => array('1-Day (repeating) (about Phone Call)'), |
6a488035 | 820 | ), |
567b2076 EM |
821 | array( |
822 | // Run cron 4 hours later; first message already sent | |
6a488035 TO |
823 | 'time' => '2012-06-14 20:00:00', |
824 | 'recipients' => array(), | |
f8c3594b | 825 | 'subjects' => array(), |
6a488035 | 826 | ), |
567b2076 EM |
827 | array( |
828 | // Run cron 6 hours later; send second message. | |
6a488035 TO |
829 | 'time' => '2012-06-14 21:00:01', |
830 | 'recipients' => array(array('test-member@example.com')), | |
f8c3594b | 831 | 'subjects' => array('1-Day (repeating) (about Phone Call)'), |
6a488035 TO |
832 | ), |
833 | )); | |
834 | } | |
835 | ||
836 | /** | |
837 | * For contacts/activities which don't match the schedule filter, | |
838 | * an email should *not* be sent. | |
839 | */ | |
840 | // TODO // function testActivityDateTime_NonMatch() { } | |
841 | ||
842 | /** | |
843 | * For contacts/members which match schedule based on join date, | |
844 | * an email should be sent. | |
845 | */ | |
92c99a4a | 846 | public function testMembershipJoinDateMatch() { |
b29be8c2 | 847 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 1))); |
6a488035 | 848 | $this->assertTrue(is_numeric($membership->id)); |
bf308d29 | 849 | $result = $this->callAPISuccess('Email', 'create', array( |
6a488035 TO |
850 | 'contact_id' => $membership->contact_id, |
851 | 'email' => 'test-member@example.com', | |
852 | 'location_type_id' => 1, | |
92915c55 | 853 | )); |
6a488035 TO |
854 | $this->assertAPISuccess($result); |
855 | ||
bf308d29 | 856 | $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); |
6a488035 TO |
857 | $actionSchedule = $this->fixtures['sched_membership_join_2week']; |
858 | $actionSchedule['entity_value'] = $membership->membership_type_id; | |
cee19268 | 859 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); |
6a488035 TO |
860 | $this->assertTrue(is_numeric($actionScheduleDao->id)); |
861 | ||
862 | // start_date=2012-03-15 ; schedule is 2 weeks after start_date | |
863 | $this->assertCronRuns(array( | |
567b2076 EM |
864 | array( |
865 | // Before the 2-week mark, no email. | |
6a488035 TO |
866 | 'time' => '2012-03-28 01:00:00', |
867 | 'recipients' => array(), | |
f8c3594b | 868 | 'subjects' => array(), |
6a488035 | 869 | ), |
567b2076 EM |
870 | array( |
871 | // After the 2-week mark, send an email. | |
6a488035 TO |
872 | 'time' => '2012-03-29 01:00:00', |
873 | 'recipients' => array(array('test-member@example.com')), | |
f8c3594b | 874 | 'subjects' => array('subject sched_membership_join_2week (joined March 15th, 2012)'), |
6a488035 TO |
875 | ), |
876 | )); | |
877 | } | |
878 | ||
879 | /** | |
442cf836 EM |
880 | * Test end date email sent. |
881 | * | |
6a488035 TO |
882 | * For contacts/members which match schedule based on join date, |
883 | * an email should be sent. | |
884 | */ | |
92c99a4a | 885 | public function testMembershipJoinDateNonMatch() { |
6a488035 TO |
886 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', $this->fixtures['rolling_membership']); |
887 | $this->assertTrue(is_numeric($membership->id)); | |
bf308d29 | 888 | $result = $this->callAPISuccess('Email', 'create', array( |
6a488035 TO |
889 | 'contact_id' => $membership->contact_id, |
890 | 'location_type_id' => 1, | |
891 | 'email' => 'test-member@example.com', | |
6a488035 | 892 | )); |
fe265b4e | 893 | |
6a488035 TO |
894 | // Add an alternative membership type, and only send messages for that type |
895 | $extraMembershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', array()); | |
896 | $this->assertTrue(is_numeric($extraMembershipType->id)); | |
cee19268 | 897 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($this->fixtures['sched_membership_join_2week']); |
6a488035 TO |
898 | $this->assertTrue(is_numeric($actionScheduleDao->id)); |
899 | $actionScheduleDao->entity_value = $extraMembershipType->id; | |
900 | $actionScheduleDao->save(); | |
901 | ||
902 | // start_date=2012-03-15 ; schedule is 2 weeks after start_date | |
903 | $this->assertCronRuns(array( | |
567b2076 EM |
904 | array( |
905 | // After the 2-week mark, don't send email because we have different membership type. | |
6a488035 TO |
906 | 'time' => '2012-03-29 01:00:00', |
907 | 'recipients' => array(), | |
908 | ), | |
909 | )); | |
910 | } | |
911 | ||
861d11c4 | 912 | /** |
442cf836 | 913 | * Test that the first and SECOND notifications are sent out. |
861d11c4 | 914 | */ |
92c99a4a | 915 | public function testMembershipEndDateRepeat() { |
861d11c4 DG |
916 | // creates membership with end_date = 20120615 |
917 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); | |
918 | $result = $this->callAPISuccess('Email', 'create', array( | |
919 | 'contact_id' => $membership->contact_id, | |
920 | 'email' => 'test-member@example.com', | |
921 | )); | |
922 | $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); | |
923 | ||
924 | $actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks']; | |
925 | $actionSchedule['entity_value'] = $membership->membership_type_id; | |
926 | $this->callAPISuccess('action_schedule', 'create', $actionSchedule); | |
927 | ||
928 | // end_date=2012-06-15 ; schedule is 2 weeks before end_date | |
929 | $this->assertCronRuns(array( | |
567b2076 EM |
930 | array( |
931 | // After the 2-week mark, send an email. | |
861d11c4 DG |
932 | 'time' => '2012-08-15 01:00:00', |
933 | 'recipients' => array(array('test-member@example.com')), | |
934 | ), | |
567b2076 EM |
935 | array( |
936 | // After the 2-week mark, send an email. | |
861d11c4 DG |
937 | 'time' => '2012-09-12 01:00:00', |
938 | 'recipients' => array(array('test-member@example.com')), | |
939 | ), | |
940 | )); | |
941 | } | |
942 | ||
943 | /** | |
442cf836 EM |
944 | * Test behaviour when date changes. |
945 | * | |
861d11c4 DG |
946 | * Test that the first notification is sent but the second is NOT sent if the end date changes in |
947 | * between | |
948 | * see CRM-15376 | |
949 | */ | |
92c99a4a | 950 | public function testMembershipEndDateRepeatChangedEndDate_CRM_15376() { |
861d11c4 DG |
951 | // creates membership with end_date = 20120615 |
952 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); | |
953 | $this->callAPISuccess('Email', 'create', array( | |
954 | 'contact_id' => $membership->contact_id, | |
955 | 'email' => 'test-member@example.com', | |
956 | )); | |
957 | $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); | |
958 | ||
959 | $actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks']; | |
960 | $actionSchedule['entity_value'] = $membership->membership_type_id; | |
961 | $this->callAPISuccess('action_schedule', 'create', $actionSchedule); | |
962 | // end_date=2012-06-15 ; schedule is 2 weeks before end_date | |
963 | $this->assertCronRuns(array( | |
567b2076 EM |
964 | array( |
965 | // After the 2-week mark, send an email. | |
861d11c4 DG |
966 | 'time' => '2012-08-15 01:00:00', |
967 | 'recipients' => array(array('test-member@example.com')), | |
968 | ), | |
969 | )); | |
970 | ||
442cf836 | 971 | // Extend membership - reminder should NOT go out. |
861d11c4 DG |
972 | $this->callAPISuccess('membership', 'create', array('id' => $membership->id, 'end_date' => '2014-01-01')); |
973 | $this->assertCronRuns(array( | |
442cf836 EM |
974 | array( |
975 | // After the 2-week mark, send an email. | |
861d11c4 DG |
976 | 'time' => '2012-09-12 01:00:00', |
977 | 'recipients' => array(), | |
978 | ), | |
979 | )); | |
980 | } | |
981 | ||
6a488035 | 982 | /** |
442cf836 EM |
983 | * Test membership end date email sends. |
984 | * | |
6a488035 TO |
985 | * For contacts/members which match schedule based on end date, |
986 | * an email should be sent. | |
987 | */ | |
92c99a4a | 988 | public function testMembershipEndDateMatch() { |
6a488035 | 989 | // creates membership with end_date = 20120615 |
b29be8c2 | 990 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); |
6a488035 | 991 | $this->assertTrue(is_numeric($membership->id)); |
bf308d29 | 992 | $this->callAPISuccess('Email', 'create', array( |
6a488035 TO |
993 | 'contact_id' => $membership->contact_id, |
994 | 'email' => 'test-member@example.com', | |
92915c55 | 995 | )); |
bf308d29 | 996 | $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); |
6a488035 TO |
997 | |
998 | $actionSchedule = $this->fixtures['sched_membership_end_2week']; | |
999 | $actionSchedule['entity_value'] = $membership->membership_type_id; | |
cee19268 | 1000 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); |
6a488035 TO |
1001 | $this->assertTrue(is_numeric($actionScheduleDao->id)); |
1002 | ||
1003 | // end_date=2012-06-15 ; schedule is 2 weeks before end_date | |
1004 | $this->assertCronRuns(array( | |
442cf836 EM |
1005 | array( |
1006 | // Before the 2-week mark, no email. | |
6a488035 | 1007 | 'time' => '2012-05-31 01:00:00', |
442cf836 EM |
1008 | // 'time' => '2012-06-01 01:00:00', |
1009 | // FIXME: Is this the right boundary? | |
6a488035 TO |
1010 | 'recipients' => array(), |
1011 | ), | |
442cf836 EM |
1012 | array( |
1013 | // After the 2-week mark, send an email. | |
6a488035 TO |
1014 | 'time' => '2012-06-01 01:00:00', |
1015 | 'recipients' => array(array('test-member@example.com')), | |
1016 | ), | |
1017 | )); | |
d2868251 | 1018 | |
1019 | // Now suppose user has renewed for rolling membership after 3 months, so upcoming assertion is written | |
1020 | // to ensure that new reminder is sent 2 week before the new end_date i.e. '2012-09-15' | |
1021 | $membership->end_date = '2012-09-15'; | |
1022 | $membership->save(); | |
1023 | ||
1024 | //change the email id of chosen membership contact to assert | |
1025 | //recipient of not the previously sent mail but the new one | |
1026 | $result = $this->callAPISuccess('Email', 'create', array( | |
1027 | 'is_primary' => 1, | |
1028 | 'contact_id' => $membership->contact_id, | |
cbcb7579 | 1029 | 'email' => 'member2@example.com', |
d2868251 | 1030 | )); |
1031 | $this->assertAPISuccess($result); | |
1032 | ||
1033 | // end_date=2012-09-15 ; schedule is 2 weeks before end_date | |
1034 | $this->assertCronRuns(array( | |
cbcb7579 TO |
1035 | array( |
1036 | // Before the 2-week mark, no email | |
d2868251 | 1037 | 'time' => '2012-08-31 01:00:00', |
1038 | 'recipients' => array(), | |
cbcb7579 TO |
1039 | ), |
1040 | //array( // After the 2-week mark, send an email | |
1041 | //'time' => '2012-09-01 01:00:00', | |
1042 | //'recipients' => array(array('member2@example.com')), | |
1043 | //), | |
d2868251 | 1044 | )); |
6a488035 TO |
1045 | } |
1046 | ||
4b1efa1d | 1047 | |
1048 | /** | |
442cf836 EM |
1049 | * Test membership end date email. |
1050 | * | |
6c6e6187 TO |
1051 | * For contacts/members which match schedule based on end date, |
1052 | * an email should be sent. | |
1053 | */ | |
92c99a4a | 1054 | public function testMembershipEndDateNoMatch() { |
4b1efa1d | 1055 | // creates membership with end_date = 20120615 |
5c4d6559 | 1056 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 3))); |
4b1efa1d | 1057 | $this->assertTrue(is_numeric($membership->id)); |
6c6e6187 | 1058 | $result = $this->callAPISuccess('Email', 'create', array( |
4b1efa1d | 1059 | 'contact_id' => $membership->contact_id, |
1060 | 'email' => 'test-member@example.com', | |
4b1efa1d | 1061 | )); |
bf308d29 | 1062 | $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); |
4b1efa1d | 1063 | |
1064 | $actionSchedule = $this->fixtures['sched_membership_end_2month']; | |
1065 | $actionSchedule['entity_value'] = $membership->membership_type_id; | |
cee19268 | 1066 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); |
4b1efa1d | 1067 | $this->assertTrue(is_numeric($actionScheduleDao->id)); |
1068 | ||
1069 | // end_date=2012-06-15 ; schedule is 2 weeks before end_date | |
1070 | $this->assertCronRuns(array( | |
442cf836 EM |
1071 | array( |
1072 | // Before the 2-week mark, no email. | |
4b1efa1d | 1073 | 'time' => '2012-05-31 01:00:00', |
442cf836 EM |
1074 | // 'time' => '2012-06-01 01:00:00', |
1075 | // FIXME: Is this the right boundary? | |
4b1efa1d | 1076 | 'recipients' => array(), |
1077 | ), | |
442cf836 EM |
1078 | array( |
1079 | // After the 2-week mark, send an email. | |
4b1efa1d | 1080 | 'time' => '2013-05-01 01:00:00', |
1081 | 'recipients' => array(), | |
1082 | ), | |
1083 | )); | |
1084 | } | |
1085 | ||
92c99a4a | 1086 | public function testContactBirthDateNoAnniv() { |
bf308d29 | 1087 | $contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']); |
43030baf AH |
1088 | $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; |
1089 | $actionSchedule = $this->fixtures['sched_contact_bday_yesterday']; | |
1090 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1091 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1092 | $this->assertCronRuns(array( | |
442cf836 EM |
1093 | array( |
1094 | // On the birthday, no email. | |
43030baf AH |
1095 | 'time' => '2005-07-07 01:00:00', |
1096 | 'recipients' => array(), | |
1097 | ), | |
442cf836 EM |
1098 | array( |
1099 | // The next day, send an email. | |
43030baf AH |
1100 | 'time' => '2005-07-08 20:00:00', |
1101 | 'recipients' => array(array('test-bday@example.com')), | |
1102 | ), | |
1103 | )); | |
1104 | } | |
1105 | ||
92c99a4a | 1106 | public function testContactBirthDateAnniversary() { |
6c6e6187 | 1107 | $contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']); |
43030baf AH |
1108 | $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; |
1109 | $actionSchedule = $this->fixtures['sched_contact_bday_anniv']; | |
1110 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1111 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1112 | $this->assertCronRuns(array( | |
92c99a4a EM |
1113 | array( |
1114 | // On some random day, no email. | |
43030baf AH |
1115 | 'time' => '2014-03-07 01:00:00', |
1116 | 'recipients' => array(), | |
1117 | ), | |
92c99a4a EM |
1118 | array( |
1119 | // On the eve of their 9th birthday, send an email. | |
43030baf AH |
1120 | 'time' => '2014-07-06 20:00:00', |
1121 | 'recipients' => array(array('test-bday@example.com')), | |
1122 | ), | |
1123 | )); | |
1124 | } | |
4b1efa1d | 1125 | |
92c99a4a | 1126 | public function testContactCustomDateNoAnniv() { |
43030baf AH |
1127 | $group = array( |
1128 | 'title' => 'Test_Group', | |
1129 | 'name' => 'test_group', | |
1130 | 'extends' => array('Individual'), | |
1131 | 'style' => 'Inline', | |
6c6e6187 | 1132 | 'is_multiple' => FALSE, |
43030baf | 1133 | 'is_active' => 1, |
43030baf | 1134 | ); |
bf308d29 | 1135 | $createGroup = $this->callAPISuccess('custom_group', 'create', $group); |
43030baf | 1136 | $field = array( |
43030baf AH |
1137 | 'label' => 'Graduation', |
1138 | 'data_type' => 'Date', | |
1139 | 'html_type' => 'Select Date', | |
1140 | 'custom_group_id' => $createGroup['id'], | |
1141 | ); | |
bf308d29 | 1142 | $createField = $this->callAPISuccess('custom_field', 'create', $field); |
43030baf AH |
1143 | $contactParams = $this->fixtures['contact']; |
1144 | $contactParams["custom_{$createField['id']}"] = '2013-12-16'; | |
bf308d29 | 1145 | $contact = $this->callAPISuccess('Contact', 'create', $contactParams); |
43030baf AH |
1146 | $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; |
1147 | $actionSchedule = $this->fixtures['sched_contact_grad_tomorrow']; | |
1148 | $actionSchedule['entity_value'] = "custom_{$createField['id']}"; | |
1149 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1150 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1151 | $this->assertCronRuns(array( | |
92c99a4a EM |
1152 | array( |
1153 | // On some random day, no email. | |
43030baf AH |
1154 | 'time' => '2014-03-07 01:00:00', |
1155 | 'recipients' => array(), | |
1156 | ), | |
92c99a4a EM |
1157 | array( |
1158 | // On the eve of their graduation, send an email. | |
43030baf AH |
1159 | 'time' => '2013-12-15 20:00:00', |
1160 | 'recipients' => array(array('test-member@example.com')), | |
1161 | ), | |
1162 | )); | |
6c6e6187 | 1163 | $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id'])); |
43030baf | 1164 | } |
92915c55 | 1165 | |
4aff0253 AH |
1166 | public function testContactCreatedNoAnniv() { |
1167 | $contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']); | |
1168 | $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; | |
1169 | $actionSchedule = $this->fixtures['sched_contact_created_yesterday']; | |
1170 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1171 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1172 | $this->assertCronRuns(array( | |
1173 | array( | |
1174 | // On the date created, no email. | |
1175 | 'time' => $contact['values'][$contact['id']]['created_date'], | |
1176 | 'recipients' => array(), | |
1177 | ), | |
1178 | array( | |
1179 | // The next day, send an email. | |
1180 | 'time' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['created_date'] . ' +1 day')), | |
1181 | 'recipients' => array(array('test-bday@example.com')), | |
1182 | ), | |
1183 | )); | |
1184 | } | |
1185 | ||
1186 | public function testContactModifiedAnniversary() { | |
1187 | $contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']); | |
1188 | $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; | |
688bd604 | 1189 | $modifiedDate = $this->callAPISuccess('Contact', 'getvalue', array('id' => $contact['id'], 'return' => 'modified_date')); |
4aff0253 AH |
1190 | $actionSchedule = $this->fixtures['sched_contact_mod_anniv']; |
1191 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1192 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1193 | $this->assertCronRuns(array( | |
1194 | array( | |
1195 | // On some random day, no email. | |
a9ac9f6c | 1196 | 'time' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['modified_date'] . ' -60 days')), |
4aff0253 AH |
1197 | 'recipients' => array(), |
1198 | ), | |
1199 | array( | |
1200 | // On the eve of 3 years after they were modified, send an email. | |
688bd604 | 1201 | 'time' => date('Y-m-d H:i:s', strtotime($modifiedDate . ' +3 years -1 day')), |
4aff0253 AH |
1202 | 'recipients' => array(array('test-bday@example.com')), |
1203 | ), | |
1204 | )); | |
1205 | } | |
1206 | ||
baa85770 | 1207 | /** |
92c99a4a | 1208 | * Check that limit_to + an empty recipients doesn't sent to multiple contacts. |
baa85770 | 1209 | */ |
00be9182 | 1210 | public function testMembershipLimitToNone() { |
baa85770 EM |
1211 | // creates membership with end_date = 20120615 |
1212 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); | |
1213 | ||
1214 | $this->assertTrue(is_numeric($membership->id)); | |
1215 | $result = $this->callAPISuccess('Email', 'create', array( | |
1216 | 'contact_id' => $membership->contact_id, | |
1217 | 'email' => 'member@example.com', | |
1218 | )); | |
1219 | $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); | |
1220 | $this->callAPISuccess('contact', 'create', array('email' => 'b@c.com', 'contact_type' => 'Individual')); | |
1221 | ||
1222 | $this->assertAPISuccess($result); | |
1223 | ||
1224 | $actionSchedule = $this->fixtures['sched_membership_end_limit_to_none']; | |
1225 | $actionSchedule['entity_value'] = $membership->membership_type_id; | |
1226 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1227 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1228 | ||
1229 | // end_date=2012-06-15 ; schedule is 2 weeks before end_date | |
1230 | $this->assertCronRuns(array( | |
92c99a4a EM |
1231 | array( |
1232 | // Before the 2-week mark, no email. | |
baa85770 EM |
1233 | 'time' => '2012-05-31 01:00:00', |
1234 | // 'time' => '2012-06-01 01:00:00', // FIXME: Is this the right boundary? | |
1235 | 'recipients' => array(), | |
1236 | ), | |
1237 | )); | |
1238 | } | |
1239 | ||
cbcb7579 | 1240 | public function testMembership_referenceDate() { |
5c4d6559 | 1241 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); |
1242 | ||
1243 | $this->assertTrue(is_numeric($membership->id)); | |
1244 | $result = $this->callAPISuccess('Email', 'create', array( | |
1245 | 'contact_id' => $membership->contact_id, | |
1246 | 'email' => 'member@example.com', | |
1247 | )); | |
1248 | ||
1249 | $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); | |
1250 | $this->assertAPISuccess($result); | |
1251 | ||
1252 | $actionSchedule = $this->fixtures['sched_membership_join_2week']; | |
1253 | $actionSchedule['entity_value'] = $membership->membership_type_id; | |
1254 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1255 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1256 | ||
1257 | // start_date=2012-03-15 ; schedule is 2 weeks after start_date | |
1258 | $this->assertCronRuns(array( | |
cbcb7579 TO |
1259 | array( |
1260 | // After the 2-week mark, send an email | |
5c4d6559 | 1261 | 'time' => '2012-03-29 01:00:00', |
1262 | 'recipients' => array(array('member@example.com')), | |
9c0fe051 | 1263 | ), |
cbcb7579 TO |
1264 | array( |
1265 | // After the 2-week 1day mark, don't send an email | |
9c0fe051 | 1266 | 'time' => '2012-03-30 01:00:00', |
1267 | 'recipients' => array(), | |
1268 | ), | |
5c4d6559 | 1269 | )); |
1270 | ||
1271 | //check if reference date is set to membership's join date | |
1272 | //as per the action_start_date chosen for current schedule reminder | |
1273 | $this->assertEquals('2012-03-15', | |
1274 | CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionLog', $membership->contact_id, 'reference_date', 'contact_id') | |
1275 | ); | |
1276 | ||
e7c6a902 | 1277 | //change current membership join date that may signifies as membership renewal activity |
5c4d6559 | 1278 | $membership->join_date = '2012-03-29'; |
1279 | $membership->save(); | |
1280 | ||
5c4d6559 | 1281 | $this->assertCronRuns(array( |
cbcb7579 TO |
1282 | array( |
1283 | // After the 13 days of the changed join date 2012-03-29, don't send an email | |
9c0fe051 | 1284 | 'time' => '2012-04-11 01:00:00', |
cbcb7579 TO |
1285 | 'recipients' => array(), |
1286 | ), | |
1287 | array( | |
1288 | // After the 2-week of the changed join date 2012-03-29, send an email | |
5c4d6559 | 1289 | 'time' => '2012-04-12 01:00:00', |
cbcb7579 | 1290 | 'recipients' => array(array('member@example.com')), |
5c4d6559 | 1291 | ), |
1292 | )); | |
7d48c97b | 1293 | $this->assertCronRuns(array( |
1294 | array( | |
1295 | // It should not re-send on the same day | |
1296 | 'time' => '2012-04-12 01:00:00', | |
1297 | 'recipients' => array(array()), | |
1298 | ), | |
1299 | )); | |
5c4d6559 | 1300 | } |
baa85770 | 1301 | |
d2868251 | 1302 | public function testMembershipOnMultipleReminder() { |
1303 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); | |
d2868251 | 1304 | |
1305 | $this->assertTrue(is_numeric($membership->id)); | |
1306 | $result = $this->callAPISuccess('Email', 'create', array( | |
1307 | 'contact_id' => $membership->contact_id, | |
1308 | 'email' => 'member@example.com', | |
1309 | )); | |
cbcb7579 | 1310 | $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); |
d2868251 | 1311 | $this->assertAPISuccess($result); |
1312 | ||
1313 | $actionScheduleBefore = $this->fixtures['sched_membership_end_2week']; // Send email 2 weeks before end_date | |
1314 | $actionScheduleOn = $this->fixtures['sched_on_membership_end_date']; // Send email on end_date/expiry date | |
1315 | $actionScheduleAfter = $this->fixtures['sched_after_1day_membership_end_date']; // Send email 1 day after end_date/grace period | |
1316 | $actionScheduleBefore['entity_value'] = $actionScheduleOn['entity_value'] = $actionScheduleAfter['entity_value'] = $membership->membership_type_id; | |
1317 | foreach (array('actionScheduleBefore', 'actionScheduleOn', 'actionScheduleAfter') as $value) { | |
1318 | $$value = CRM_Core_BAO_ActionSchedule::add($$value); | |
1319 | $this->assertTrue(is_numeric($$value->id)); | |
1320 | } | |
1321 | ||
1322 | $this->assertCronRuns( | |
1323 | array( | |
cbcb7579 TO |
1324 | array( |
1325 | // 1day 2weeks before membership end date(MED), don't send mail | |
d2868251 | 1326 | 'time' => '2012-05-31 01:00:00', |
1327 | 'recipients' => array(), | |
1328 | ), | |
cbcb7579 TO |
1329 | array( |
1330 | // 2 weeks before MED, send an email | |
d2868251 | 1331 | 'time' => '2012-06-01 01:00:00', |
1332 | 'recipients' => array(array('member@example.com')), | |
1333 | ), | |
cbcb7579 TO |
1334 | array( |
1335 | // 1day before MED, don't send mail | |
d2868251 | 1336 | 'time' => '2012-06-14 01:00:00', |
1337 | 'recipients' => array(), | |
1338 | ), | |
cbcb7579 TO |
1339 | array( |
1340 | // On MED, send an email | |
d2868251 | 1341 | 'time' => '2012-06-15 00:00:00', |
1342 | 'recipients' => array(array('member@example.com')), | |
1343 | ), | |
cbcb7579 TO |
1344 | array( |
1345 | // After 1day of MED, send an email | |
d2868251 | 1346 | 'time' => '2012-06-16 01:00:00', |
1347 | 'recipients' => array(array('member@example.com')), | |
1348 | ), | |
cbcb7579 TO |
1349 | array( |
1350 | // After 1day 1min of MED, don't send an email | |
d2868251 | 1351 | 'time' => '2012-06-17 00:01:00', |
1352 | 'recipients' => array(), | |
1353 | ), | |
cbcb7579 TO |
1354 | ) |
1355 | ); | |
d2868251 | 1356 | |
1357 | // Assert the timestamp as of when the emails of respective three reminders as configured | |
1358 | // 2 weeks before, on and 1 day after MED, are sent | |
f42ab010 TO |
1359 | $this->assertApproxEquals( |
1360 | strtotime('2012-06-01 01:00:00'), | |
1361 | strtotime(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionLog', $actionScheduleBefore->id, 'action_date_time', 'action_schedule_id', TRUE)), | |
1362 | 3 // Variation in test execution time. | |
1363 | ); | |
1364 | $this->assertApproxEquals( | |
1365 | strtotime('2012-06-15 00:00:00'), | |
1366 | strtotime(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionLog', $actionScheduleOn->id, 'action_date_time', 'action_schedule_id', TRUE)), | |
1367 | 3 // Variation in test execution time. | |
1368 | ); | |
1369 | $this->assertApproxEquals( | |
1370 | strtotime('2012-06-16 01:00:00'), | |
1371 | strtotime(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionLog', $actionScheduleAfter->id, 'action_date_time', 'action_schedule_id', TRUE)), | |
1372 | 3 // Variation in test execution time. | |
1373 | ); | |
d2868251 | 1374 | |
e7c6a902 | 1375 | //extend MED to 2 weeks after the current MED (that may signifies as membership renewal activity) |
d2868251 | 1376 | // and lets assert as of when the new set of reminders will be sent against their respective Schedule Reminders(SR) |
9c0fe051 | 1377 | $membership->end_date = '2012-06-20'; |
d2868251 | 1378 | $membership->save(); |
d2868251 | 1379 | |
9c0fe051 | 1380 | $result = $this->callAPISuccess('Contact', 'get', array('id' => $membership->contact_id)); |
d2868251 | 1381 | $this->assertCronRuns( |
1382 | array( | |
cbcb7579 TO |
1383 | array( |
1384 | // 1day 2weeks before membership end date(MED), don't send mail | |
9c0fe051 | 1385 | 'time' => '2012-06-05 01:00:00', |
d2868251 | 1386 | 'recipients' => array(), |
1387 | ), | |
cbcb7579 TO |
1388 | array( |
1389 | // 2 weeks before MED, send an email | |
9c0fe051 | 1390 | 'time' => '2012-06-06 01:00:00', |
1391 | 'recipients' => array(array('member@example.com')), | |
d2868251 | 1392 | ), |
cbcb7579 TO |
1393 | array( |
1394 | // 1day before MED, don't send mail | |
9c0fe051 | 1395 | 'time' => '2012-06-19 01:00:00', |
d2868251 | 1396 | 'recipients' => array(), |
1397 | ), | |
cbcb7579 TO |
1398 | array( |
1399 | // On MED, send an email | |
9c0fe051 | 1400 | 'time' => '2012-06-20 00:00:00', |
d2868251 | 1401 | 'recipients' => array(array('member@example.com')), |
1402 | ), | |
cbcb7579 TO |
1403 | array( |
1404 | // After 1day of MED, send an email | |
9c0fe051 | 1405 | 'time' => '2012-06-21 01:00:00', |
d2868251 | 1406 | 'recipients' => array(array('member@example.com')), |
1407 | ), | |
cbcb7579 TO |
1408 | array( |
1409 | // After 1day 1min of MED, don't send an email | |
9c0fe051 | 1410 | 'time' => '2012-07-21 00:01:00', |
d2868251 | 1411 | 'recipients' => array(), |
1412 | ), | |
d2868251 | 1413 | )); |
1414 | } | |
1415 | ||
1416 | public function testContactCustomDate_Anniv() { | |
43030baf AH |
1417 | $group = array( |
1418 | 'title' => 'Test_Group now', | |
1419 | 'name' => 'test_group_now', | |
1420 | 'extends' => array('Individual'), | |
1421 | 'style' => 'Inline', | |
6c6e6187 | 1422 | 'is_multiple' => FALSE, |
43030baf | 1423 | 'is_active' => 1, |
43030baf | 1424 | ); |
bf308d29 | 1425 | $createGroup = $this->callAPISuccess('custom_group', 'create', $group); |
43030baf | 1426 | $field = array( |
43030baf AH |
1427 | 'label' => 'Graduation', |
1428 | 'data_type' => 'Date', | |
1429 | 'html_type' => 'Select Date', | |
1430 | 'custom_group_id' => $createGroup['id'], | |
1431 | ); | |
bf308d29 EM |
1432 | $createField = $this->callAPISuccess('custom_field', 'create', $field); |
1433 | ||
43030baf AH |
1434 | $contactParams = $this->fixtures['contact']; |
1435 | $contactParams["custom_{$createField['id']}"] = '2013-12-16'; | |
bf308d29 | 1436 | $contact = $this->callAPISuccess('Contact', 'create', $contactParams); |
43030baf AH |
1437 | $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; |
1438 | $actionSchedule = $this->fixtures['sched_contact_grad_anniv']; | |
1439 | $actionSchedule['entity_value'] = "custom_{$createField['id']}"; | |
1440 | $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); | |
1441 | $this->assertTrue(is_numeric($actionScheduleDao->id)); | |
1442 | $this->assertCronRuns(array( | |
92c99a4a EM |
1443 | array( |
1444 | // On some random day, no email. | |
43030baf AH |
1445 | 'time' => '2014-03-07 01:00:00', |
1446 | 'recipients' => array(), | |
1447 | ), | |
92c99a4a EM |
1448 | array( |
1449 | // A week after their 5th anniversary of graduation, send an email. | |
43030baf AH |
1450 | 'time' => '2018-12-23 20:00:00', |
1451 | 'recipients' => array(array('test-member@example.com')), | |
1452 | ), | |
1453 | )); | |
6c6e6187 | 1454 | $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id'])); |
43030baf | 1455 | } |
4b1efa1d | 1456 | |
d3eae6ea TO |
1457 | public function testEventTypeStartDate() { |
1458 | // Create event+participant with start_date = 20120315, end_date = 20120615. | |
1459 | $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 2))); | |
1460 | $this->callAPISuccess('Email', 'create', array( | |
1461 | 'contact_id' => $participant->contact_id, | |
1462 | 'email' => 'test-event@example.com', | |
1463 | )); | |
1464 | $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id))); | |
1465 | ||
1466 | $actionSchedule = $this->fixtures['sched_eventtype_start_1week_before']; | |
1467 | $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id'); | |
1468 | $this->callAPISuccess('action_schedule', 'create', $actionSchedule); | |
1469 | ||
1470 | //echo "CREATED\n"; ob_flush(); sleep(20); | |
1471 | ||
1472 | // end_date=2012-06-15 ; schedule is 2 weeks before end_date | |
1473 | $this->assertCronRuns(array( | |
1474 | array( | |
1475 | // 2 weeks before | |
1476 | 'time' => '2012-03-02 01:00:00', | |
1477 | 'recipients' => array(), | |
1478 | ), | |
1479 | array( | |
1480 | // 1 week before | |
1481 | 'time' => '2012-03-08 01:00:00', | |
1482 | 'recipients' => array(array('test-event@example.com')), | |
1483 | ), | |
1484 | array( | |
1485 | // And then nothing else | |
1486 | 'time' => '2012-03-16 01:00:00', | |
1487 | 'recipients' => array(), | |
1488 | ), | |
1489 | )); | |
1490 | } | |
1491 | ||
1492 | public function testEventTypeEndDateRepeat() { | |
1493 | // Create event+participant with start_date = 20120315, end_date = 20120615. | |
1494 | $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 2))); | |
1495 | $this->callAPISuccess('Email', 'create', array( | |
1496 | 'contact_id' => $participant->contact_id, | |
1497 | 'email' => 'test-event@example.com', | |
1498 | )); | |
1499 | $c = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id))); | |
1500 | ||
1501 | $actionSchedule = $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks']; | |
1502 | $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id'); | |
1503 | $this->callAPISuccess('action_schedule', 'create', $actionSchedule); | |
1504 | ||
1505 | $this->assertCronRuns(array( | |
1506 | array( | |
1507 | // Almost 2 months. | |
1508 | 'time' => '2012-08-13 01:00:00', | |
1509 | 'recipients' => array(), | |
1510 | ), | |
1511 | array( | |
1512 | // After the 2-month mark, send an email. | |
1513 | 'time' => '2012-08-16 01:00:00', | |
1514 | 'recipients' => array(array('test-event@example.com')), | |
1515 | ), | |
1516 | array( | |
1517 | // After 2 months and 1 week, don't repeat yet. | |
1518 | 'time' => '2012-08-23 02:00:00', | |
1519 | 'recipients' => array(), | |
1520 | ), | |
1521 | array( | |
1522 | // After 2 months and 2 weeks | |
1523 | 'time' => '2012-08-30 02:00:00', | |
1524 | 'recipients' => array(array('test-event@example.com')), | |
1525 | ), | |
1526 | array( | |
1527 | // After 2 months and 4 week | |
1528 | 'time' => '2012-09-13 02:00:00', | |
1529 | 'recipients' => array(array('test-event@example.com')), | |
1530 | ), | |
1531 | array( | |
1532 | // After 2 months and 6 weeks | |
1533 | 'time' => '2012-09-27 01:00:00', | |
1534 | 'recipients' => array(), | |
1535 | ), | |
1536 | )); | |
1537 | } | |
1538 | ||
6a488035 TO |
1539 | // TODO // function testMembershipEndDate_NonMatch() { } |
1540 | // TODO // function testEventTypeStartDate_Match() { } | |
1541 | // TODO // function testEventTypeEndDate_Match() { } | |
1542 | // TODO // function testEventNameStartDate_Match() { } | |
1543 | // TODO // function testEventNameEndDate_Match() { } | |
1544 | ||
1545 | /** | |
92c99a4a | 1546 | * Run a series of cron jobs and make an assertion about email deliveries. |
6a488035 | 1547 | * |
16b10e64 CW |
1548 | * @param array $cronRuns |
1549 | * array specifying when to run cron and what messages to expect; each item is an array with keys: | |
1550 | * - time: string, e.g. '2012-06-15 21:00:01' | |
1551 | * - recipients: array(array(string)), list of email addresses which should receive messages | |
6a488035 | 1552 | */ |
00be9182 | 1553 | public function assertCronRuns($cronRuns) { |
6a488035 TO |
1554 | foreach ($cronRuns as $cronRun) { |
1555 | CRM_Utils_Time::setTime($cronRun['time']); | |
bf308d29 | 1556 | $this->callAPISuccess('job', 'send_reminder', array()); |
6a488035 | 1557 | $this->mut->assertRecipients($cronRun['recipients']); |
f8c3594b TO |
1558 | if (array_key_exists('subjects', $cronRun)) { |
1559 | $this->mut->assertSubjects($cronRun['subjects']); | |
1560 | } | |
6a488035 TO |
1561 | $this->mut->clearMessages(); |
1562 | } | |
1563 | } | |
1564 | ||
6a488035 TO |
1565 | /** |
1566 | * @var array(DAO_Name => array(int)) List of items to garbage-collect during tearDown | |
1567 | */ | |
1568 | private $_testObjects; | |
1569 | ||
1570 | /** | |
1571 | * Sets up the fixture, for example, opens a network connection. | |
92c99a4a | 1572 | * |
6a488035 | 1573 | * This method is called before a test is executed. |
6a488035 TO |
1574 | */ |
1575 | protected function _setUp() { | |
1576 | $this->_testObjects = array(); | |
1577 | } | |
1578 | ||
1579 | /** | |
1580 | * Tears down the fixture, for example, closes a network connection. | |
92c99a4a | 1581 | * |
6a488035 | 1582 | * This method is called after a test is executed. |
6a488035 TO |
1583 | */ |
1584 | protected function _tearDown() { | |
1585 | parent::tearDown(); | |
1586 | $this->deleteTestObjects(); | |
1587 | } | |
1588 | ||
1589 | /** | |
1590 | * This is a wrapper for CRM_Core_DAO::createTestObject which tracks | |
92c99a4a | 1591 | * created entities and provides for brainless cleanup. |
6a488035 TO |
1592 | * |
1593 | * @see CRM_Core_DAO::createTestObject | |
92c99a4a | 1594 | * |
1e1fdcf6 EM |
1595 | * @param $daoName |
1596 | * @param array $params | |
1597 | * @param int $numObjects | |
1598 | * @param bool $createOnly | |
92c99a4a EM |
1599 | * |
1600 | * @return array|NULL|object | |
6a488035 | 1601 | */ |
2da40d21 | 1602 | public function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE) { |
6a488035 TO |
1603 | $objects = CRM_Core_DAO::createTestObject($daoName, $params, $numObjects, $createOnly); |
1604 | if (is_array($objects)) { | |
1605 | $this->registerTestObjects($objects); | |
0db6c3e1 TO |
1606 | } |
1607 | else { | |
6a488035 TO |
1608 | $this->registerTestObjects(array($objects)); |
1609 | } | |
1610 | return $objects; | |
1611 | } | |
1612 | ||
1613 | /** | |
5a4f6742 CW |
1614 | * @param array $objects |
1615 | * DAO or BAO objects. | |
6a488035 | 1616 | */ |
00be9182 | 1617 | public function registerTestObjects($objects) { |
6a488035 TO |
1618 | //if (is_object($objects)) { |
1619 | // $objects = array($objects); | |
1620 | //} | |
1621 | foreach ($objects as $object) { | |
1622 | $daoName = preg_replace('/_BAO_/', '_DAO_', get_class($object)); | |
1623 | $this->_testObjects[$daoName][] = $object->id; | |
1624 | } | |
1625 | } | |
1626 | ||
00be9182 | 1627 | public function deleteTestObjects() { |
6a488035 TO |
1628 | // Note: You might argue that the FK relations between test |
1629 | // objects could make this problematic; however, it should | |
1630 | // behave intuitively as long as we mentally split our | |
1631 | // test-objects between the "manual/primary records" | |
1632 | // and the "automatic/secondary records" | |
1633 | foreach ($this->_testObjects as $daoName => $daoIds) { | |
1634 | foreach ($daoIds as $daoId) { | |
1635 | CRM_Core_DAO::deleteTestObjects($daoName, array('id' => $daoId)); | |
1636 | } | |
1637 | } | |
1638 | $this->_testObjects = array(); | |
1639 | } | |
1640 | ||
52f09320 PH |
1641 | /** |
1642 | * Test that the various repetition units work correctly. | |
1643 | * CRM-17028 | |
1644 | */ | |
1645 | public function testRepetitionFrequencyUnit() { | |
1646 | $membershipTypeParams = array( | |
1647 | 'duration_interval' => '1', | |
1648 | 'duration_unit' => 'year', | |
1649 | 'is_active' => 1, | |
1650 | 'period_type' => 'rolling', | |
1651 | ); | |
1652 | $membershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', $membershipTypeParams); | |
1653 | $interval_units = array('hour', 'day', 'week', 'month', 'year'); | |
1654 | foreach ($interval_units as $interval_unit) { | |
1655 | $membershipEndDate = DateTime::createFromFormat('Y-m-d H:i:s', "2013-03-15 00:00:00"); | |
1656 | $contactParams = array( | |
1657 | 'contact_type' => 'Individual', | |
1658 | 'first_name' => 'Test', | |
1659 | 'last_name' => "Interval $interval_unit", | |
1660 | 'is_deceased' => 0, | |
1661 | ); | |
1662 | $contact = $this->createTestObject('CRM_Contact_DAO_Contact', $contactParams); | |
1663 | $this->assertTrue(is_numeric($contact->id)); | |
1664 | $emailParams = array( | |
1665 | 'contact_id' => $contact->id, | |
1666 | 'email' => "test-member-{$interval_unit}@example.com", | |
1667 | 'location_type_id' => 1, | |
1668 | ); | |
1669 | $email = $this->createTestObject('CRM_Core_DAO_Email', $emailParams); | |
1670 | $this->assertTrue(is_numeric($email->id)); | |
1671 | $membershipParams = array( | |
1672 | 'membership_type_id' => $membershipType->id, | |
1673 | 'contact_id' => $contact->id, | |
1674 | 'join_date' => '20120315', | |
1675 | 'start_date' => '20120315', | |
1676 | 'end_date' => '20130315', | |
1677 | 'is_override' => 0, | |
1678 | 'status_id' => 2, | |
1679 | ); | |
1680 | $membershipParams['status-id'] = 1; | |
1681 | $membership = $this->createTestObject('CRM_Member_DAO_Membership', $membershipParams); | |
1682 | $actionScheduleParams = $this->fixtures['sched_on_membership_end_date_repeat_interval']; | |
1683 | $actionScheduleParams['entity_value'] = $membershipType->id; | |
1684 | $actionScheduleParams['repetition_frequency_unit'] = $interval_unit; | |
1685 | $actionScheduleParams['repetition_frequency_interval'] = 2; | |
1686 | $actionSchedule = CRM_Core_BAO_ActionSchedule::add($actionScheduleParams); | |
1687 | $this->assertTrue(is_numeric($actionSchedule->id)); | |
1688 | $beforeEndDate = $this->createModifiedDateTime($membershipEndDate, '-1 day'); | |
1689 | $beforeFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+1 $interval_unit"); | |
1690 | $afterFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+2 $interval_unit"); | |
1691 | $cronRuns = array( | |
1692 | array( | |
1693 | 'time' => $beforeEndDate->format('Y-m-d H:i:s'), | |
1694 | 'recipients' => array(), | |
1695 | ), | |
1696 | array( | |
1697 | 'time' => $membershipEndDate->format('Y-m-d H:i:s'), | |
1698 | 'recipients' => array(array("test-member-{$interval_unit}@example.com")), | |
1699 | ), | |
1700 | array( | |
1701 | 'time' => $beforeFirstUnit->format('Y-m-d H:i:s'), | |
1702 | 'recipients' => array(), | |
1703 | ), | |
1704 | array( | |
1705 | 'time' => $afterFirstUnit->format('Y-m-d H:i:s'), | |
1706 | 'recipients' => array(array("test-member-{$interval_unit}@example.com")), | |
1707 | ), | |
1708 | ); | |
1709 | $this->assertCronRuns($cronRuns); | |
1710 | $actionSchedule->delete(); | |
1711 | $membership->delete(); | |
1712 | } | |
1713 | } | |
1714 | ||
1715 | public function createModifiedDateTime($origDateTime, $modifyRule) { | |
1716 | $newDateTime = clone($origDateTime); | |
1717 | $newDateTime->modify($modifyRule); | |
1718 | return $newDateTime; | |
1719 | } | |
1720 | ||
6a488035 | 1721 | } |