Merge pull request #12876 from colemanw/Don't
[civicrm-core.git] / tests / phpunit / api / v3 / MailingTest.php
CommitLineData
6a488035 1<?php
8891a36e 2/*
6a488035
TO
3 * File for the TestMailing class
4 *
5 * (PHP 5)
6 *
7 * @package CiviCRM
8 *
9 * This file is part of CiviCRM
10 *
11 * CiviCRM is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Affero General Public License
13 * as published by the Free Software Foundation; either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * CiviCRM is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Affero General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public
22 * License along with this program. If not, see
23 * <http://www.gnu.org/licenses/>.
24 */
25
6a488035
TO
26
27/**
28 * Test APIv3 civicrm_mailing_* functions
29 *
6c6e6187 30 * @package CiviCRM
acb109b7 31 * @group headless
6a488035
TO
32 */
33class api_v3_MailingTest extends CiviUnitTestCase {
34 protected $_groupID;
35 protected $_email;
c43d01f3 36 protected $_apiversion = 3;
37 protected $_params = array();
e37b4b04 38 protected $_entity = 'Mailing';
161ae41b 39 protected $_contactID;
430ae6dd 40
d8e9212d
TO
41 /**
42 * APIv3 result from creating an example footer
43 * @var array
44 */
45 protected $footer;
46
00be9182 47 public function setUp() {
6a488035 48 parent::setUp();
7ada2376 49 $this->useTransaction();
97b7d4a0 50 CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW
161ae41b 51 $this->_contactID = $this->individualCreate();
fadb804f 52 $this->_groupID = $this->groupCreate();
ef170fe0 53 $this->_email = 'test@test.test';
c43d01f3 54 $this->_params = array(
51ae62c4 55 'subject' => 'Hello {contact.display_name}',
b4fb9733
ML
56 'body_text' => "This is {contact.display_name}.\nhttps://civicrm.org\n{domain.address}{action.optOutUrl}",
57 'body_html' => "<p>This is {contact.display_name}.</p><p><a href='https://civicrm.org/'>CiviCRM.org</a></p><p>{domain.address}{action.optOutUrl}</p>",
c43d01f3 58 'name' => 'mailing name',
161ae41b 59 'created_id' => $this->_contactID,
b0a31714
TO
60 'header_id' => '',
61 'footer_id' => '',
c43d01f3 62 );
d8e9212d
TO
63
64 $this->footer = civicrm_api3('MailingComponent', 'create', array(
7824ac72
SL
65 'name' => 'test domain footer',
66 'component_type' => 'footer',
d8e9212d
TO
67 'body_html' => '<p>From {domain.address}. To opt out, go to {action.optOutUrl}.</p>',
68 'body_text' => 'From {domain.address}. To opt out, go to {action.optOutUrl}.',
69 ));
6a488035
TO
70 }
71
00be9182 72 public function tearDown() {
97b7d4a0
TO
73 CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW
74 parent::tearDown();
6a488035
TO
75 }
76
77 /**
fe482240 78 * Test civicrm_mailing_create.
6a488035
TO
79 */
80 public function testMailerCreateSuccess() {
5f445749 81 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
c43d01f3 82 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
6a488035 83 $this->assertEquals(1, $jobs['count']);
ef170fe0 84 unset($this->_params['created_id']); // return isn't working on this in getAndCheck so lets not check it for now
e37b4b04 85 $this->getAndCheck($this->_params, $result['id'], 'mailing');
6a488035
TO
86 }
87
4ea375b4 88 /**
89 * Tes that the parameter _skip_evil_bao_auto_schedule_ is respected & prevents jobs being created.
90 */
91 public function testSkipAutoSchedule() {
92 $this->callAPISuccess('Mailing', 'create', array_merge($this->_params, [
93 '_skip_evil_bao_auto_schedule_' => TRUE,
94 'scheduled_date' => 'now'
95 ]));
96 $this->callAPISuccessGetCount('Mailing', [], 1);
97 $this->callAPISuccessGetCount('MailingJob', [], 0);
98 }
99
11bb7484 100 /**
101 * Create a completed mailing (e.g when importing from a provider).
102 */
103 public function testMailerCreateCompleted() {
104 $this->_params['body_html'] = 'I am completed so it does not matter if there is an opt out link since I have already been sent by another system';
105 $this->_params['is_completed'] = 1;
106 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
107 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
108 $this->assertEquals(1, $jobs['count']);
109 $this->assertEquals('Complete', $jobs['values'][$jobs['id']]['status']);
110 unset($this->_params['created_id']); // return isn't working on this in getAndCheck so lets not check it for now
111 $this->getAndCheck($this->_params, $result['id'], 'mailing');
112 }
113
c442f1b6 114 /**
115 * Per CRM-20316 the mailing should still create without created_id (not mandatory).
116 */
117 public function testMailerCreateSuccessNoCreatedID() {
118 unset($this->_params['created_id']);
119 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
120 $this->getAndCheck($this->_params, $result['id'], 'mailing');
121 }
122
703875d8
TO
123 /**
124 *
125 */
126 public function testTemplateTypeOptions() {
127 $types = $this->callAPISuccess('Mailing', 'getoptions', array('field' => 'template_type'));
128 $this->assertTrue(isset($types['values']['traditional']));
129 }
130
6bc3944a
TO
131 /**
132 * The `template_options` field should be treated a JSON object.
133 *
134 * This test will create, read, and update the field.
135 */
136 public function testMailerCreateTemplateOptions() {
137 // 1. Create mailing with template_options.
138 $params = $this->_params;
139 $params['template_options'] = json_encode(array('foo' => 'bar_1'));
140 $createResult = $this->callAPISuccess('mailing', 'create', $params);
141 $id = $createResult['id'];
142 $this->assertDBQuery('{"foo":"bar_1"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', array(
143 1 => array($id, 'Int'),
144 ));
145 $this->assertEquals('bar_1', $createResult['values'][$id]['template_options']['foo']);
146
147 // 2. Get mailing with template_options.
148 $getResult = $this->callAPISuccess('mailing', 'get', array(
149 'id' => $id,
150 ));
151 $this->assertEquals('bar_1', $getResult['values'][$id]['template_options']['foo']);
152 $getValueResult = $this->callAPISuccess('mailing', 'getvalue', array(
153 'id' => $id,
154 'return' => 'template_options',
155 ));
156 $this->assertEquals('bar_1', $getValueResult['foo']);
157
158 // 3. Update mailing with template_options.
159 $updateResult = $this->callAPISuccess('mailing', 'create', array(
160 'id' => $id,
161 'template_options' => array('foo' => 'bar_2'),
162 ));
163 $this->assertDBQuery('{"foo":"bar_2"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', array(
164 1 => array($id, 'Int'),
165 ));
166 $this->assertEquals('bar_2', $updateResult['values'][$id]['template_options']['foo']);
167 }
168
21eb0c57
TO
169 /**
170 * The Mailing.create API supports magic properties "groups[include,enclude]" and "mailings[include,exclude]".
171 * Make sure these work
172 */
173 public function testMagicGroups_create_update() {
174 // BEGIN SAMPLE DATA
175 $groupIDs['a'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
176 $groupIDs['b'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group'));
92915c55
TO
177 $contactIDs['a'] = $this->individualCreate(array(
178 'email' => 'include.me@example.org',
179 'first_name' => 'Includer',
5396af74 180 'last_name' => 'Person',
92915c55
TO
181 ));
182 $contactIDs['b'] = $this->individualCreate(array(
183 'email' => 'exclude.me@example.org',
5396af74 184 'last_name' => 'Excluder',
92915c55
TO
185 ));
186 $this->callAPISuccess('GroupContact', 'create', array(
187 'group_id' => $groupIDs['a'],
5396af74 188 'contact_id' => $contactIDs['a'],
92915c55
TO
189 ));
190 $this->callAPISuccess('GroupContact', 'create', array(
191 'group_id' => $groupIDs['b'],
5396af74 192 'contact_id' => $contactIDs['b'],
92915c55 193 ));
21eb0c57
TO
194 // END SAMPLE DATA
195
196 // ** Pass 1: Create
197 $createParams = $this->_params;
198 $createParams['groups']['include'] = array($groupIDs['a']);
199 $createParams['groups']['exclude'] = array();
200 $createParams['mailings']['include'] = array();
201 $createParams['mailings']['exclude'] = array();
5f445749 202 $createParams['api.mailing_job.create'] = 1;
21eb0c57
TO
203 $createResult = $this->callAPISuccess('Mailing', 'create', $createParams);
204 $getGroup1 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
205 $getGroup1_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup1['values']));
206 $this->assertEquals(array($groupIDs['a']), $getGroup1_ids);
39010e60
EM
207 $getRecipient1 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
208 $getRecipient1_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient1['values']));
209 $this->assertEquals(array($contactIDs['a']), $getRecipient1_ids);
21eb0c57
TO
210
211 // ** Pass 2: Update without any changes to groups[include]
39010e60
EM
212 $nullOpParams = $createParams;
213 $nullOpParams['id'] = $createResult['id'];
7575b840 214 $updateParams['api.mailing_job.create'] = 1;
39010e60
EM
215 unset($nullOpParams['groups']['include']);
216 $this->callAPISuccess('Mailing', 'create', $nullOpParams);
21eb0c57
TO
217 $getGroup2 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
218 $getGroup2_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup2['values']));
219 $this->assertEquals(array($groupIDs['a']), $getGroup2_ids);
39010e60
EM
220 $getRecipient2 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
221 $getRecip2_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient2['values']));
7575b840 222 $this->assertEquals(array($contactIDs['a']), $getRecip2_ids);
21eb0c57
TO
223
224 // ** Pass 3: Update with different groups[include]
225 $updateParams = $createParams;
226 $updateParams['id'] = $createResult['id'];
227 $updateParams['groups']['include'] = array($groupIDs['b']);
7575b840 228 $updateParams['api.mailing_job.create'] = 1;
21eb0c57
TO
229 $this->callAPISuccess('Mailing', 'create', $updateParams);
230 $getGroup3 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
231 $getGroup3_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup3['values']));
232 $this->assertEquals(array($groupIDs['b']), $getGroup3_ids);
39010e60
EM
233 $getRecipient3 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
234 $getRecipient3_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient3['values']));
235 $this->assertEquals(array($contactIDs['b']), $getRecipient3_ids);
21eb0c57
TO
236 }
237
ef643544 238 public function testMailerPreview() {
51ae62c4 239 // BEGIN SAMPLE DATA
6c6e6187 240 $contactID = $this->individualCreate();
ef643544 241 $displayName = $this->callAPISuccess('contact', 'get', array('id' => $contactID));
242 $displayName = $displayName['values'][$contactID]['display_name'];
51ae62c4
TO
243 $this->assertTrue(!empty($displayName));
244
245 $params = $this->_params;
246 $params['api.Mailing.preview'] = array(
247 'id' => '$value.id',
248 'contact_id' => $contactID,
249 );
250 $params['options']['force_rollback'] = 1;
251 // END SAMPLE DATA
7811a84b 252
6c6e6187 253 $maxIDs = array(
51ae62c4
TO
254 'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'),
255 'job' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_job'),
256 'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'),
39010e60 257 'recipient' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_recipients'),
51ae62c4
TO
258 );
259 $result = $this->callAPISuccess('mailing', 'create', $params);
260 $this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); // 'Preview should not create any mailing records'
261 $this->assertDBQuery($maxIDs['job'], 'SELECT MAX(id) FROM civicrm_mailing_job'); // 'Preview should not create any mailing_job record'
262 $this->assertDBQuery($maxIDs['group'], 'SELECT MAX(id) FROM civicrm_mailing_group'); // 'Preview should not create any mailing_group records'
39010e60 263 $this->assertDBQuery($maxIDs['recipient'], 'SELECT MAX(id) FROM civicrm_mailing_recipients'); // 'Preview should not create any mailing_recipient records'
7811a84b 264
51ae62c4
TO
265 $previewResult = $result['values'][$result['id']]['api.Mailing.preview'];
266 $this->assertEquals("Hello $displayName", $previewResult['values']['subject']);
21b09c13
TO
267 $this->assertContains("This is $displayName", $previewResult['values']['body_text']);
268 $this->assertContains("<p>This is $displayName.</p>", $previewResult['values']['body_html']);
ef643544 269 }
7811a84b 270
fddd185d
TO
271 public function testMailerPreviewRecipients() {
272 // BEGIN SAMPLE DATA
161ae41b
TO
273 $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
274 $groupIDs['exc'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group'));
39010e60 275 $contactIDs['include_me'] = $this->individualCreate(array(
92915c55
TO
276 'email' => 'include.me@example.org',
277 'first_name' => 'Includer',
5396af74 278 'last_name' => 'Person',
92915c55 279 ));
39010e60 280 $contactIDs['exclude_me'] = $this->individualCreate(array(
92915c55 281 'email' => 'exclude.me@example.org',
39010e60 282 'last_name' => 'Excluder',
92915c55
TO
283 ));
284 $this->callAPISuccess('GroupContact', 'create', array(
285 'group_id' => $groupIDs['inc'],
5396af74 286 'contact_id' => $contactIDs['include_me'],
92915c55
TO
287 ));
288 $this->callAPISuccess('GroupContact', 'create', array(
289 'group_id' => $groupIDs['inc'],
5396af74 290 'contact_id' => $contactIDs['exclude_me'],
92915c55
TO
291 ));
292 $this->callAPISuccess('GroupContact', 'create', array(
293 'group_id' => $groupIDs['exc'],
5396af74 294 'contact_id' => $contactIDs['exclude_me'],
92915c55 295 ));
fddd185d
TO
296
297 $params = $this->_params;
161ae41b
TO
298 $params['groups']['include'] = array($groupIDs['inc']);
299 $params['groups']['exclude'] = array($groupIDs['exc']);
fddd185d
TO
300 $params['mailings']['include'] = array();
301 $params['mailings']['exclude'] = array();
b73e0c53
TO
302 $params['options']['force_rollback'] = 1;
303 $params['api.MailingRecipients.get'] = array(
304 'mailing_id' => '$value.id',
305 'api.contact.getvalue' => array(
306 'return' => 'display_name',
307 ),
308 'api.email.getvalue' => array(
309 'return' => 'email',
310 ),
311 );
fddd185d
TO
312 // END SAMPLE DATA
313
6c6e6187 314 $maxIDs = array(
fddd185d 315 'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'),
fddd185d
TO
316 'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'),
317 );
b73e0c53 318 $create = $this->callAPIAndDocument('Mailing', 'create', $params, __FUNCTION__, __FILE__);
fddd185d 319 $this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); // 'Preview should not create any mailing records'
fddd185d
TO
320 $this->assertDBQuery($maxIDs['group'], 'SELECT MAX(id) FROM civicrm_mailing_group'); // 'Preview should not create any mailing_group records'
321
b73e0c53 322 $preview = $create['values'][$create['id']]['api.MailingRecipients.get'];
fddd185d 323 $previewIds = array_values(CRM_Utils_Array::collect('contact_id', $preview['values']));
39010e60 324 $this->assertEquals(array((string) $contactIDs['include_me']), $previewIds);
b73e0c53
TO
325 $previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values']));
326 $this->assertEquals(array('include.me@example.org'), $previewEmails);
327 $previewNames = array_values(CRM_Utils_Array::collect('api.contact.getvalue', $preview['values']));
6c6e6187 328 $this->assertTrue((bool) preg_match('/Includer Person/', $previewNames[0]), "Name 'Includer Person' should appear in '" . $previewNames[0] . '"');
fddd185d
TO
329 }
330
2008d65d
JP
331 /**
332 * Test if Mailing recipients include duplicate OR on_hold emails
333 */
334 public function testMailerPreviewRecipientsDeduplicateAndOnholdEmails() {
b20e7428
AS
335 // BEGIN SAMPLE DATA
336 $groupIDs['grp'] = $this->groupCreate(array('name' => 'Example group', 'title' => 'Example group'));
337 $contactIDs['include_me'] = $this->individualCreate(array(
338 'email' => 'include.me@example.org',
339 'first_name' => 'Includer',
340 'last_name' => 'Person',
341 ));
342 $contactIDs['include_me_duplicate'] = $this->individualCreate(array(
343 'email' => 'include.me@example.org',
344 'first_name' => 'IncluderDuplicate',
345 'last_name' => 'Person',
346 ));
2008d65d
JP
347
348 $contactIDs['include_me_onhold'] = $this->individualCreate(array(
349 'email' => 'onholdinclude.me@example.org',
350 'first_name' => 'Onhold',
351 'last_name' => 'Person',
352 ));
353 $emailId = $this->callAPISuccessGetValue('Email', array(
354 'return' => 'id',
355 'contact_id' => $contactIDs['include_me_onhold'],
356 ));
357 $this->callAPISuccess('Email', 'create', array(
358 'id' => $emailId,
359 'on_hold' => TRUE,
360 ));
361
b20e7428
AS
362 $this->callAPISuccess('GroupContact', 'create', array(
363 'group_id' => $groupIDs['grp'],
364 'contact_id' => $contactIDs['include_me'],
365 ));
366 $this->callAPISuccess('GroupContact', 'create', array(
367 'group_id' => $groupIDs['grp'],
368 'contact_id' => $contactIDs['include_me_duplicate'],
369 ));
2008d65d
JP
370 $this->callAPISuccess('GroupContact', 'create', array(
371 'group_id' => $groupIDs['grp'],
372 'contact_id' => $contactIDs['include_me_onhold'],
373 ));
b20e7428
AS
374
375 $params = $this->_params;
376 $params['groups']['include'] = array($groupIDs['grp']);
377 $params['mailings']['include'] = array();
378 $params['options']['force_rollback'] = 1;
379 $params['dedupe_email'] = 1;
b20e7428
AS
380 $params['api.MailingRecipients.get'] = array(
381 'mailing_id' => '$value.id',
382 'api.contact.getvalue' => array(
383 'return' => 'display_name',
384 ),
385 'api.email.getvalue' => array(
386 'return' => 'email',
387 ),
388 );
389 // END SAMPLE DATA
390
3c27d467 391 $create = $this->callAPISuccess('Mailing', 'create', $params);
b20e7428 392
2008d65d 393 //Recipient should not contain duplicate or on_hold emails.
b20e7428
AS
394 $preview = $create['values'][$create['id']]['api.MailingRecipients.get'];
395 $this->assertEquals(1, $preview['count']);
396 $previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values']));
397 $this->assertEquals(array('include.me@example.org'), $previewEmails);
398 }
399
39010e60 400 /**
480a9346 401 * Test sending a test mailing.
39010e60 402 */
7ada2376 403 public function testMailerSendTest_email() {
92915c55
TO
404 $contactIDs['alice'] = $this->individualCreate(array(
405 'email' => 'alice@example.org',
406 'first_name' => 'Alice',
5396af74 407 'last_name' => 'Person',
92915c55 408 ));
7811a84b 409
ef643544 410 $mail = $this->callAPISuccess('mailing', 'create', $this->_params);
7811a84b 411
736a042c 412 $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
480a9346 413 // Per https://lab.civicrm.org/dev/core/issues/229 ensure this is not passed through!
414 $params['id'] = $mail['id'];
ef643544 415 $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
480a9346 416 $this->assertEquals(1, $deliveredInfo['count']); // verify mail has been sent to user by count
736a042c
TO
417
418 $deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values']));
419 $this->assertEquals(array($contactIDs['alice']), $deliveredContacts);
420
421 $deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values']));
422 $this->assertEquals(array('alice@example.org'), $deliveredEmails);
ef643544 423 }
7811a84b 424
39010e60
EM
425 /**
426 *
427 */
7ada2376
TO
428 public function testMailerSendTest_group() {
429 // BEGIN SAMPLE DATA
161ae41b 430 $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
92915c55
TO
431 $contactIDs['alice'] = $this->individualCreate(array(
432 'email' => 'alice@example.org',
433 'first_name' => 'Alice',
5396af74 434 'last_name' => 'Person',
92915c55
TO
435 ));
436 $contactIDs['bob'] = $this->individualCreate(array(
437 'email' => 'bob@example.org',
438 'first_name' => 'Bob',
5396af74 439 'last_name' => 'Person',
92915c55
TO
440 ));
441 $contactIDs['carol'] = $this->individualCreate(array(
442 'email' => 'carol@example.org',
443 'first_name' => 'Carol',
5396af74 444 'last_name' => 'Person',
92915c55
TO
445 ));
446 $this->callAPISuccess('GroupContact', 'create', array(
447 'group_id' => $groupIDs['inc'],
5396af74 448 'contact_id' => $contactIDs['alice'],
92915c55
TO
449 ));
450 $this->callAPISuccess('GroupContact', 'create', array(
451 'group_id' => $groupIDs['inc'],
5396af74 452 'contact_id' => $contactIDs['bob'],
92915c55
TO
453 ));
454 $this->callAPISuccess('GroupContact', 'create', array(
455 'group_id' => $groupIDs['inc'],
5396af74 456 'contact_id' => $contactIDs['carol'],
92915c55 457 ));
7ada2376
TO
458 // END SAMPLE DATA
459
460 $mail = $this->callAPISuccess('mailing', 'create', $this->_params);
461 $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', array(
462 'mailing_id' => $mail['id'],
463 'test_email' => NULL,
161ae41b 464 'test_group' => $groupIDs['inc'],
7ada2376
TO
465 ));
466 $this->assertEquals(3, $deliveredInfo['count'], "in line " . __LINE__); // verify mail has been sent to user by count
736a042c 467
7ada2376 468 $deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values']));
161ae41b 469 $this->assertEquals(array($contactIDs['alice'], $contactIDs['bob'], $contactIDs['carol']), $deliveredContacts);
736a042c 470
7ada2376
TO
471 $deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values']));
472 $this->assertEquals(array('alice@example.org', 'bob@example.org', 'carol@example.org'), $deliveredEmails);
473 }
474
ad4f6a9c
EM
475 /**
476 * @return array
477 */
6818346a
TO
478 public function submitProvider() {
479 $cases = array(); // $useLogin, $params, $expectedFailure, $expectedJobCount
480 $cases[] = array(
481 TRUE, //useLogin
d78cc635 482 array(), // createParams
6818346a
TO
483 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
484 FALSE, // expectedFailure
485 1, // expectedJobCount
486 );
487 $cases[] = array(
488 FALSE, //useLogin
d78cc635 489 array(), // createParams
6818346a
TO
490 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
491 "/Failed to determine current user/", // expectedFailure
492 0, // expectedJobCount
493 );
494 $cases[] = array(
495 TRUE, //useLogin
d78cc635 496 array(), // createParams
6818346a
TO
497 array('scheduled_date' => '2014-12-13 10:00:00'),
498 FALSE, // expectedFailure
499 1, // expectedJobCount
500 );
501 $cases[] = array(
502 TRUE, //useLogin
d78cc635 503 array(), // createParams
6818346a
TO
504 array(),
505 "/Missing parameter scheduled_date and.or approval_date/", // expectedFailure
506 0, // expectedJobCount
507 );
d78cc635
TO
508 $cases[] = array(
509 TRUE, //useLogin
510 array('name' => ''), // createParams
511 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
21b09c13 512 "/Mailing cannot be sent. There are missing or invalid fields \\(name\\)./", // expectedFailure
d78cc635
TO
513 0, // expectedJobCount
514 );
21b09c13
TO
515 $cases[] = array(
516 TRUE, //useLogin
517 array('body_html' => '', 'body_text' => ''), // createParams
518 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
519 "/Mailing cannot be sent. There are missing or invalid fields \\(body\\)./", // expectedFailure
520 0, // expectedJobCount
521 );
522 $cases[] = array(
523 TRUE, //useLogin
524 array('body_html' => 'Oops, did I leave my tokens at home?'), // createParams
525 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
526 "/Mailing cannot be sent. There are missing or invalid fields \\(.*body_html.*optOut.*\\)./", // expectedFailure
527 0, // expectedJobCount
528 );
529 $cases[] = array(
530 TRUE, //useLogin
531 array('body_text' => 'Oops, did I leave my tokens at home?'), // createParams
532 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
533 "/Mailing cannot be sent. There are missing or invalid fields \\(.*body_text.*optOut.*\\)./", // expectedFailure
534 0, // expectedJobCount
535 );
d8e9212d
TO
536 $cases[] = array(
537 TRUE, //useLogin
538 array('body_text' => 'Look ma, magic tokens in the text!', 'footer_id' => '%FOOTER%'), // createParams
539 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
540 FALSE, // expectedFailure
541 1, // expectedJobCount
542 );
543 $cases[] = array(
544 TRUE, //useLogin
545 array('body_html' => '<p>Look ma, magic tokens in the markup!</p>', 'footer_id' => '%FOOTER%'), // createParams
546 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
547 FALSE, // expectedFailure
548 1, // expectedJobCount
549 );
6818346a
TO
550 return $cases;
551 }
552
553 /**
554 * @param bool $useLogin
d78cc635
TO
555 * @param array $createParams
556 * @param array $submitParams
6818346a
TO
557 * @param null|string $expectedFailure
558 * @param int $expectedJobCount
559 * @dataProvider submitProvider
560 */
d78cc635 561 public function testMailerSubmit($useLogin, $createParams, $submitParams, $expectedFailure, $expectedJobCount) {
6818346a
TO
562 if ($useLogin) {
563 $this->createLoggedInUser();
564 }
565
d8e9212d
TO
566 if (isset($createParams['footer_id']) && $createParams['footer_id'] == '%FOOTER%') {
567 $createParams['footer_id'] = $this->footer['id'];
568 }
569
d78cc635 570 $id = $this->createDraftMailing($createParams);
6818346a 571
d78cc635 572 $submitParams['id'] = $id;
6818346a 573 if ($expectedFailure) {
d78cc635 574 $submitResult = $this->callAPIFailure('mailing', 'submit', $submitParams);
6818346a
TO
575 $this->assertRegExp($expectedFailure, $submitResult['error_message']);
576 }
577 else {
d78cc635 578 $submitResult = $this->callAPIAndDocument('mailing', 'submit', $submitParams, __FUNCTION__, __FILE__);
6818346a
TO
579 $this->assertTrue(is_numeric($submitResult['id']));
580 $this->assertTrue(is_numeric($submitResult['values'][$id]['scheduled_id']));
d78cc635 581 $this->assertEquals($submitParams['scheduled_date'], $submitResult['values'][$id]['scheduled_date']);
6818346a
TO
582 }
583 $this->assertDBQuery($expectedJobCount, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
21dfd5f5 584 1 => array($id, 'Integer'),
6818346a
TO
585 ));
586 }
587
9629f523
JP
588 /**
589 * Test unsubscribe list contains correct groups
590 * when include = 'previous mailing'
591 */
592 public function testUnsubscribeGroupList() {
593 // Create set of groups and add a contact to both of them.
594 $groupID2 = $this->groupCreate(array('name' => 'Test group 2', 'title' => 'group title 2'));
595 $groupID3 = $this->groupCreate(array('name' => 'Test group 3', 'title' => 'group title 3'));
596 $contactId = $this->individualCreate();
597 foreach (array($groupID2, $groupID3) as $grp) {
598 $params = array(
599 'contact_id' => $contactId,
600 'group_id' => $grp,
601 );
602 $this->callAPISuccess('GroupContact', 'create', $params);
603 }
604
605 //Send mail to groupID3
606 $mail = $this->callAPISuccess('mailing', 'create', $this->_params);
607 $params = array('mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $groupID3);
608 $this->callAPISuccess($this->_entity, 'send_test', $params);
609
610 $mgParams = array(
611 'mailing_id' => $mail['id'],
612 'entity_table' => 'civicrm_group',
613 'entity_id' => $groupID3,
614 'group_type' => 'Include',
615 );
616 $mailingGroup = $this->callAPISuccess('MailingGroup', 'create', $mgParams);
617
618 //Include previous mail in the mailing group.
619 $mail2 = $this->callAPISuccess('mailing', 'create', $this->_params);
620 $params = array('mailing_id' => $mail2['id'], 'test_email' => NULL, 'test_group' => $groupID3);
621 $this->callAPISuccess($this->_entity, 'send_test', $params);
622
623 $mgParams = array(
624 'mailing_id' => $mail2['id'],
625 'entity_table' => 'civicrm_mailing',
626 'entity_id' => $mail['id'],
627 'group_type' => 'Include',
628 );
629 $mailingGroup = $this->callAPISuccess('MailingGroup', 'create', $mgParams);
630 //CRM-20431 - Delete group id that matches first mailing id.
631 $this->callAPISuccess('Group', 'delete', array('id' => $this->_groupID));
632 $jobId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingJob', $mail2['id'], 'id', 'mailing_id');
633 $hash = CRM_Core_DAO::getFieldValue('CRM_Mailing_Event_DAO_Queue', $jobId, 'hash', 'job_id');
634 $queueId = CRM_Core_DAO::getFieldValue('CRM_Mailing_Event_DAO_Queue', $jobId, 'id', 'job_id');
635
636 $group = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($jobId, $queueId, $hash, TRUE);
637 //Assert only one group returns in the unsubscribe list.
638 $this->assertCount(1, $group);
639 $this->assertEquals($groupID3, key($group));
640 }
641
39010e60
EM
642 /**
643 *
644 */
ef643544 645 public function testMailerStats() {
646 $result = $this->groupContactCreate($this->_groupID, 100);
647 $this->assertEquals(100, $result['added']); //verify if 100 contacts are added for group
7811a84b 648
649 //Create and send test mail first and change the mail job to live,
650 //because stats api only works on live mail
ef643544 651 $mail = $this->callAPISuccess('mailing', 'create', $this->_params);
7811a84b 652 $params = array('mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $this->_groupID);
ef643544 653 $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
92915c55 654 $deliveredIds = implode(',', array_keys($deliveredInfo['values']));
7811a84b 655
656 //Change the test mail into live
657 $sql = "UPDATE civicrm_mailing_job SET is_test = 0 WHERE mailing_id = {$mail['id']}";
658 CRM_Core_DAO::executeQuery($sql);
659
ef643544 660 foreach (array('bounce', 'unsubscribe', 'opened') as $type) {
661 $sql = "CREATE TEMPORARY TABLE mail_{$type}_temp
662(event_queue_id int, time_stamp datetime, delivered_id int)
663SELECT event_queue_id, time_stamp, id
664 FROM civicrm_mailing_event_delivered
665 WHERE id IN ($deliveredIds)
666 ORDER BY RAND() LIMIT 0,20;";
ef643544 667 CRM_Core_DAO::executeQuery($sql);
7811a84b 668
ef643544 669 $sql = "DELETE FROM civicrm_mailing_event_delivered WHERE id IN (SELECT delivered_id FROM mail_{$type}_temp);";
670 CRM_Core_DAO::executeQuery($sql);
7811a84b 671
ef643544 672 if ($type == 'unsubscribe') {
673 $sql = "INSERT INTO civicrm_mailing_event_{$type} (event_queue_id, time_stamp, org_unsubscribe)
674SELECT event_queue_id, time_stamp, 1 FROM mail_{$type}_temp";
675 }
676 else {
677 $sql = "INSERT INTO civicrm_mailing_event_{$type} (event_queue_id, time_stamp)
678SELECT event_queue_id, time_stamp FROM mail_{$type}_temp";
679 }
680 CRM_Core_DAO::executeQuery($sql);
681 }
7811a84b 682
ef643544 683 $result = $this->callAPISuccess('mailing', 'stats', array('mailing_id' => $mail['id']));
684 $expectedResult = array(
685 'Delivered' => 80, //since among 100 mails 20 has been bounced
686 'Bounces' => 20,
687 'Opened' => 20,
688 'Unique Clicks' => 0,
21dfd5f5 689 'Unsubscribers' => 20,
796b4348
SL
690 'delivered_rate' => '80%',
691 'opened_rate' => '25%',
692 'clickthrough_rate' => '0%',
ef643544 693 );
ef643544 694 $this->checkArrayEquals($expectedResult, $result['values'][$mail['id']]);
695 }
92915c55 696
c43d01f3 697 /**
fe482240 698 * Test civicrm_mailing_delete.
c43d01f3 699 */
700 public function testMailerDeleteSuccess() {
e37b4b04 701 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
ad4f6a9c 702 $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
e37b4b04 703 $this->assertAPIDeleted($this->_entity, $result['id']);
c43d01f3 704 }
6a488035 705
1d280e03
CW
706 /**
707 * Test Mailing.gettokens.
708 */
709 public function testMailGetTokens() {
9950a1c9 710 $description = "Demonstrates fetching tokens for one or more entities (in this case \"Contact\" and \"Mailing\").
1d280e03 711 Optionally pass sequential=1 to have output ready-formatted for the select2 widget.";
9950a1c9
CW
712 $result = $this->callAPIAndDocument($this->_entity, 'gettokens', array('entity' => array('Contact', 'Mailing')), __FUNCTION__, __FILE__, $description);
713 $this->assertContains('Contact Type', $result['values']);
714
715 // Check that passing "sequential" correctly outputs a hierarchical array
716 $result = $this->callAPISuccess($this->_entity, 'gettokens', array('entity' => 'contact', 'sequential' => 1));
717 $this->assertArrayHasKey('text', $result['values'][0]);
718 $this->assertArrayHasKey('id', $result['values'][0]['children'][0]);
1d280e03
CW
719 }
720
00dc999a
TO
721 public function testClone() {
722 // BEGIN SAMPLE DATA
723 $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
724 $contactIDs['include_me'] = $this->individualCreate(array(
725 'email' => 'include.me@example.org',
726 'first_name' => 'Includer',
727 'last_name' => 'Person',
728 ));
729 $this->callAPISuccess('GroupContact', 'create', array(
730 'group_id' => $groupIDs['inc'],
731 'contact_id' => $contactIDs['include_me'],
732 ));
733
734 $params = $this->_params;
735 $params['groups']['include'] = array($groupIDs['inc']);
736 $params['groups']['exclude'] = array();
737 $params['mailings']['include'] = array();
738 $params['mailings']['exclude'] = array();
739 // END SAMPLE DATA
740
741 $create = $this->callAPISuccess('Mailing', 'create', $params);
f487e358 742 $created = $this->callAPISuccess('Mailing', 'get', []);
00dc999a
TO
743 $createId = $create['id'];
744 $this->createLoggedInUser();
745 $clone = $this->callAPIAndDocument('Mailing', 'clone', array('id' => $create['id']), __FUNCTION__, __FILE__);
746 $cloneId = $clone['id'];
747
748 $this->assertNotEquals($createId, $cloneId, 'Create and clone should return different records');
749 $this->assertTrue(is_numeric($cloneId));
750
751 $this->assertNotEmpty($clone['values'][$cloneId]['subject']);
752 $this->assertEquals($params['subject'], $clone['values'][$cloneId]['subject'], "Cloned subject should match");
753
754 // created_id is special - populated based on current user (ie the cloner).
755 $this->assertNotEmpty($clone['values'][$cloneId]['created_id']);
756 $this->assertNotEquals($create['values'][$createId]['created_id'], $clone['values'][$cloneId]['created_id'], 'Clone should be created by a different person');
757
758 // Target groups+mailings are special.
759 $cloneGroups = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $cloneId, 'sequential' => 1));
760 $this->assertEquals(1, $cloneGroups['count']);
761 $this->assertEquals($cloneGroups['values'][0]['group_type'], 'Include');
762 $this->assertEquals($cloneGroups['values'][0]['entity_table'], 'civicrm_group');
763 $this->assertEquals($cloneGroups['values'][0]['entity_id'], $groupIDs['inc']);
764 }
765
6a488035
TO
766 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
767
768 //------------ civicrm_mailing_event_bounce methods------------
769
770 /**
771 * Test civicrm_mailing_event_bounce with wrong params.
e37b4b04 772 * Note that tests like this are slightly better than no test but an
773 * api function cannot be considered supported / 'part of the api' without a
774 * success test
6a488035
TO
775 */
776 public function testMailerBounceWrongParams() {
777 $params = array(
778 'job_id' => 'Wrong ID',
779 'event_queue_id' => 'Wrong ID',
780 'hash' => 'Wrong Hash',
781 'body' => 'Body...',
6a488035
TO
782 'time_stamp' => '20111109212100',
783 );
ad4f6a9c 784 $this->callAPIFailure('mailing_event', 'bounce', $params,
30d44db2 785 'Queue event could not be found'
786 );
6a488035
TO
787 }
788
789 //----------- civicrm_mailing_event_confirm methods -----------
790
791 /**
792 * Test civicrm_mailing_event_confirm with wrong params.
e37b4b04 793 * Note that tests like this are slightly better than no test but an
794 * api function cannot be considered supported / 'part of the api' without a
795 * success test
6a488035
TO
796 */
797 public function testMailerConfirmWrongParams() {
798 $params = array(
799 'contact_id' => 'Wrong ID',
800 'subscribe_id' => 'Wrong ID',
801 'hash' => 'Wrong Hash',
802 'event_subscribe_id' => '123',
803 'time_stamp' => '20111111010101',
ef170fe0 804 );
ad4f6a9c 805 $this->callAPIFailure('mailing_event', 'confirm', $params,
4f94e3fa 806 'contact_id is not a valid integer'
e37b4b04 807 );
6a488035
TO
808 }
809
810 //---------- civicrm_mailing_event_reply methods -----------
811
812 /**
813 * Test civicrm_mailing_event_reply with wrong params.
e37b4b04 814 *
815 * Note that tests like this are slightly better than no test but an
816 * api function cannot be considered supported / 'part of the api' without a
817 * success test
6a488035
TO
818 */
819 public function testMailerReplyWrongParams() {
820 $params = array(
821 'job_id' => 'Wrong ID',
822 'event_queue_id' => 'Wrong ID',
823 'hash' => 'Wrong Hash',
824 'bodyTxt' => 'Body...',
825 'replyTo' => $this->_email,
826 'time_stamp' => '20111111010101',
ef170fe0 827 );
ad4f6a9c 828 $this->callAPIFailure('mailing_event', 'reply', $params,
e37b4b04 829 'Queue event could not be found'
30d44db2 830 );
6a488035
TO
831 }
832
833
834 //----------- civicrm_mailing_event_forward methods ----------
835
836 /**
837 * Test civicrm_mailing_event_forward with wrong params.
e37b4b04 838 * Note that tests like this are slightly better than no test but an
839 * api function cannot be considered supported / 'part of the api' without a
840 * success test
6a488035
TO
841 */
842 public function testMailerForwardWrongParams() {
843 $params = array(
844 'job_id' => 'Wrong ID',
845 'event_queue_id' => 'Wrong ID',
846 'hash' => 'Wrong Hash',
847 'email' => $this->_email,
848 'time_stamp' => '20111111010101',
ef170fe0 849 );
ad4f6a9c 850 $this->callAPIFailure('mailing_event', 'forward', $params,
e37b4b04 851 'Queue event could not be found'
852 );
6a488035
TO
853 }
854
6818346a 855 /**
d78cc635
TO
856 * @param array $params
857 * Extra parameters for the draft mailing.
6818346a
TO
858 * @return array|int
859 */
d78cc635
TO
860 public function createDraftMailing($params = array()) {
861 $createParams = array_merge($this->_params, $params);
6818346a
TO
862 $createResult = $this->callAPISuccess('mailing', 'create', $createParams, __FUNCTION__, __FILE__);
863 $this->assertTrue(is_numeric($createResult['id']));
864 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
21dfd5f5 865 1 => array($createResult['id'], 'Integer'),
6818346a
TO
866 ));
867 return $createResult['id'];
868 }
869
b4fb9733
ML
870 /**
871 * Test to make sure that if the event queue hashes have been archived,
872 * we can still have working click-trough URLs working (CRM-17959).
873 */
874 public function testUrlWithMissingTrackingHash() {
3c27d467 875 $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
b4fb9733
ML
876 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $mail['id']));
877 $this->assertEquals(1, $jobs['count']);
878
879 $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
880 $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
881
882 $sql = "SELECT turl.id as url_id, turl.url, q.id as queue_id
883 FROM civicrm_mailing_trackable_url as turl
884 INNER JOIN civicrm_mailing_job as j ON turl.mailing_id = j.mailing_id
885 INNER JOIN civicrm_mailing_event_queue q ON j.id = q.job_id
886 ORDER BY turl.id DESC LIMIT 1";
887
888 $dao = CRM_Core_DAO::executeQuery($sql);
889 $this->assertTrue($dao->fetch());
890
891 $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
892 $this->assertContains('https://civicrm.org', $url);
893
894 // Now delete the event queue hashes and see if the tracking still works.
895 CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_event_queue');
896
897 $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
898 $this->assertContains('https://civicrm.org', $url);
899 }
6a488035 900
3c70eacb 901 /**
902 * Test Trackable URL with unicode character
903 */
904 public function testTrackableURLWithUnicodeSign() {
905 $unicodeURL = "https://civiƄcrm.org";
906 $this->_params['body_text'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_text']);
907 $this->_params['body_html'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_html']);
908
3c27d467 909 $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now'));
3c70eacb 910
911 $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
3c27d467 912 $this->callAPISuccess($this->_entity, 'send_test', $params);
3c70eacb 913
914 $sql = "SELECT turl.id as url_id, turl.url, q.id as queue_id
915 FROM civicrm_mailing_trackable_url as turl
916 INNER JOIN civicrm_mailing_job as j ON turl.mailing_id = j.mailing_id
917 INNER JOIN civicrm_mailing_event_queue q ON j.id = q.job_id
918 ORDER BY turl.id DESC LIMIT 1";
919
920 $dao = CRM_Core_DAO::executeQuery($sql);
921 $this->assertTrue($dao->fetch());
922
923 $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
924 $this->assertContains($unicodeURL, $url);
925
926 // Now delete the event queue hashes and see if the tracking still works.
927 CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_event_queue');
928
929 $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($dao->queue_id, $dao->url_id);
930 $this->assertContains($unicodeURL, $url);
931 }
932
c26f9b8c
SL
933 /**
934 * CRM-20892 : Test if Mail.create API throws error on update,
935 * if modified_date less then the date when the mail was last updated/created
936 */
937 public function testModifiedDateMismatchOnMailingUpdate() {
938 $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('modified_date' => 'now'));
939 try {
940 $this->callAPISuccess('mailing', 'create', $this->_params + array('id' => $mail['id'], 'modified_date' => '2 seconds ago'));
941 }
942 catch (Exception $e) {
943 $this->assertRegExp("/Failure in api call for mailing create: Mailing has not been saved, Content maybe out of date, please refresh the page and try again/", $e->getMessage());
944 }
945 }
946
6a488035 947}