Merge pull request #5130 from totten/master-mailing-misc2
[civicrm-core.git] / tests / phpunit / api / v3 / MailingTest.php
1 <?php
2 /*
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
26 require_once 'CiviTest/CiviUnitTestCase.php';
27
28
29 /**
30 * Test APIv3 civicrm_mailing_* functions
31 *
32 * @package CiviCRM
33 */
34 class api_v3_MailingTest extends CiviUnitTestCase {
35 protected $_groupID;
36 protected $_email;
37 protected $_apiversion = 3;
38 protected $_params = array();
39 protected $_entity = 'Mailing';
40 protected $_contactID;
41
42 public function setUp() {
43 parent::setUp();
44 $this->useTransaction();
45 CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW
46 $this->_contactID = $this->individualCreate();
47 $this->_groupID = $this->groupCreate();
48 $this->_email = 'test@test.test';
49 $this->_params = array(
50 'subject' => 'Hello {contact.display_name}',
51 'body_text' => "This is {contact.display_name}.\n{domain.address}{action.optOutUrl}",
52 'body_html' => "<p>This is {contact.display_name}.</p><p>{domain.address}{action.optOutUrl}</p>",
53 'name' => 'mailing name',
54 'created_id' => $this->_contactID,
55 'header_id' => '',
56 'footer_id' => '',
57 );
58 }
59
60 public function tearDown() {
61 CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW
62 parent::tearDown();
63 }
64
65 /**
66 * Test civicrm_mailing_create.
67 */
68 public function testMailerCreateSuccess() {
69 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
70 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
71 $this->assertEquals(1, $jobs['count']);
72 unset($this->_params['created_id']); // return isn't working on this in getAndCheck so lets not check it for now
73 $this->getAndCheck($this->_params, $result['id'], 'mailing');
74 }
75
76 /**
77 * The Mailing.create API supports magic properties "groups[include,enclude]" and "mailings[include,exclude]".
78 * Make sure these work
79 */
80 public function testMagicGroups_create_update() {
81 // BEGIN SAMPLE DATA
82 $groupIDs['a'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
83 $groupIDs['b'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group'));
84 $contactIDs['a'] = $this->individualCreate(array(
85 'email' => 'include.me@example.org',
86 'first_name' => 'Includer',
87 'last_name' => 'Person',
88 ));
89 $contactIDs['b'] = $this->individualCreate(array(
90 'email' => 'exclude.me@example.org',
91 'last_name' => 'Excluder',
92 ));
93 $this->callAPISuccess('GroupContact', 'create', array(
94 'group_id' => $groupIDs['a'],
95 'contact_id' => $contactIDs['a'],
96 ));
97 $this->callAPISuccess('GroupContact', 'create', array(
98 'group_id' => $groupIDs['b'],
99 'contact_id' => $contactIDs['b'],
100 ));
101 // END SAMPLE DATA
102
103 // ** Pass 1: Create
104 $createParams = $this->_params;
105 $createParams['groups']['include'] = array($groupIDs['a']);
106 $createParams['groups']['exclude'] = array();
107 $createParams['mailings']['include'] = array();
108 $createParams['mailings']['exclude'] = array();
109 $createParams['api.mailing_job.create'] = 1;
110 $createResult = $this->callAPISuccess('Mailing', 'create', $createParams);
111 $getGroup1 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
112 $getGroup1_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup1['values']));
113 $this->assertEquals(array($groupIDs['a']), $getGroup1_ids);
114 $getRecipient1 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
115 $getRecipient1_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient1['values']));
116 $this->assertEquals(array($contactIDs['a']), $getRecipient1_ids);
117
118 // ** Pass 2: Update without any changes to groups[include]
119 $nullOpParams = $createParams;
120 $nullOpParams['id'] = $createResult['id'];
121 $updateParams['api.mailing_job.create'] = 1;
122 unset($nullOpParams['groups']['include']);
123 $this->callAPISuccess('Mailing', 'create', $nullOpParams);
124 $getGroup2 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
125 $getGroup2_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup2['values']));
126 $this->assertEquals(array($groupIDs['a']), $getGroup2_ids);
127 $getRecipient2 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
128 $getRecip2_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient2['values']));
129 $this->assertEquals(array($contactIDs['a']), $getRecip2_ids);
130
131 // ** Pass 3: Update with different groups[include]
132 $updateParams = $createParams;
133 $updateParams['id'] = $createResult['id'];
134 $updateParams['groups']['include'] = array($groupIDs['b']);
135 $updateParams['api.mailing_job.create'] = 1;
136 $this->callAPISuccess('Mailing', 'create', $updateParams);
137 $getGroup3 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
138 $getGroup3_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup3['values']));
139 $this->assertEquals(array($groupIDs['b']), $getGroup3_ids);
140 $getRecipient3 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
141 $getRecipient3_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient3['values']));
142 $this->assertEquals(array($contactIDs['b']), $getRecipient3_ids);
143 }
144
145 public function testMailerPreview() {
146 // BEGIN SAMPLE DATA
147 $contactID = $this->individualCreate();
148 $displayName = $this->callAPISuccess('contact', 'get', array('id' => $contactID));
149 $displayName = $displayName['values'][$contactID]['display_name'];
150 $this->assertTrue(!empty($displayName));
151
152 $params = $this->_params;
153 $params['api.Mailing.preview'] = array(
154 'id' => '$value.id',
155 'contact_id' => $contactID,
156 );
157 $params['options']['force_rollback'] = 1;
158 // END SAMPLE DATA
159
160 $maxIDs = array(
161 'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'),
162 'job' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_job'),
163 'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'),
164 'recipient' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_recipients'),
165 );
166 $result = $this->callAPISuccess('mailing', 'create', $params);
167 $this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); // 'Preview should not create any mailing records'
168 $this->assertDBQuery($maxIDs['job'], 'SELECT MAX(id) FROM civicrm_mailing_job'); // 'Preview should not create any mailing_job record'
169 $this->assertDBQuery($maxIDs['group'], 'SELECT MAX(id) FROM civicrm_mailing_group'); // 'Preview should not create any mailing_group records'
170 $this->assertDBQuery($maxIDs['recipient'], 'SELECT MAX(id) FROM civicrm_mailing_recipients'); // 'Preview should not create any mailing_recipient records'
171
172 $previewResult = $result['values'][$result['id']]['api.Mailing.preview'];
173 $this->assertEquals("Hello $displayName", $previewResult['values']['subject']);
174 $this->assertContains("This is $displayName", $previewResult['values']['body_text']);
175 $this->assertContains("<p>This is $displayName.</p>", $previewResult['values']['body_html']);
176 }
177
178 public function testMailerPreviewRecipients() {
179 // BEGIN SAMPLE DATA
180 $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
181 $groupIDs['exc'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group'));
182 $contactIDs['include_me'] = $this->individualCreate(array(
183 'email' => 'include.me@example.org',
184 'first_name' => 'Includer',
185 'last_name' => 'Person',
186 ));
187 $contactIDs['exclude_me'] = $this->individualCreate(array(
188 'email' => 'exclude.me@example.org',
189 'last_name' => 'Excluder',
190 ));
191 $this->callAPISuccess('GroupContact', 'create', array(
192 'group_id' => $groupIDs['inc'],
193 'contact_id' => $contactIDs['include_me'],
194 ));
195 $this->callAPISuccess('GroupContact', 'create', array(
196 'group_id' => $groupIDs['inc'],
197 'contact_id' => $contactIDs['exclude_me'],
198 ));
199 $this->callAPISuccess('GroupContact', 'create', array(
200 'group_id' => $groupIDs['exc'],
201 'contact_id' => $contactIDs['exclude_me'],
202 ));
203
204 $params = $this->_params;
205 $params['groups']['include'] = array($groupIDs['inc']);
206 $params['groups']['exclude'] = array($groupIDs['exc']);
207 $params['mailings']['include'] = array();
208 $params['mailings']['exclude'] = array();
209 $params['options']['force_rollback'] = 1;
210 $params['api.mailing_job.create'] = 1;
211 $params['api.MailingRecipients.get'] = array(
212 'mailing_id' => '$value.id',
213 'api.contact.getvalue' => array(
214 'return' => 'display_name',
215 ),
216 'api.email.getvalue' => array(
217 'return' => 'email',
218 ),
219 );
220 // END SAMPLE DATA
221
222 $maxIDs = array(
223 'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'),
224 'job' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_job'),
225 'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'),
226 );
227 $create = $this->callAPIAndDocument('Mailing', 'create', $params, __FUNCTION__, __FILE__);
228 $this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); // 'Preview should not create any mailing records'
229 $this->assertDBQuery($maxIDs['job'], 'SELECT MAX(id) FROM civicrm_mailing_job'); // 'Preview should not create any mailing_job record'
230 $this->assertDBQuery($maxIDs['group'], 'SELECT MAX(id) FROM civicrm_mailing_group'); // 'Preview should not create any mailing_group records'
231
232 $preview = $create['values'][$create['id']]['api.MailingRecipients.get'];
233 $previewIds = array_values(CRM_Utils_Array::collect('contact_id', $preview['values']));
234 $this->assertEquals(array((string) $contactIDs['include_me']), $previewIds);
235 $previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values']));
236 $this->assertEquals(array('include.me@example.org'), $previewEmails);
237 $previewNames = array_values(CRM_Utils_Array::collect('api.contact.getvalue', $preview['values']));
238 $this->assertTrue((bool) preg_match('/Includer Person/', $previewNames[0]), "Name 'Includer Person' should appear in '" . $previewNames[0] . '"');
239 }
240
241 /**
242 *
243 */
244 public function testMailerSendTest_email() {
245 $contactIDs['alice'] = $this->individualCreate(array(
246 'email' => 'alice@example.org',
247 'first_name' => 'Alice',
248 'last_name' => 'Person',
249 ));
250
251 $mail = $this->callAPISuccess('mailing', 'create', $this->_params);
252
253 $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
254 $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
255 $this->assertEquals(1, $deliveredInfo['count'], "in line " . __LINE__); // verify mail has been sent to user by count
256
257 $deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values']));
258 $this->assertEquals(array($contactIDs['alice']), $deliveredContacts);
259
260 $deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values']));
261 $this->assertEquals(array('alice@example.org'), $deliveredEmails);
262 }
263
264 /**
265 *
266 */
267 public function testMailerSendTest_group() {
268 // BEGIN SAMPLE DATA
269 $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
270 $contactIDs['alice'] = $this->individualCreate(array(
271 'email' => 'alice@example.org',
272 'first_name' => 'Alice',
273 'last_name' => 'Person',
274 ));
275 $contactIDs['bob'] = $this->individualCreate(array(
276 'email' => 'bob@example.org',
277 'first_name' => 'Bob',
278 'last_name' => 'Person',
279 ));
280 $contactIDs['carol'] = $this->individualCreate(array(
281 'email' => 'carol@example.org',
282 'first_name' => 'Carol',
283 'last_name' => 'Person',
284 ));
285 $this->callAPISuccess('GroupContact', 'create', array(
286 'group_id' => $groupIDs['inc'],
287 'contact_id' => $contactIDs['alice'],
288 ));
289 $this->callAPISuccess('GroupContact', 'create', array(
290 'group_id' => $groupIDs['inc'],
291 'contact_id' => $contactIDs['bob'],
292 ));
293 $this->callAPISuccess('GroupContact', 'create', array(
294 'group_id' => $groupIDs['inc'],
295 'contact_id' => $contactIDs['carol'],
296 ));
297 // END SAMPLE DATA
298
299 $mail = $this->callAPISuccess('mailing', 'create', $this->_params);
300 $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', array(
301 'mailing_id' => $mail['id'],
302 'test_email' => NULL,
303 'test_group' => $groupIDs['inc'],
304 ));
305 $this->assertEquals(3, $deliveredInfo['count'], "in line " . __LINE__); // verify mail has been sent to user by count
306
307 $deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values']));
308 $this->assertEquals(array($contactIDs['alice'], $contactIDs['bob'], $contactIDs['carol']), $deliveredContacts);
309
310 $deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values']));
311 $this->assertEquals(array('alice@example.org', 'bob@example.org', 'carol@example.org'), $deliveredEmails);
312 }
313
314 /**
315 * @return array
316 */
317 public function submitProvider() {
318 $cases = array(); // $useLogin, $params, $expectedFailure, $expectedJobCount
319 $cases[] = array(
320 TRUE, //useLogin
321 array(), // createParams
322 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
323 FALSE, // expectedFailure
324 1, // expectedJobCount
325 );
326 $cases[] = array(
327 FALSE, //useLogin
328 array(), // createParams
329 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
330 "/Failed to determine current user/", // expectedFailure
331 0, // expectedJobCount
332 );
333 $cases[] = array(
334 TRUE, //useLogin
335 array(), // createParams
336 array('scheduled_date' => '2014-12-13 10:00:00'),
337 FALSE, // expectedFailure
338 1, // expectedJobCount
339 );
340 $cases[] = array(
341 TRUE, //useLogin
342 array(), // createParams
343 array(),
344 "/Missing parameter scheduled_date and.or approval_date/", // expectedFailure
345 0, // expectedJobCount
346 );
347 $cases[] = array(
348 TRUE, //useLogin
349 array('name' => ''), // createParams
350 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
351 "/Mailing cannot be sent. There are missing or invalid fields \\(name\\)./", // expectedFailure
352 0, // expectedJobCount
353 );
354 $cases[] = array(
355 TRUE, //useLogin
356 array('body_html' => '', 'body_text' => ''), // createParams
357 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
358 "/Mailing cannot be sent. There are missing or invalid fields \\(body\\)./", // expectedFailure
359 0, // expectedJobCount
360 );
361 $cases[] = array(
362 TRUE, //useLogin
363 array('body_html' => 'Oops, did I leave my tokens at home?'), // createParams
364 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
365 "/Mailing cannot be sent. There are missing or invalid fields \\(.*body_html.*optOut.*\\)./", // expectedFailure
366 0, // expectedJobCount
367 );
368 $cases[] = array(
369 TRUE, //useLogin
370 array('body_text' => 'Oops, did I leave my tokens at home?'), // createParams
371 array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
372 "/Mailing cannot be sent. There are missing or invalid fields \\(.*body_text.*optOut.*\\)./", // expectedFailure
373 0, // expectedJobCount
374 );
375
376 return $cases;
377 }
378
379 /**
380 * @param bool $useLogin
381 * @param array $createParams
382 * @param array $submitParams
383 * @param null|string $expectedFailure
384 * @param int $expectedJobCount
385 * @dataProvider submitProvider
386 */
387 public function testMailerSubmit($useLogin, $createParams, $submitParams, $expectedFailure, $expectedJobCount) {
388 if ($useLogin) {
389 $this->createLoggedInUser();
390 }
391
392 $id = $this->createDraftMailing($createParams);
393
394 $submitParams['id'] = $id;
395 if ($expectedFailure) {
396 $submitResult = $this->callAPIFailure('mailing', 'submit', $submitParams);
397 $this->assertRegExp($expectedFailure, $submitResult['error_message']);
398 }
399 else {
400 $submitResult = $this->callAPIAndDocument('mailing', 'submit', $submitParams, __FUNCTION__, __FILE__);
401 $this->assertTrue(is_numeric($submitResult['id']));
402 $this->assertTrue(is_numeric($submitResult['values'][$id]['scheduled_id']));
403 $this->assertEquals($submitParams['scheduled_date'], $submitResult['values'][$id]['scheduled_date']);
404 }
405 $this->assertDBQuery($expectedJobCount, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
406 1 => array($id, 'Integer'),
407 ));
408 }
409
410 /**
411 *
412 */
413 public function testMailerStats() {
414 $result = $this->groupContactCreate($this->_groupID, 100);
415 $this->assertEquals(100, $result['added']); //verify if 100 contacts are added for group
416
417 //Create and send test mail first and change the mail job to live,
418 //because stats api only works on live mail
419 $mail = $this->callAPISuccess('mailing', 'create', $this->_params);
420 $params = array('mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $this->_groupID);
421 $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
422 $deliveredIds = implode(',', array_keys($deliveredInfo['values']));
423
424 //Change the test mail into live
425 $sql = "UPDATE civicrm_mailing_job SET is_test = 0 WHERE mailing_id = {$mail['id']}";
426 CRM_Core_DAO::executeQuery($sql);
427
428 foreach (array('bounce', 'unsubscribe', 'opened') as $type) {
429 $sql = "CREATE TEMPORARY TABLE mail_{$type}_temp
430 (event_queue_id int, time_stamp datetime, delivered_id int)
431 SELECT event_queue_id, time_stamp, id
432 FROM civicrm_mailing_event_delivered
433 WHERE id IN ($deliveredIds)
434 ORDER BY RAND() LIMIT 0,20;";
435 CRM_Core_DAO::executeQuery($sql);
436
437 $sql = "DELETE FROM civicrm_mailing_event_delivered WHERE id IN (SELECT delivered_id FROM mail_{$type}_temp);";
438 CRM_Core_DAO::executeQuery($sql);
439
440 if ($type == 'unsubscribe') {
441 $sql = "INSERT INTO civicrm_mailing_event_{$type} (event_queue_id, time_stamp, org_unsubscribe)
442 SELECT event_queue_id, time_stamp, 1 FROM mail_{$type}_temp";
443 }
444 else {
445 $sql = "INSERT INTO civicrm_mailing_event_{$type} (event_queue_id, time_stamp)
446 SELECT event_queue_id, time_stamp FROM mail_{$type}_temp";
447 }
448 CRM_Core_DAO::executeQuery($sql);
449 }
450
451 $result = $this->callAPISuccess('mailing', 'stats', array('mailing_id' => $mail['id']));
452 $expectedResult = array(
453 'Delivered' => 80, //since among 100 mails 20 has been bounced
454 'Bounces' => 20,
455 'Opened' => 20,
456 'Unique Clicks' => 0,
457 'Unsubscribers' => 20,
458 );
459 $this->checkArrayEquals($expectedResult, $result['values'][$mail['id']]);
460 }
461
462 /**
463 * Test civicrm_mailing_delete.
464 */
465 public function testMailerDeleteSuccess() {
466 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
467 $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
468 $this->assertAPIDeleted($this->_entity, $result['id']);
469 }
470
471 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
472
473 //------------ civicrm_mailing_event_bounce methods------------
474
475 /**
476 * Test civicrm_mailing_event_bounce with wrong params.
477 * Note that tests like this are slightly better than no test but an
478 * api function cannot be considered supported / 'part of the api' without a
479 * success test
480 */
481 public function testMailerBounceWrongParams() {
482 $params = array(
483 'job_id' => 'Wrong ID',
484 'event_queue_id' => 'Wrong ID',
485 'hash' => 'Wrong Hash',
486 'body' => 'Body...',
487 'time_stamp' => '20111109212100',
488 );
489 $this->callAPIFailure('mailing_event', 'bounce', $params,
490 'Queue event could not be found'
491 );
492 }
493
494 //----------- civicrm_mailing_event_confirm methods -----------
495
496 /**
497 * Test civicrm_mailing_event_confirm with wrong params.
498 * Note that tests like this are slightly better than no test but an
499 * api function cannot be considered supported / 'part of the api' without a
500 * success test
501 */
502 public function testMailerConfirmWrongParams() {
503 $params = array(
504 'contact_id' => 'Wrong ID',
505 'subscribe_id' => 'Wrong ID',
506 'hash' => 'Wrong Hash',
507 'event_subscribe_id' => '123',
508 'time_stamp' => '20111111010101',
509 );
510 $this->callAPIFailure('mailing_event', 'confirm', $params,
511 'Confirmation failed'
512 );
513 }
514
515 //---------- civicrm_mailing_event_reply methods -----------
516
517 /**
518 * Test civicrm_mailing_event_reply with wrong params.
519 *
520 * Note that tests like this are slightly better than no test but an
521 * api function cannot be considered supported / 'part of the api' without a
522 * success test
523 */
524 public function testMailerReplyWrongParams() {
525 $params = array(
526 'job_id' => 'Wrong ID',
527 'event_queue_id' => 'Wrong ID',
528 'hash' => 'Wrong Hash',
529 'bodyTxt' => 'Body...',
530 'replyTo' => $this->_email,
531 'time_stamp' => '20111111010101',
532 );
533 $this->callAPIFailure('mailing_event', 'reply', $params,
534 'Queue event could not be found'
535 );
536 }
537
538
539 //----------- civicrm_mailing_event_forward methods ----------
540
541 /**
542 * Test civicrm_mailing_event_forward with wrong params.
543 * Note that tests like this are slightly better than no test but an
544 * api function cannot be considered supported / 'part of the api' without a
545 * success test
546 */
547 public function testMailerForwardWrongParams() {
548 $params = array(
549 'job_id' => 'Wrong ID',
550 'event_queue_id' => 'Wrong ID',
551 'hash' => 'Wrong Hash',
552 'email' => $this->_email,
553 'time_stamp' => '20111111010101',
554 );
555 $this->callAPIFailure('mailing_event', 'forward', $params,
556 'Queue event could not be found'
557 );
558 }
559
560 /**
561 * @param array $params
562 * Extra parameters for the draft mailing.
563 * @return array|int
564 */
565 public function createDraftMailing($params = array()) {
566 $createParams = array_merge($this->_params, $params);
567 $createResult = $this->callAPISuccess('mailing', 'create', $createParams, __FUNCTION__, __FILE__);
568 $this->assertTrue(is_numeric($createResult['id']));
569 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
570 1 => array($createResult['id'], 'Integer'),
571 ));
572 return $createResult['id'];
573 }
574
575 //----------- civicrm_mailing_create ----------
576
577 }